Merge lp://qastaging/~edgar-b-dsouza/acire/save_snippet_as into lp://qastaging/acire

Proposed by Ed S
Status: Merged
Merged at revision: not available
Proposed branch: lp://qastaging/~edgar-b-dsouza/acire/save_snippet_as
Merge into: lp://qastaging/acire
Diff against target: 124 lines (+82/-0)
2 files modified
bin/acire (+62/-0)
data/ui/AcireWindow.ui (+20/-0)
To merge this branch: bzr merge lp://qastaging/~edgar-b-dsouza/acire/save_snippet_as
Reviewer Review Type Date Requested Status
Jono Bacon Pending
Review via email: mp+18824@code.qastaging.launchpad.net
To post a comment you must log in.
Revision history for this message
Ed S (edgar-b-dsouza) wrote :

Changes:
- Implemented Save As button (shortcut Ctrl+S), as per Bug #514124, with gtk.FileChooserDialog; default folder is user home folder, filename is basename of snippet's original filename.
- Implemented copy_snippet() handler for Copy button (though gtksourceview editor already provides copy functionality, the button is single-step vs. Select All+Copy in the editor)
- Added shortcut Ctrl+C for Copy button. Enables snippet copying when editor does not have focus.
- Added shortcut F5 for Execute button. Focus can remain in the editor widget, enables edit-run-fix-rerun with only keyboard.

Please review.

Thanks,
Ed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/acire'
2--- bin/acire 2010-02-07 11:05:09 +0000
3+++ bin/acire 2010-02-08 06:21:15 +0000
4@@ -26,6 +26,13 @@
5 import gnome.vfs
6 import pango
7 import tempfile #Used in run_snippet to run user-modded snippet
8+###Needed to check for GTK version, gtk.FileChooserDialog available, see save_snippet()
9+import pygtk
10+pygtk.require('2.0')
11+if gtk.pygtk_version < (2,3,90):
12+ print "PyGtk ver. 2.3.90 or later required for FileChooserDialog, to save snippets."
13+###/Needed to check for GTK version
14+
15
16 # Check if we are working in the source tree or from the installed
17 # package and mangle the python path accordingly
18@@ -249,6 +256,61 @@
19 #For now, leaving the file(s) there; need ideas for cleanup - on app shutdown?
20 ###os.unlink(tmp_sn_filename)
21
22+ def save_snippet(self, widget, data=None):
23+ if not self.current_filename:
24+ md = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO,
25+ gtk.BUTTONS_CLOSE, "Please choose a snippet first.")
26+ md.run()
27+ md.destroy()
28+ return
29+ if gtk.pygtk_version < (2,3,90):
30+ md = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,
31+ gtk.BUTTONS_CLOSE, "Sorry, PyGTK must be at least version 2.4 to display the Save As dialog!")
32+ md.run()
33+ md.destroy()
34+ return
35+
36+ dialog = gtk.FileChooserDialog("Save Snippet As...",
37+ None,
38+ gtk.FILE_CHOOSER_ACTION_SAVE,
39+ (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
40+ gtk.STOCK_SAVE_AS, gtk.RESPONSE_OK))
41+ dialog.set_default_response(gtk.RESPONSE_OK)
42+
43+ filter = gtk.FileFilter()
44+ filter.set_name("All files")
45+ filter.add_pattern("*")
46+ dialog.add_filter(filter)
47+
48+ filter = gtk.FileFilter()
49+ filter.set_name("Python scripts")
50+ filter.add_mime_type("application/x-python")
51+ filter.add_mime_type("text/plain")
52+ filter.add_mime_type("application/octet-stream")
53+ filter.add_pattern("*.py")
54+ dialog.add_filter(filter)
55+
56+ if os.getenv("HOME"):
57+ dialog.set_current_folder(os.getenv("HOME"))
58+ dialog.set_current_name(os.path.basename(self.current_filename))
59+ dialog.set_do_overwrite_confirmation(True)
60+
61+ response = dialog.run()
62+ if response == gtk.RESPONSE_OK:
63+ saveas_filename = dialog.get_filename()
64+ saveas_file = open(saveas_filename, 'w', False)
65+ e = self.editor_buffer
66+ saveas_file.write(e.get_text(e.get_start_iter(), e.get_end_iter()))
67+ saveas_file.close()
68+ dialog.destroy()
69+
70+ def copy_snippet(self, widget, data=None):
71+ clpb = gtk.Clipboard()
72+ #self.editor_buffer.copy_clipboard(clpb)
73+ e = self.editor_buffer
74+ textdata = e.get_text(e.get_start_iter(), e.get_end_iter())
75+ clpb.set_text(textdata, len=-1)
76+
77 def get_snippets_file_list(self):
78 """Read in the snippets directory and put all Python files into a list."""
79
80
81=== modified file 'data/ui/AcireWindow.ui'
82--- data/ui/AcireWindow.ui 2010-02-05 06:57:45 +0000
83+++ data/ui/AcireWindow.ui 2010-02-08 06:21:15 +0000
84@@ -206,6 +206,7 @@
85 <property name="can_focus">True</property>
86 <property name="receives_default">True</property>
87 <property name="use_stock">True</property>
88+ <accelerator key="F5" signal="clicked"/>
89 <signal name="clicked" handler="run_snippet"/>
90 </object>
91 <packing>
92@@ -221,6 +222,8 @@
93 <property name="can_focus">True</property>
94 <property name="receives_default">True</property>
95 <property name="use_stock">True</property>
96+ <accelerator key="c" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
97+ <signal name="clicked" handler="copy_snippet"/>
98 </object>
99 <packing>
100 <property name="expand">False</property>
101@@ -228,6 +231,23 @@
102 <property name="position">1</property>
103 </packing>
104 </child>
105+ <child>
106+ <object class="GtkButton" id="saveas_button">
107+ <property name="label">gtk-save-as</property>
108+ <property name="visible">True</property>
109+ <property name="can_focus">True</property>
110+ <property name="receives_default">True</property>
111+ <property name="use_stock">True</property>
112+ <property name="image_position">top</property>
113+ <accelerator key="s" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
114+ <signal name="clicked" handler="save_snippet"/>
115+ </object>
116+ <packing>
117+ <property name="expand">False</property>
118+ <property name="fill">False</property>
119+ <property name="position">2</property>
120+ </packing>
121+ </child>
122 </object>
123 <packing>
124 <property name="expand">False</property>

Subscribers

People subscribed via source and target branches

to all changes: