Merge lp:~flimm/quickly/better-new into lp:quickly
- better-new
- Merge into trunk
Proposed by
David D Lowe
Status: | Merged |
---|---|
Merge reported by: | Rick Spencer |
Merged at revision: | not available |
Proposed branch: | lp:~flimm/quickly/better-new |
Merge into: | lp:quickly |
Diff against target: |
274 lines (+62/-85) 4 files modified
data/templates/ubuntu-application/project_root/bin/project_name (+27/-26) data/templates/ubuntu-application/project_root/python/Aboutcamel_case_nameDialog.py (+14/-24) data/templates/ubuntu-application/project_root/python/Preferencescamel_case_nameDialog.py (+16/-28) data/templates/ubuntu-application/project_root/python/helpers.py (+5/-7) |
To merge this branch: | bzr merge lp:~flimm/quickly/better-new |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Rick Spencer | Approve | ||
Review via email: mp+21384@code.launchpad.net |
Commit message
Description of the change
Replaced New methods with __new__, it's more elegant.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'data/templates/ubuntu-application/project_root/bin/project_name' | |||
2 | --- data/templates/ubuntu-application/project_root/bin/project_name 2010-03-09 09:36:08 +0000 | |||
3 | +++ data/templates/ubuntu-application/project_root/bin/project_name 2010-03-15 16:53:12 +0000 | |||
4 | @@ -31,31 +31,41 @@ | |||
5 | 31 | 31 | ||
6 | 32 | from python_name import ( | 32 | from python_name import ( |
7 | 33 | Aboutcamel_case_nameDialog, Preferencescamel_case_nameDialog) | 33 | Aboutcamel_case_nameDialog, Preferencescamel_case_nameDialog) |
9 | 34 | from python_name.helpers import make_window | 34 | from python_name.helpers import get_builder |
10 | 35 | 35 | ||
11 | 36 | 36 | ||
12 | 37 | class camel_case_nameWindow(gtk.Window): | 37 | class camel_case_nameWindow(gtk.Window): |
13 | 38 | __gtype_name__ = "camel_case_nameWindow" | 38 | __gtype_name__ = "camel_case_nameWindow" |
25 | 39 | 39 | ||
26 | 40 | def __init__(self): | 40 | # To construct a new instance of this method, the following notable |
27 | 41 | """Construct a camel_case_nameWindow. | 41 | # methods are called in this order: |
28 | 42 | 42 | # __new__(cls) | |
29 | 43 | This function is typically not called directly. Creation a | 43 | # __init__(self) |
30 | 44 | camel_case_nameWindow requires rereading the associated ui file and | 44 | # finish_initializing(self, builder) |
31 | 45 | parsing the ui definition externally, and then calling | 45 | # __init__(self) |
32 | 46 | camel_case_nameWindow.finish_initializing(). | 46 | # |
33 | 47 | 47 | # For this reason, it's recommended you leave __init__ empty and put | |
34 | 48 | Use the convenience function Newcamel_case_nameWindow to create | 48 | # your inialization code in finish_intializing |
35 | 49 | camel_case_nameWindow object. | 49 | |
36 | 50 | def __new__(cls): | ||
37 | 51 | """Special static method that's automatically called by Python when | ||
38 | 52 | constructing a new instance of this class. | ||
39 | 53 | |||
40 | 54 | Returns a fully instantiated camel_case_nameWindow object. | ||
41 | 50 | """ | 55 | """ |
43 | 51 | pass | 56 | builder = get_builder('camel_case_nameWindow') |
44 | 57 | new_object = builder.get_object("python_name_window") | ||
45 | 58 | new_object.finish_initializing(builder) | ||
46 | 59 | return new_object | ||
47 | 52 | 60 | ||
48 | 53 | def finish_initializing(self, builder): | 61 | def finish_initializing(self, builder): |
50 | 54 | """Called after we've finished initializing. | 62 | """Called while initializing this instance in __new__ |
51 | 55 | 63 | ||
52 | 56 | finish_initalizing should be called after parsing the UI definition | 64 | finish_initalizing should be called after parsing the UI definition |
53 | 57 | and creating a camel_case_nameWindow object with it in order to finish | 65 | and creating a camel_case_nameWindow object with it in order to finish |
54 | 58 | initializing the start of the new camel_case_nameWindow instance. | 66 | initializing the start of the new camel_case_nameWindow instance. |
55 | 67 | |||
56 | 68 | Put your initilization code in here and leave __init__ undefined. | ||
57 | 59 | """ | 69 | """ |
58 | 60 | # Get a reference to the builder and set up the signals. | 70 | # Get a reference to the builder and set up the signals. |
59 | 61 | self.builder = builder | 71 | self.builder = builder |
60 | @@ -80,13 +90,13 @@ | |||
61 | 80 | 90 | ||
62 | 81 | def about(self, widget, data=None): | 91 | def about(self, widget, data=None): |
63 | 82 | """Display the about box for project_name.""" | 92 | """Display the about box for project_name.""" |
65 | 83 | about = Aboutcamel_case_nameDialog.NewAboutcamel_case_nameDialog() | 93 | about = Aboutcamel_case_nameDialog.Aboutcamel_case_nameDialog() |
66 | 84 | response = about.run() | 94 | response = about.run() |
67 | 85 | about.destroy() | 95 | about.destroy() |
68 | 86 | 96 | ||
69 | 87 | def preferences(self, widget, data=None): | 97 | def preferences(self, widget, data=None): |
70 | 88 | """Display the preferences window for project_name.""" | 98 | """Display the preferences window for project_name.""" |
72 | 89 | prefs = Preferencescamel_case_nameDialog.NewPreferencescamel_case_nameDialog() | 99 | prefs = Preferencescamel_case_nameDialog.Preferencescamel_case_nameDialog() |
73 | 90 | response = prefs.run() | 100 | response = prefs.run() |
74 | 91 | if response == gtk.RESPONSE_OK: | 101 | if response == gtk.RESPONSE_OK: |
75 | 92 | # Make any updates based on changed preferences here. | 102 | # Make any updates based on changed preferences here. |
76 | @@ -102,15 +112,6 @@ | |||
77 | 102 | # Clean up code for saving application state should be added here. | 112 | # Clean up code for saving application state should be added here. |
78 | 103 | gtk.main_quit() | 113 | gtk.main_quit() |
79 | 104 | 114 | ||
80 | 105 | |||
81 | 106 | def Newcamel_case_nameWindow(): | ||
82 | 107 | """Newcamel_case_nameWindow - returns a fully instantiated | ||
83 | 108 | camel_case_nameWindow object. Use this function rather than | ||
84 | 109 | creating a camel_case_nameWindow directly. | ||
85 | 110 | """ | ||
86 | 111 | return make_window('camel_case_nameWindow', "python_name_window") | ||
87 | 112 | |||
88 | 113 | |||
89 | 114 | if __name__ == "__main__": | 115 | if __name__ == "__main__": |
90 | 115 | # Support for command line options. | 116 | # Support for command line options. |
91 | 116 | import logging | 117 | import logging |
92 | @@ -127,6 +128,6 @@ | |||
93 | 127 | logging.debug('logging enabled') | 128 | logging.debug('logging enabled') |
94 | 128 | 129 | ||
95 | 129 | # Run the application. | 130 | # Run the application. |
97 | 130 | window = Newcamel_case_nameWindow() | 131 | window = camel_case_nameWindow() |
98 | 131 | window.show() | 132 | window.show() |
99 | 132 | gtk.main() | 133 | gtk.main() |
100 | 133 | 134 | ||
101 | === modified file 'data/templates/ubuntu-application/project_root/python/Aboutcamel_case_nameDialog.py' | |||
102 | --- data/templates/ubuntu-application/project_root/python/Aboutcamel_case_nameDialog.py 2010-02-10 05:54:07 +0000 | |||
103 | +++ data/templates/ubuntu-application/project_root/python/Aboutcamel_case_nameDialog.py 2010-03-15 16:53:12 +0000 | |||
104 | @@ -5,7 +5,7 @@ | |||
105 | 5 | 5 | ||
106 | 6 | import gtk | 6 | import gtk |
107 | 7 | 7 | ||
109 | 8 | from python_name.helpers import make_window | 8 | from python_name.helpers import get_builder |
110 | 9 | 9 | ||
111 | 10 | import gettext | 10 | import gettext |
112 | 11 | from gettext import gettext as _ | 11 | from gettext import gettext as _ |
113 | @@ -14,26 +14,26 @@ | |||
114 | 14 | class Aboutcamel_case_nameDialog(gtk.AboutDialog): | 14 | class Aboutcamel_case_nameDialog(gtk.AboutDialog): |
115 | 15 | __gtype_name__ = "Aboutcamel_case_nameDialog" | 15 | __gtype_name__ = "Aboutcamel_case_nameDialog" |
116 | 16 | 16 | ||
127 | 17 | def __init__(self): | 17 | def __new__(cls): |
128 | 18 | """Construct an Aboutcamel_case_nameDialog. | 18 | """Special static method that's automatically called by Python when |
129 | 19 | 19 | constructing a new instance of this class. | |
130 | 20 | This function is typically not called directly. Creation of an | 20 | |
131 | 21 | Aboutcamel_case_nameDialog requires redeading the associated UI file | 21 | Returns a fully instantiated Aboutcamel_case_nameDialog object. |
122 | 22 | and parsing the UI definition externally, and then calling | ||
123 | 23 | Aboutcamel_case_nameDialog.finish_initializing(). | ||
124 | 24 | |||
125 | 25 | Use the convenience function NewAboutcamel_case_nameDialog to create | ||
126 | 26 | NewAboutcamel_case_nameDialog objects. | ||
132 | 27 | """ | 22 | """ |
134 | 28 | pass | 23 | builder = get_builder('Aboutcamel_case_nameDialog') |
135 | 24 | new_object = builder.get_object("about_python_name_dialog") | ||
136 | 25 | new_object.finish_initializing(builder) | ||
137 | 26 | return new_object | ||
138 | 29 | 27 | ||
139 | 30 | def finish_initializing(self, builder): | 28 | def finish_initializing(self, builder): |
141 | 31 | """Called after we've finished initializing. | 29 | """Called while initializing this instance in __new__ |
142 | 32 | 30 | ||
143 | 33 | finish_initalizing should be called after parsing the ui definition | 31 | finish_initalizing should be called after parsing the ui definition |
144 | 34 | and creating a Aboutcamel_case_nameDialog object with it in order to | 32 | and creating a Aboutcamel_case_nameDialog object with it in order to |
145 | 35 | finish initializing the start of the new Aboutcamel_case_nameDialog | 33 | finish initializing the start of the new Aboutcamel_case_nameDialog |
146 | 36 | instance. | 34 | instance. |
147 | 35 | |||
148 | 36 | Put your initialization code in here and leave __init__ undefined. | ||
149 | 37 | """ | 37 | """ |
150 | 38 | # Get a reference to the builder and set up the signals. | 38 | # Get a reference to the builder and set up the signals. |
151 | 39 | self.builder = builder | 39 | self.builder = builder |
152 | @@ -42,17 +42,7 @@ | |||
153 | 42 | # Code for other initialization actions should be added here. | 42 | # Code for other initialization actions should be added here. |
154 | 43 | 43 | ||
155 | 44 | 44 | ||
156 | 45 | def NewAboutcamel_case_nameDialog(): | ||
157 | 46 | """Returns a fully instantiated Aboutcamel_case_nameDialog object. | ||
158 | 47 | |||
159 | 48 | Use this function rather than creating a Aboutcamel_case_nameDialog | ||
160 | 49 | instance directly. | ||
161 | 50 | """ | ||
162 | 51 | return make_window( | ||
163 | 52 | 'Aboutcamel_case_nameDialog', "about_python_name_dialog") | ||
164 | 53 | |||
165 | 54 | |||
166 | 55 | if __name__ == "__main__": | 45 | if __name__ == "__main__": |
168 | 56 | dialog = NewAboutcamel_case_nameDialog() | 46 | dialog = Aboutcamel_case_nameDialog() |
169 | 57 | dialog.show() | 47 | dialog.show() |
170 | 58 | gtk.main() | 48 | gtk.main() |
171 | 59 | 49 | ||
172 | === modified file 'data/templates/ubuntu-application/project_root/python/Preferencescamel_case_nameDialog.py' | |||
173 | --- data/templates/ubuntu-application/project_root/python/Preferencescamel_case_nameDialog.py 2010-02-10 05:54:07 +0000 | |||
174 | +++ data/templates/ubuntu-application/project_root/python/Preferencescamel_case_nameDialog.py 2010-03-15 16:53:12 +0000 | |||
175 | @@ -7,7 +7,7 @@ | |||
176 | 7 | from desktopcouch.records.record import Record | 7 | from desktopcouch.records.record import Record |
177 | 8 | import gtk | 8 | import gtk |
178 | 9 | 9 | ||
180 | 10 | from python_name.helpers import make_window | 10 | from python_name.helpers import get_builder |
181 | 11 | 11 | ||
182 | 12 | import gettext | 12 | import gettext |
183 | 13 | from gettext import gettext as _ | 13 | from gettext import gettext as _ |
184 | @@ -17,26 +17,26 @@ | |||
185 | 17 | __gtype_name__ = "Preferencescamel_case_nameDialog" | 17 | __gtype_name__ = "Preferencescamel_case_nameDialog" |
186 | 18 | preferences = {} | 18 | preferences = {} |
187 | 19 | 19 | ||
198 | 20 | def __init__(self): | 20 | def __new__(cls): |
199 | 21 | """Construct a Preferencescamel_case_nameDialog. | 21 | """Special static method that's automatically called by Python when |
200 | 22 | 22 | constructing a new instance of this class. | |
201 | 23 | This function is typically not called directly. Creation of a | 23 | |
202 | 24 | Preferencescamel_case_nameDialog requires rereading the associated UI | 24 | Returns a fully instantiated Preferencescamel_case_nameDialog object. |
193 | 25 | file and parsing the UI definition extrenally, and then calling | ||
194 | 26 | Preferencescamel_case_nameDialog.finish_initializing(). | ||
195 | 27 | |||
196 | 28 | Use the convenience function NewPreferencescamel_case_nameDialog to | ||
197 | 29 | create NewAboutcamel_case_nameDialog objects. | ||
203 | 30 | """ | 25 | """ |
205 | 31 | pass | 26 | builder = get_builder('Preferencescamel_case_nameDialog') |
206 | 27 | new_object = builder.get_object("preferences_python_name_dialog") | ||
207 | 28 | new_object.finish_initializing(builder) | ||
208 | 29 | return new_object | ||
209 | 32 | 30 | ||
210 | 33 | def finish_initializing(self, builder): | 31 | def finish_initializing(self, builder): |
212 | 34 | """Called after we've finished initializing. | 32 | """Called while initializing this instance in __new__ |
213 | 35 | 33 | ||
214 | 36 | finish_initalizing should be called after parsing the ui definition | 34 | finish_initalizing should be called after parsing the ui definition |
217 | 37 | and creating a Aboutcamel_case_nameDialog object with it in order to | 35 | and creating a Preferencescamel_case_nameDialog object with it in order to |
218 | 38 | finish initializing the start of the new Aboutcamel_case_nameDialog | 36 | finish initializing the start of the new Perferencescamel_case_nameDialog |
219 | 39 | instance. | 37 | instance. |
220 | 38 | |||
221 | 39 | Put your initialization code in here and leave __init__ undefined. | ||
222 | 40 | """ | 40 | """ |
223 | 41 | 41 | ||
224 | 42 | # Get a reference to the builder and set up the signals. | 42 | # Get a reference to the builder and set up the signals. |
225 | @@ -105,19 +105,7 @@ | |||
226 | 105 | # Restore any changes to self._preferences here. | 105 | # Restore any changes to self._preferences here. |
227 | 106 | pass | 106 | pass |
228 | 107 | 107 | ||
229 | 108 | |||
230 | 109 | def NewPreferencescamel_case_nameDialog(): | ||
231 | 110 | """Returns a fully instantiated Preferencescamel_case_nameDialog object. | ||
232 | 111 | |||
233 | 112 | Use this function rather than creating a Preferencescamel_case_nameDialog | ||
234 | 113 | instance directly. | ||
235 | 114 | """ | ||
236 | 115 | return make_window( | ||
237 | 116 | 'Preferencescamel_case_nameDialog', | ||
238 | 117 | "preferences_python_name_dialog") | ||
239 | 118 | |||
240 | 119 | |||
241 | 120 | if __name__ == "__main__": | 108 | if __name__ == "__main__": |
243 | 121 | dialog = NewPreferencescamel_case_nameDialog() | 109 | dialog = Preferencescamel_case_nameDialog() |
244 | 122 | dialog.show() | 110 | dialog.show() |
245 | 123 | gtk.main() | 111 | gtk.main() |
246 | 124 | 112 | ||
247 | === modified file 'data/templates/ubuntu-application/project_root/python/helpers.py' | |||
248 | --- data/templates/ubuntu-application/project_root/python/helpers.py 2010-03-03 14:27:09 +0000 | |||
249 | +++ data/templates/ubuntu-application/project_root/python/helpers.py 2010-03-15 16:53:12 +0000 | |||
250 | @@ -18,12 +18,12 @@ | |||
251 | 18 | from gettext import gettext as _ | 18 | from gettext import gettext as _ |
252 | 19 | gettext.textdomain('project_name') | 19 | gettext.textdomain('project_name') |
253 | 20 | 20 | ||
257 | 21 | def make_window(builder_file_name, window_name): | 21 | def get_builder(builder_file_name): |
258 | 22 | """Return a fully-instantiated window or dialog. | 22 | """Return a fully-instantiated gtk.Builder instance from specified ui |
259 | 23 | 23 | file | |
260 | 24 | |||
261 | 24 | :param builder_file_name: The name of the builder file, without extension. | 25 | :param builder_file_name: The name of the builder file, without extension. |
262 | 25 | Assumed to be in the 'ui' directory under the data path. | 26 | Assumed to be in the 'ui' directory under the data path. |
263 | 26 | :param window_name: The name of the window or dialog in the builder file. | ||
264 | 27 | """ | 27 | """ |
265 | 28 | # Look for the ui file that describes the user interface. | 28 | # Look for the ui file that describes the user interface. |
266 | 29 | ui_filename = get_data_file('ui', '%s.ui' % (builder_file_name,)) | 29 | ui_filename = get_data_file('ui', '%s.ui' % (builder_file_name,)) |
267 | @@ -33,6 +33,4 @@ | |||
268 | 33 | builder = gtk.Builder() | 33 | builder = gtk.Builder() |
269 | 34 | builder.set_translation_domain('project_name') | 34 | builder.set_translation_domain('project_name') |
270 | 35 | builder.add_from_file(ui_filename) | 35 | builder.add_from_file(ui_filename) |
274 | 36 | dialog = builder.get_object(window_name) | 36 | return builder |
272 | 37 | dialog.finish_initializing(builder) | ||
273 | 38 | return dialog |
awesome ... we will need to make 'add dialog' work this way as well, but should be simple. next will be updating the docs.