Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~andreambu/phatch/pep8 |
Merge into: | lp:phatch |
Diff against target: |
1274 lines (+388/-331) 14 files modified
phatch/lib/__init__.py (+1/-1) phatch/lib/pyWx/__init__.py (+4/-2) phatch/lib/pyWx/paint.py (+2/-0) phatch/lib/pyWx/screenshot.py (+26/-20) phatch/lib/pyWx/shell.py (+13/-10) phatch/lib/pyWx/treeDragDrop.py (+2/-1) phatch/lib/pyWx/treeEdit.py (+298/-280) phatch/lib/pyWx/wildcard.py (+2/-1) phatch/lib/pyWx/wxcheck.py (+30/-15) phatch/pyWx/__init__.py (+2/-0) phatch/pyWx/images.py (+1/-1) phatch/pyWx/nuovext.py (+2/-0) phatch/pyWx/plugin.py (+3/-0) phatch/pyWx/wxGlade/__init__.py (+2/-0) |
To merge this branch: | bzr merge lp:~andreambu/phatch/pep8 |
Related bugs: | |
Related blueprints: |
Port all code to PEP8
(Essential)
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Stani | Pending | ||
Review via email: mp+20844@code.launchpad.net |
Commit message
Description of the change
PEP8 conversion complete ;D
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 'phatch/lib/__init__.py' |
2 | --- phatch/lib/__init__.py 2010-03-02 05:29:41 +0000 |
3 | +++ phatch/lib/__init__.py 2010-03-07 00:55:24 +0000 |
4 | @@ -12,5 +12,5 @@ |
5 | # |
6 | # You should have received a copy of the GNU General Public License |
7 | # along with this program. If not, see http://www.gnu.org/licenses/ |
8 | - |
9 | +# |
10 | # Follows PEP8 |
11 | |
12 | === modified file 'phatch/lib/pyWx/__init__.py' |
13 | --- phatch/lib/pyWx/__init__.py 2008-01-01 15:05:58 +0000 |
14 | +++ phatch/lib/pyWx/__init__.py 2010-03-07 00:55:24 +0000 |
15 | @@ -9,6 +9,8 @@ |
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | # GNU General Public License for more details. |
19 | -# |
20 | +# |
21 | # You should have received a copy of the GNU General Public License |
22 | -# along with this program. If not, see http://www.gnu.org/licenses/ |
23 | \ No newline at end of file |
24 | +# along with this program. If not, see http://www.gnu.org/licenses/ |
25 | +# |
26 | +# Follow PEP8 |
27 | |
28 | === modified file 'phatch/lib/pyWx/paint.py' |
29 | --- phatch/lib/pyWx/paint.py 2010-03-06 18:44:33 +0000 |
30 | +++ phatch/lib/pyWx/paint.py 2010-03-07 00:55:24 +0000 |
31 | @@ -14,6 +14,8 @@ |
32 | # |
33 | # You should have received a copy of the GNU General Public License |
34 | # along with this program. If not, see http://www.gnu.org/licenses/ |
35 | +# |
36 | +# Follow PEP8 |
37 | |
38 | import wx |
39 | from compatible import GCDC, FONT_SIZE |
40 | |
41 | === modified file 'phatch/lib/pyWx/screenshot.py' |
42 | --- phatch/lib/pyWx/screenshot.py 2010-02-24 21:00:07 +0000 |
43 | +++ phatch/lib/pyWx/screenshot.py 2010-03-07 00:55:24 +0000 |
44 | @@ -12,52 +12,58 @@ |
45 | # |
46 | # You should have received a copy of the GNU General Public License |
47 | # along with this program. If not, see http://www.gnu.org/licenses/ |
48 | +# |
49 | +# Follow PEP8 |
50 | |
51 | import os |
52 | import wx |
53 | |
54 | + |
55 | def get(rect): |
56 | """ Takes a screenshot of the screen at give pos & size (rect). """ |
57 | |
58 | - #Create a DC for the whole screen area |
59 | + # Create a DC for the whole screen area. |
60 | dcScreen = wx.ScreenDC() |
61 | |
62 | - #Create a Bitmap that will later on hold the screenshot image |
63 | - #Note that the Bitmap must have a size big enough to hold the screenshot |
64 | - #-1 means using the current default color depth |
65 | + # Create a Bitmap that will later on hold the screenshot image. |
66 | + # Note that the Bitmap must have a size big enough to hold the screenshot. |
67 | + # -1 means using the current default color depth. |
68 | bmp = wx.EmptyBitmap(rect.width, rect.height) |
69 | |
70 | - #Create a memory DC that will be used for actually taking the screenshot |
71 | + # Create a memory DC that will be used for actually taking the screenshot. |
72 | memDC = wx.MemoryDC() |
73 | |
74 | - #Tell the memory DC to use our Bitmap |
75 | - #all drawing action on the memory DC will go to the Bitmap now |
76 | + # Tell the memory DC to use our Bitmap |
77 | + # all drawing action on the memory DC will go to the Bitmap now. |
78 | memDC.SelectObject(bmp) |
79 | |
80 | - #Blit (in this case copy) the actual screen on the memory DC |
81 | - #and thus the Bitmap |
82 | - memDC.Blit( 0, #Copy to this X coordinate |
83 | - 0, #Copy to this Y coordinate |
84 | - rect.width, #Copy this width |
85 | - rect.height, #Copy this height |
86 | - dcScreen, #From where do we copy? |
87 | - rect.x, #What's the X offset in the original DC? |
88 | - rect.y #What's the Y offset in the original DC? |
89 | + # Blit (in this case copy) the actual screen on the memory DC |
90 | + # and thus the Bitmap |
91 | + memDC.Blit(0, # Copy to this X coordinate. |
92 | + 0, # Copy to this Y coordinate. |
93 | + rect.width, # Copy this width. |
94 | + rect.height, # Copy this height. |
95 | + dcScreen, # From where do we copy? |
96 | + rect.x, # What's the X offset in the original DC? |
97 | + rect.y # What's the Y offset in the original DC? |
98 | ) |
99 | |
100 | - #Select the Bitmap out of the memory DC by selecting a new |
101 | - #uninitialized Bitmap |
102 | + # Select the Bitmap out of the memory DC by selecting a new |
103 | + # uninitialized Bitmap. |
104 | memDC.SelectObject(wx.NullBitmap) |
105 | |
106 | return bmp |
107 | |
108 | + |
109 | def get_window(window): |
110 | return get(window.GetRect()) |
111 | |
112 | -def save(rect,filename): |
113 | + |
114 | +def save(rect, filename): |
115 | ext = os.path.splitext(filename)[-1][1:].upper() |
116 | - typ = getattr(wx,'BITMAP_TYPE_' + ext) |
117 | + typ = getattr(wx, 'BITMAP_TYPE_' + ext) |
118 | return get(rect).SaveFile(filename, typ) |
119 | |
120 | + |
121 | def save_window(window, filename): |
122 | return save(window.GetRect(), filename) |
123 | |
124 | === modified file 'phatch/lib/pyWx/shell.py' |
125 | --- phatch/lib/pyWx/shell.py 2009-09-22 17:10:51 +0000 |
126 | +++ phatch/lib/pyWx/shell.py 2010-03-07 00:55:24 +0000 |
127 | @@ -12,6 +12,8 @@ |
128 | # |
129 | # You should have received a copy of the GNU General Public License |
130 | # along with this program. If not, see http://www.gnu.org/licenses/ |
131 | +# |
132 | +# Follow PEP8 |
133 | |
134 | try: |
135 | _ |
136 | @@ -27,19 +29,21 @@ |
137 | |
138 | TRANSLATE = _ |
139 | |
140 | + |
141 | class Frame(wx.Frame): |
142 | def __init__(self, parent, title='Shell', intro='', values={}, icon=None, |
143 | **kw): |
144 | - wx.Frame.__init__(self, parent, -1, title = title, **kw) |
145 | + wx.Frame.__init__(self, parent, -1, title=title, **kw) |
146 | self.shell = wx.py.crust.Crust(self, -1, intro=intro) |
147 | - pp = self.shell.shell.interp.locals['pp'] |
148 | + pp = self.shell.shell.interp.locals['pp'] |
149 | self.shell.shell.interp.locals.clear() |
150 | self.shell.shell.interp.locals.update(values) |
151 | self.shell.shell.interp.locals['pp'] = pp |
152 | - if icon: self.SetIcon(icon) |
153 | - self.Bind(wx.EVT_CLOSE,self.on_close,self) |
154 | + if icon: |
155 | + self.SetIcon(icon) |
156 | + self.Bind(wx.EVT_CLOSE, self.on_close, self) |
157 | |
158 | - shell = self.shell.shell |
159 | + shell = self.shell.shell |
160 | shell.Unbind(wx.EVT_IDLE) |
161 | shell.Bind(wx.EVT_IDLE, self.OnIdle) |
162 | |
163 | @@ -50,9 +54,8 @@ |
164 | if self.shell.shell.waiting: |
165 | time.sleep(0.05) |
166 | |
167 | - |
168 | - def on_close(self,event): |
169 | - parent = self.GetParent() |
170 | - parent.menu_tools.Check(parent.menu_tools_python_shell.GetId(),False) |
171 | - parent.shell = None |
172 | + def on_close(self, event): |
173 | + parent = self.GetParent() |
174 | + parent.menu_tools.Check(parent.menu_tools_python_shell.GetId(), False) |
175 | + parent.shell = None |
176 | event.Skip() |
177 | |
178 | === modified file 'phatch/lib/pyWx/treeDragDrop.py' |
179 | --- phatch/lib/pyWx/treeDragDrop.py 2010-03-06 20:35:59 +0000 |
180 | +++ phatch/lib/pyWx/treeDragDrop.py 2010-03-07 00:55:24 +0000 |
181 | @@ -12,7 +12,8 @@ |
182 | # |
183 | # You should have received a copy of the GNU General Public License |
184 | # along with this program. If not, see http://www.gnu.org/licenses/ |
185 | - |
186 | +# |
187 | +# Follow PEP8 |
188 | import wx |
189 | |
190 | |
191 | |
192 | === modified file 'phatch/lib/pyWx/treeEdit.py' |
193 | --- phatch/lib/pyWx/treeEdit.py 2010-03-06 01:30:28 +0000 |
194 | +++ phatch/lib/pyWx/treeEdit.py 2010-03-07 00:55:24 +0000 |
195 | @@ -12,13 +12,15 @@ |
196 | # |
197 | # You should have received a copy of the GNU General Public License |
198 | # along with this program. If not, see http://www.gnu.org/licenses/ |
199 | +# |
200 | +# Follow PEP8 |
201 | |
202 | -#---import modules |
203 | +# ---import modules |
204 | |
205 | # gui-indepedent |
206 | if __name__ == '__main__': |
207 | import sys |
208 | - sys.path.insert(0,'..') |
209 | + sys.path.insert(0, '..') |
210 | |
211 | from lib import formField |
212 | from lib import metadata |
213 | @@ -30,284 +32,292 @@ |
214 | import treeDragDrop |
215 | |
216 | if __name__ == '__main__': |
217 | - sys.path.insert(0,'../..') |
218 | + sys.path.insert(0, '../..') |
219 | |
220 | from lib.unicoding import exception_to_unicode |
221 | |
222 | FIELD_DELIMITER = ': ' |
223 | -WX_ENCODING = wx.GetDefaultPyEncoding() |
224 | +WX_ENCODING = wx.GetDefaultPyEncoding() |
225 | IMAGE_TEST_INFO = metadata.InfoTest() |
226 | |
227 | -#---functions |
228 | +# ---functions |
229 | |
230 | -#---tree |
231 | +# ---tree |
232 | ITEM_HEIGHT = 28 |
233 | -ICON_SIZE = (ITEM_HEIGHT,ITEM_HEIGHT) |
234 | -TR_DEFAULT_STYLE = wx.TR_HAS_BUTTONS | wx.TR_NO_LINES | wx.TR_FULL_ROW_HIGHLIGHT | wx.TR_HIDE_ROOT | wx.TR_DEFAULT_STYLE | wx.SUNKEN_BORDER |
235 | - |
236 | -def _do_nothing(*args,**keyw): |
237 | +ICON_SIZE = (ITEM_HEIGHT, ITEM_HEIGHT) |
238 | +TR_DEFAULT_STYLE = wx.TR_HAS_BUTTONS | wx.TR_NO_LINES | \ |
239 | + wx.TR_FULL_ROW_HIGHLIGHT | wx.TR_HIDE_ROOT | \ |
240 | + wx.TR_DEFAULT_STYLE | wx.SUNKEN_BORDER |
241 | + |
242 | + |
243 | +def _do_nothing(*args, **keyw): |
244 | pass |
245 | |
246 | -def rescale(image,x,y,filter=None): |
247 | + |
248 | +def rescale(image, x, y, filter=None): |
249 | """For compatibility with wxPython 2.6""" |
250 | - if filter is None and hasattr(wx,'IMAGE_QUALITY_HIGH'): |
251 | - filter = wx.IMAGE_QUALITY_HIGH |
252 | + if filter is None and hasattr(wx, 'IMAGE_QUALITY_HIGH'): |
253 | + filter = wx.IMAGE_QUALITY_HIGH |
254 | if filter is None: |
255 | - image.Rescale(x,y) |
256 | + image.Rescale(x, y) |
257 | else: |
258 | - image.Rescale(x,y,filter) |
259 | - |
260 | -def get_index(li,index,n=3): |
261 | + image.Rescale(x, y, filter) |
262 | + |
263 | + |
264 | +def get_index(li, index, n=3): |
265 | try: |
266 | return li[index] |
267 | except IndexError: |
268 | - return (None,)*n |
269 | + return (None, ) * n |
270 | + |
271 | |
272 | class TreeMixin(treeDragDrop.Mixin): |
273 | """ |
274 | - form is like an action |
275 | """ |
276 | - def __init__(self,form_factory={},CtrlMixin=[], |
277 | - icon_size=(28,28),show_error=_do_nothing,set_dirty=_do_nothing): |
278 | + def __init__(self, form_factory={}, CtrlMixin=[], |
279 | + icon_size=(28, 28), show_error=_do_nothing, set_dirty=_do_nothing): |
280 | if wx.Platform == "__WXGTK__": |
281 | - #indentation |
282 | - self.SetIndent(int(self.GetIndent()*1.5)) |
283 | -## elif wx.Platform == "__WXMSW__":#doesn't work |
284 | -## self.SetIndent(int(self.GetIndent() / 2)) |
285 | - #form factory |
286 | - self.form_factory = form_factory |
287 | - self.CtrlMixin = CtrlMixin |
288 | - #popup |
289 | - self.popup = None |
290 | - self.popup_item = None |
291 | - self._field_selected = False |
292 | - #methods |
293 | - self.show_error = show_error |
294 | - self.set_dirty = set_dirty |
295 | - #image list |
296 | + # indentation |
297 | + self.SetIndent(int(self.GetIndent() * 1.5)) |
298 | +# # elif wx.Platform == "__WXMSW__": # doesn't work |
299 | +# # self.SetIndent(int(self.GetIndent() / 2)) |
300 | + # form factory |
301 | + self.form_factory = form_factory |
302 | + self.CtrlMixin = CtrlMixin |
303 | + # popup |
304 | + self.popup = None |
305 | + self.popup_item = None |
306 | + self._field_selected = False |
307 | + # methods |
308 | + self.show_error = show_error |
309 | + self.set_dirty = set_dirty |
310 | + # image list |
311 | self.CreateImageList(icon_size) |
312 | - #drag & drop |
313 | + # drag & drop |
314 | self.EnableDrag(dragTo=self.get_form_item) |
315 | - #collapse |
316 | + # collapse |
317 | self.collapse_automatic = False |
318 | self.evt_leave_window = False |
319 | - #clear |
320 | + # clear |
321 | self.delete_all_forms() |
322 | - #events |
323 | + # events |
324 | self.events() |
325 | |
326 | - def CreateImageList(self,icon_size): |
327 | + def CreateImageList(self, icon_size): |
328 | self.image_list = wx.ImageList(*icon_size) |
329 | - icon_disabled = graphics.bitmap(ICON_DISABLED) |
330 | + icon_disabled = graphics.bitmap(ICON_DISABLED) |
331 | for form in self.form_factory.values(): |
332 | - self._AddFormToImageList(form,icon_size,icon_disabled) |
333 | + self._AddFormToImageList(form, icon_size, icon_disabled) |
334 | self.SetImageList(self.image_list) |
335 | |
336 | - def _AddFormToImageList(self,form,icon_size,icon_disabled): |
337 | - wx_image = graphics.image(form.icon,icon_size) |
338 | - form.icon_bitmap = wx.BitmapFromImage(wx_image) |
339 | - #rescale(image,icon_size[0],icon_size[1]) |
340 | + def _AddFormToImageList(self, form, icon_size, icon_disabled): |
341 | + wx_image = graphics.image(form.icon, icon_size) |
342 | + form.icon_bitmap = wx.BitmapFromImage(wx_image) |
343 | + # rescale(image, icon_size[0], icon_size[1]) |
344 | import Image |
345 | from wxPil import pil_wxImage, wxImage_pil |
346 | - wx_image=pil_wxImage(wxImage_pil(wx_image).resize(icon_size,Image.ANTIALIAS)) |
347 | - form.icon_tree = wx.BitmapFromImage(wx_image) |
348 | - form.icon_tree_disabled = icon_disabled |
349 | - form.icon_tree_id = ( |
350 | + wx_image = pil_wxImage(wxImage_pil(wx_image).resize(icon_size,\ |
351 | + Image.ANTIALIAS)) |
352 | + form.icon_tree = wx.BitmapFromImage(wx_image) |
353 | + form.icon_tree_disabled = icon_disabled |
354 | + form.icon_tree_id = ( |
355 | self.image_list.Add(form.icon_tree_disabled), |
356 | self.image_list.Add(form.icon_tree)) |
357 | |
358 | - def set_item_image(self,x,image): |
359 | - self.SetItemImage(x,image,wx.TreeItemIcon_Normal) |
360 | + def set_item_image(self, x, image): |
361 | + self.SetItemImage(x, image, wx.TreeItemIcon_Normal) |
362 | |
363 | - def tree_label(self,name,value): |
364 | - return ''.join([_(name),FIELD_DELIMITER, |
365 | + def tree_label(self, name, value): |
366 | + return ''.join([_(name), FIELD_DELIMITER, |
367 | self.CtrlMixin._to_local(value)]) |
368 | |
369 | def delete_all_forms(self): |
370 | self.DeleteAllItems() |
371 | self.AddRoot('') |
372 | |
373 | - #---forms |
374 | + # ---forms |
375 | def append_form(self, form, item=-1): |
376 | - root = self.GetRootItem() |
377 | + root = self.GetRootItem() |
378 | if item is -1: |
379 | - item = self.AppendItem(root,_(form.label)) |
380 | + item = self.AppendItem(root, _(form.label)) |
381 | else: |
382 | - item = self.InsertItem(root,item,_(form.label)) |
383 | - self.set_item_image(item,form.icon_tree_id[True]) |
384 | - self.SetItemBold(item,True) |
385 | - self.import_form(item,form) |
386 | + item = self.InsertItem(root, item, _(form.label)) |
387 | + self.set_item_image(item, form.icon_tree_id[True]) |
388 | + self.SetItemBold(item, True) |
389 | + self.import_form(item, form) |
390 | self.SelectItem(item) |
391 | return item |
392 | |
393 | - def append_forms(self,forms): |
394 | - collapse = len(forms)>4 |
395 | - for form in forms[:-1]: |
396 | + def append_forms(self, forms): |
397 | + collapse = len(forms) > 4 |
398 | + for form in forms[: -1]: |
399 | item = self.append_form(form) |
400 | if collapse: |
401 | self.Collapse(item) |
402 | self.append_form(forms[-1]) |
403 | return forms |
404 | |
405 | - def append_form_by_label(self,item,label): |
406 | - return self.append_form(self.form_factory[label](),item) |
407 | + def append_form_by_label(self, item, label): |
408 | + return self.append_form(self.form_factory[label](), item) |
409 | |
410 | def collapse_forms(self): |
411 | - root = self.GetRootItem() |
412 | + root = self.GetRootItem() |
413 | for child in self.GetItemChildren(root): |
414 | self.Collapse(child) |
415 | |
416 | - def enable_form(self,item, bool): |
417 | - self.enable_form_item(self.get_form_item(item),bool) |
418 | + def enable_form(self, item, bool): |
419 | + self.enable_form_item(self.get_form_item(item), bool) |
420 | |
421 | - def enable_form_item(self,item,bool): |
422 | - form = self.GetPyData(item) |
423 | - self.set_item_image(item,form.icon_tree_id[bool]) |
424 | - self.SetItemTextColour(item,(wx.RED,wx.GREEN)[bool]) |
425 | + def enable_form_item(self, item, bool): |
426 | + form = self.GetPyData(item) |
427 | + self.set_item_image(item, form.icon_tree_id[bool]) |
428 | + self.SetItemTextColour(item, (wx.RED, wx.GREEN)[bool]) |
429 | if bool: |
430 | self.Expand(item) |
431 | else: |
432 | self.Collapse(item) |
433 | |
434 | def expand_forms(self): |
435 | - root = self.GetRootItem() |
436 | + root = self.GetRootItem() |
437 | for child in self.GetItemChildren(root): |
438 | self.Expand(child) |
439 | |
440 | - def export_form(self,item,label=None): |
441 | - form = self.GetPyData(item) |
442 | + def export_form(self, item, label=None): |
443 | + form = self.GetPyData(item) |
444 | for field in self.GetItemChildren(item): |
445 | - label, value_as_string = self.GetPyData(field) |
446 | - form.set_field_as_string(label,value_as_string) |
447 | - form.set_field('__enabled__',self.is_form_enabled(item)) |
448 | + label, value_as_string = self.GetPyData(field) |
449 | + form.set_field_as_string(label, value_as_string) |
450 | + form.set_field('__enabled__', self.is_form_enabled(item)) |
451 | return form |
452 | |
453 | def export_forms(self): |
454 | - root = self.GetRootItem() |
455 | + root = self.GetRootItem() |
456 | forms = [] |
457 | for child in self.GetItemChildren(root): |
458 | forms.append(self.export_form(child)) |
459 | return forms |
460 | |
461 | - def import_form(self,item,form): |
462 | - self.SetPyData(item,form) |
463 | + def import_form(self, item, form): |
464 | + self.SetPyData(item, form) |
465 | self.DeleteChildren(item) |
466 | fields = form._get_fields() |
467 | if not self.update_form_relevance(item): |
468 | for label, field in fields.items(): |
469 | if field.visible: |
470 | - self.append_field(item,label,field) |
471 | + self.append_field(item, label, field) |
472 | enabled_field = form._get_fields()['__enabled__'] |
473 | - self.enable_form_item(item,enabled_field.get()) |
474 | + self.enable_form_item(item, enabled_field.get()) |
475 | |
476 | - def append_field(self,parent,label,field,method=None,item=None): |
477 | + def append_field(self, parent, label, field, method=None, item=None): |
478 | value_as_string = field.get_as_string() |
479 | if method is None: |
480 | new_item = self.AppendItem(parent, |
481 | - self.tree_label(label,value_as_string)) |
482 | + self.tree_label(label, value_as_string)) |
483 | else: |
484 | - #print method,parent,item, self.tree_label(label,value_as_string) |
485 | |
486 | - new_item = method(parent,item, |
487 | - self.tree_label(label,value_as_string)) |
488 | - self.SetPyData(new_item,(label,value_as_string)) |
489 | + # print method, parent, item, self.tree_label(label,\ |
490 | + # value_as_string) |
491 | |
492 | + new_item = method(parent, item, |
493 | + self.tree_label(label, value_as_string)) |
494 | + self.SetPyData(new_item, (label, value_as_string)) |
495 | return new_item |
496 | |
497 | - def get_form(self,item,label=None): |
498 | - return self.export_form(self.get_form_item(item),label) |
499 | + def get_form(self, item, label=None): |
500 | + return self.export_form(self.get_form_item(item), label) |
501 | |
502 | - def get_form_item(self,item): |
503 | + def get_form_item(self, item): |
504 | return self.GetRootChild(item) |
505 | |
506 | - def get_form_field(self,item): |
507 | - label, value_as_string = self.GetPyData(item) |
508 | - return self.get_form(item,label)._get_field(label) |
509 | + def get_form_field(self, item): |
510 | + label, value_as_string = self.GetPyData(item) |
511 | + return self.get_form(item, label)._get_field(label) |
512 | |
513 | - def get_form_fields_visible(self,item, form): |
514 | + def get_form_fields_visible(self, item, form): |
515 | """Retrieves the visible fields and their values. If a field |
516 | is dirty, its value will be overwritten with the newly given |
517 | value. |
518 | |
519 | Very important: this handles the dirty fields. |
520 | """ |
521 | - form = self.GetPyData(item) |
522 | - fields = [] |
523 | - for index,ui_field in enumerate(self.GetItemChildren(item)): |
524 | - label, value_as_string = self.GetPyData(ui_field) |
525 | + form = self.GetPyData(item) |
526 | + fields = [] |
527 | + for index, ui_field in enumerate(self.GetItemChildren(item)): |
528 | + label, value_as_string = self.GetPyData(ui_field) |
529 | field = form._get_field(label) |
530 | if field.dirty: |
531 | - #overrule if dirty |
532 | + # overrule if dirty |
533 | value_as_string = field.get_as_string() |
534 | self.SetItemText(ui_field, |
535 | self.tree_label(label, value_as_string)) |
536 | self.SetPyData(ui_field, (label, value_as_string)) |
537 | field.dirty = False |
538 | - fields.append((ui_field,label,value_as_string)) |
539 | + fields.append((ui_field, label, value_as_string)) |
540 | return fields |
541 | |
542 | def has_forms(self): |
543 | return self.GetCount() |
544 | |
545 | def toggle_form_item(self, item, event): |
546 | - root = self.GetRootItem() |
547 | + root = self.GetRootItem() |
548 | if item == root: |
549 | event.Skip() |
550 | else: |
551 | - parent = self.GetItemParent(item) |
552 | + parent = self.GetItemParent(item) |
553 | if parent == root: |
554 | - image = self.GetItemImage(item,wx.TreeItemIcon_Normal) |
555 | + image = self.GetItemImage(item, wx.TreeItemIcon_Normal) |
556 | if image != -1: |
557 | self.enable_form_item(item, |
558 | not self.is_form_enabled(item)) |
559 | self.set_dirty(True) |
560 | |
561 | - def set_form_field_value(self,item, value_as_string): |
562 | - label, old = self.GetPyData(item) |
563 | - form = self.get_form(item,label) |
564 | - field = form._get_field(label) |
565 | + def set_form_field_value(self, item, value_as_string): |
566 | + label, old = self.GetPyData(item) |
567 | + form = self.get_form(item, label) |
568 | + field = form._get_field(label) |
569 | value_as_string = field.fix_string(value_as_string) |
570 | if value_as_string != old: |
571 | - #test-validate the user input (see formField.Field.get) |
572 | + # test-validate the user input (see formField.Field.get) |
573 | try: |
574 | - if isinstance(field,formField.PixelField): |
575 | - field.get_size(IMAGE_TEST_INFO, 100, 100,label, |
576 | + if isinstance(field, formField.PixelField): |
577 | + field.get_size(IMAGE_TEST_INFO, 100, 100, label, |
578 | value_as_string) |
579 | - #100 is just some dummy value for base, dpi |
580 | + # 100 is just some dummy value for base, dpi |
581 | else: |
582 | field.get(IMAGE_TEST_INFO, label=label, |
583 | value_as_string=value_as_string, test=True) |
584 | self.set_dirty(True) |
585 | except formField.ValidationError, details: |
586 | - reason = exception_to_unicode(details,WX_ENCODING) |
587 | + reason = exception_to_unicode(details, WX_ENCODING) |
588 | self.show_error(reason) |
589 | if formField.Field.safe: |
590 | return |
591 | if value_as_string == '': |
592 | - #hack, fix me |
593 | + # hack, fix me |
594 | value_as_string = ' ' |
595 | - self.SetPyData(item,(label,value_as_string)) |
596 | - self.SetItemText(item,self.tree_label(label,value_as_string)) |
597 | - form.set_field_as_string(label,value_as_string) |
598 | + self.SetPyData(item, (label, value_as_string)) |
599 | + self.SetItemText(item, self.tree_label(label, value_as_string)) |
600 | + form.set_field_as_string(label, value_as_string) |
601 | |
602 | - def set_form_field_value_selected(self,value): |
603 | - item = self.GetSelection() |
604 | + def set_form_field_value_selected(self, value): |
605 | + item = self.GetSelection() |
606 | if self.GetItemParent(item) == self.GetRootItem(): |
607 | return |
608 | if item and self.GetPyData(item): |
609 | field = self.get_form_field(item) |
610 | - if not (isinstance(field,formField.ChoiceField) \ |
611 | - or isinstance(field,formField.BooleanField) \ |
612 | - or isinstance(field,formField.ColorField) \ |
613 | - or isinstance(field,formField.SliderField)): |
614 | - self.set_form_field_value(item,value) |
615 | + if not (isinstance(field, formField.ChoiceField) \ |
616 | + or isinstance(field, formField.BooleanField) \ |
617 | + or isinstance(field, formField.ColorField) \ |
618 | + or isinstance(field, formField.SliderField)): |
619 | + self.set_form_field_value(item, value) |
620 | |
621 | - #---selected form |
622 | - def append_form_by_label_to_selected(self,label): |
623 | - item = self.get_form_selected() |
624 | - return self.append_form_by_label(item,label) |
625 | + # ---selected form |
626 | + def append_form_by_label_to_selected(self, label): |
627 | + item = self.get_form_selected() |
628 | + return self.append_form_by_label(item, label) |
629 | |
630 | def enable_selected_form(self, bool): |
631 | - self.enable_form_item(self.get_form_selected(),bool) |
632 | + self.enable_form_item(self.get_form_selected(), bool) |
633 | |
634 | def get_form_selected(self): |
635 | if self.has_forms(): |
636 | @@ -320,121 +330,124 @@ |
637 | def move_form_selected_up(self): |
638 | self.MoveChildUp(self.get_form_selected()) |
639 | |
640 | - def update_form_relevance(self,field_item): |
641 | + def update_form_relevance(self, field_item): |
642 | """Conditional form""" |
643 | - item = self.get_form_item(field_item) |
644 | - form = self.GetPyData(item) |
645 | - if not hasattr(form,'get_relevant_field_labels'): |
646 | + item = self.get_form_item(field_item) |
647 | + form = self.GetPyData(item) |
648 | + if not hasattr(form, 'get_relevant_field_labels'): |
649 | return False |
650 | - all = form._get_fields() |
651 | - relevant = form.get_relevant_field_labels() |
652 | - ui_index = 0 |
653 | - ui = self.get_form_fields_visible(item, form) |
654 | - ui_labels = [f[1] for f in ui] |
655 | - ui_field,ui_label,ui_value_as_string = get_index(ui,ui_index) |
656 | - ui_field_prev = None |
657 | - #print '_'*40 |
658 | + all = form._get_fields() |
659 | + relevant = form.get_relevant_field_labels() |
660 | + ui_index = 0 |
661 | + ui = self.get_form_fields_visible(item, form) |
662 | + ui_labels = [f[1] for f in ui] |
663 | + ui_field, ui_label, ui_value_as_string = get_index(ui, ui_index) |
664 | + ui_field_prev = None |
665 | + # print '_'*40 |
666 | for label, field in all.items(): |
667 | if not field.visible: |
668 | continue |
669 | - #print 'item=',item, ', label=',label, ', ui_field=',field, ', ui_label=',ui_label, ', child =',self.ItemHasChildren(item), ', prev =',ui_field_prev |
670 | |
671 | + # print 'item=', item, ', label=', label, ', ui_field=', field, ',\ |
672 | + # ui_label=', ui_label, ', child =', self.ItemHasChildren(item),\ |
673 | + # ', prev =', ui_field_prev |
674 | |
675 | next_ui = False |
676 | deleted = False |
677 | - #relevant |
678 | + # relevant |
679 | if label in relevant: |
680 | if label == ui_label: |
681 | - #already there |
682 | + # already there |
683 | next_ui = True |
684 | elif ui_field_prev: |
685 | - #insert after previous ui field |
686 | - #print 'prev value',self.GetPyData(ui_field_prev) |
687 | - ui_field_prev = self.append_field(item,label,field, |
688 | + # insert after previous ui field |
689 | + # print 'prev value', self.GetPyData(ui_field_prev) |
690 | + ui_field_prev = self.append_field(item, label, field, |
691 | self.InsertItem, ui_field_prev) |
692 | elif self.ItemHasChildren(item): |
693 | - #insert before first ui field |
694 | - ui_field_prev = self.append_field(item,label,field, |
695 | - self.InsertItemBefore,self.GetFirstChild(item)) |
696 | + # insert before first ui field |
697 | + ui_field_prev = self.append_field(item, label, field, |
698 | + self.InsertItemBefore, self.GetFirstChild(item)) |
699 | else: |
700 | - #append as first element |
701 | - ui_field_prev = self.append_field(item,label,field) |
702 | - #not relevant |
703 | + # append as first element |
704 | + ui_field_prev = self.append_field(item, label, field) |
705 | + # not relevant |
706 | elif label in ui_labels: |
707 | - #save values |
708 | - form.set_field_as_string(ui_label,ui_value_as_string) |
709 | - #remove |
710 | + # save values |
711 | + form.set_field_as_string(ui_label, ui_value_as_string) |
712 | + # remove |
713 | self.Delete(ui_field) |
714 | next_ui = True |
715 | deleted = True |
716 | - #next ui |
717 | + # next ui |
718 | if next_ui: |
719 | if ui_field and not deleted: |
720 | - #deleted: we don't want to reference to dead objects |
721 | + # deleted: we don't want to reference to dead objects |
722 | ui_field_prev = ui_field |
723 | ui_index += 1 |
724 | - ui_field,ui_label,ui_value_as_string = \ |
725 | - get_index(ui,ui_index) |
726 | + ui_field, ui_label, ui_value_as_string = \ |
727 | + get_index(ui, ui_index) |
728 | return True |
729 | |
730 | def remove_selected_form(self): |
731 | - form = self.get_form_selected() |
732 | + form = self.get_form_selected() |
733 | if form is -1: |
734 | return False |
735 | else: |
736 | self.Delete(form) |
737 | return True |
738 | |
739 | - #---last form |
740 | - def append_form_by_label_to_last(self,label): |
741 | - item = self.get_last_form() |
742 | - self.append_form_by_label(item,label) |
743 | + # ---last form |
744 | + def append_form_by_label_to_last(self, label): |
745 | + item = self.get_last_form() |
746 | + self.append_form_by_label(item, label) |
747 | |
748 | def get_last_form(self): |
749 | return self.GetLastChild(self.GetRootItem()) |
750 | |
751 | - #---popup |
752 | - def create_popup(self,item): |
753 | + # ---popup |
754 | + def create_popup(self, item): |
755 | """Connect formField.field to popup.Ctrl (VIP!)""" |
756 | - field = self.get_form_field(item) |
757 | - label, value = self.GetItemText(item).split(FIELD_DELIMITER,1) |
758 | - pos, offset, size = self.get_popup_pos_offset_size(item) |
759 | - typ = field.__class__.__name__.replace('Field','') |
760 | + field = self.get_form_field(item) |
761 | + label, value = self.GetItemText(item).split(FIELD_DELIMITER, 1) |
762 | + pos, offset, size = self.get_popup_pos_offset_size(item) |
763 | + typ = field.__class__.__name__.replace('Field', '') |
764 | + |
765 | def on_change(value_as_string): |
766 | field.set_as_string(value_as_string) |
767 | self.update_form_relevance(item) |
768 | - if isinstance(field,formField.SliderField): |
769 | - extra = {'minValue' : field.min, 'maxValue' : field.max} |
770 | - elif isinstance(field,formField.ChoiceField): |
771 | - extra = {'choices' : field.choices, 'on_change':on_change} |
772 | - typ = 'Choice' |
773 | - elif isinstance(field,formField.DictionaryReadFileField): |
774 | + if isinstance(field, formField.SliderField): |
775 | + extra = {'minValue': field.min, 'maxValue': field.max} |
776 | + elif isinstance(field, formField.ChoiceField): |
777 | + extra = {'choices': field.choices, 'on_change': on_change} |
778 | + typ = 'Choice' |
779 | + elif isinstance(field, formField.DictionaryReadFileField): |
780 | if field.dictionary is None: |
781 | field.init_dictionary() |
782 | - extra = {'extensions' : field.extensions, |
783 | + extra = {'extensions': field.extensions, |
784 | 'dictionary': field.dictionary} |
785 | - if isinstance(field,formField.ImageDictionaryField): |
786 | + if isinstance(field, formField.ImageDictionaryField): |
787 | extra['show_path'] = False |
788 | extra['on_change'] = on_change |
789 | - if isinstance(field,formField.ImageDictionaryReadFileField): |
790 | + if isinstance(field, formField.ImageDictionaryReadFileField): |
791 | typ = 'ImageDictionaryFile' |
792 | extra['dialog'] = field.dialog |
793 | extra['icon_size'] = field.icon_size |
794 | - elif not isinstance(field,formField.FontFileField): |
795 | + elif not isinstance(field, formField.FontFileField): |
796 | typ = 'DictionaryFile' |
797 | - elif isinstance(field,formField.FileField): |
798 | - extra = {'extensions' : field.extensions} |
799 | - typ = 'LabelFile' |
800 | - elif hasattr(field,'choices'): |
801 | - extra = {'choices' : field.choices, 'on_change':on_change} |
802 | - elif isinstance(field,formField.BooleanField): |
803 | - extra = {'on_change':on_change} |
804 | + elif isinstance(field, formField.FileField): |
805 | + extra = {'extensions': field.extensions} |
806 | + typ = 'LabelFile' |
807 | + elif hasattr(field, 'choices'): |
808 | + extra = {'choices': field.choices, 'on_change': on_change} |
809 | + elif isinstance(field, formField.BooleanField): |
810 | + extra = {'on_change': on_change} |
811 | else: |
812 | - extra = {} |
813 | - self.popup_item = item |
814 | - self.popup = popup.EditPanel(self, pos = pos, offset = offset, |
815 | - size = size, label = _(label) + FIELD_DELIMITER, |
816 | - value = value, extra = extra, typ = typ, |
817 | - border = 1, CtrlMixin = self.CtrlMixin) |
818 | + extra = {} |
819 | + self.popup_item = item |
820 | + self.popup = popup.EditPanel(self, pos=pos, offset=offset, |
821 | + size=size, label=_(label) + FIELD_DELIMITER, |
822 | + value=value, extra=extra, typ=typ, |
823 | + border=1, CtrlMixin=self.CtrlMixin) |
824 | self.popup.Show() |
825 | self.resize_popup() |
826 | if not isinstance(field, formField.FontFileField): |
827 | @@ -443,12 +456,12 @@ |
828 | self.evt_leave_window = True |
829 | |
830 | def create_popup_selected(self): |
831 | - item = self.GetSelection() |
832 | + item = self.GetSelection() |
833 | if self.GetItemParent(item) == self.GetRootItem(): |
834 | return |
835 | self.create_popup(item) |
836 | |
837 | - def close_popup(self,event=None): |
838 | + def close_popup(self, event=None): |
839 | frame = wx.GetTopLevelParent(self) |
840 | if frame and self.evt_leave_window: |
841 | frame.Unbind(wx.EVT_LEAVE_WINDOW) |
842 | @@ -456,48 +469,49 @@ |
843 | if self.popup: |
844 | value_as_string = self.popup.Close() |
845 | self.set_form_field_value(self.popup_item, value_as_string) |
846 | - #self.update_form_relevance(self.popup_item) |
847 | - self.popup = self.popup_item = None |
848 | - |
849 | -## This would be logical but only works in wxPython2.6 |
850 | -## def get_popup_pos_offset_size(self, item): |
851 | -## text_only_rect = self.GetBoundingRect(item,textOnly=True) |
852 | -## rect = self.GetBoundingRect(item,textOnly=False) |
853 | -## pos = rect.GetPosition() |
854 | -## size = rect.GetSize() |
855 | -## offset = text_only_rect.GetPosition()[0] - pos[0] |
856 | -## print self.GetClientSize(),self.GetSize(),self.GetRect(),text_only_rect,rect |
857 | -## return pos, offset, size |
858 | -## |
859 | - |
860 | - #A bit unlogical but works both in wxPython2.6 and 2.8 |
861 | + # self.update_form_relevance(self.popup_item) |
862 | + self.popup = self.popup_item = None |
863 | + |
864 | +# # This would be logical but only works in wxPython2.6 |
865 | +# # def get_popup_pos_offset_size(self, item): |
866 | +# # text_only_rect = self.GetBoundingRect(item, textOnly=True) |
867 | +# # rect = self.GetBoundingRect(item, textOnly=False) |
868 | +# # pos = rect.GetPosition() |
869 | +# # size = rect.GetSize() |
870 | +# # offset = text_only_rect.GetPosition()[0] - pos[0] |
871 | +# # print self.GetClientSize(), self.GetSize(), self.GetRect(),\ |
872 | +# # text_only_rect, rect |
873 | +# # return pos, offset, size |
874 | +# # |
875 | + |
876 | + # A bit unlogical but works both in wxPython2.6 and 2.8 |
877 | def get_popup_pos_offset_size(self, item): |
878 | - text_only_rect = self.GetBoundingRect(item,textOnly=True) |
879 | - rect = self.GetRect() |
880 | - pos = rect[0],text_only_rect[1] |
881 | - offset = text_only_rect[0]-rect[0] |
882 | - size = self.GetClientSize()[0],text_only_rect.GetSize()[1] |
883 | + text_only_rect = self.GetBoundingRect(item, textOnly=True) |
884 | + rect = self.GetRect() |
885 | + pos = rect[0], text_only_rect[1] |
886 | + offset = text_only_rect[0] - rect[0] |
887 | + size = self.GetClientSize()[0], text_only_rect.GetSize()[1] |
888 | return pos, offset, size |
889 | |
890 | def resize_popup(self): |
891 | if not(self.popup is None): |
892 | - item = self.GetSelection() |
893 | - pos, offset, size = self.get_popup_pos_offset_size(item) |
894 | - popup = self.popup |
895 | + item = self.GetSelection() |
896 | + pos, offset, size = self.get_popup_pos_offset_size(item) |
897 | + popup = self.popup |
898 | popup.Freeze() |
899 | popup.SetSize(size) |
900 | popup.SetPosition(pos) |
901 | popup.Layout() |
902 | popup.Thaw() |
903 | |
904 | - #---events |
905 | + # ---events |
906 | def events(self): |
907 | - #events |
908 | + # events |
909 | self.Bind(wx.EVT_TREE_SEL_CHANGING, self.on_sel_changing, self) |
910 | self.Bind(wx.EVT_TREE_SEL_CHANGED, self.on_sel_changed, self) |
911 | self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.on_item_activated, self) |
912 | - self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK,self.on_select,self) |
913 | - self.Bind(wx.EVT_LEFT_DOWN,self.on_left_down,self) |
914 | + self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.on_select, self) |
915 | + self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down, self) |
916 | |
917 | def enable_collapse_automatic(self, state): |
918 | if state: |
919 | @@ -516,135 +530,139 @@ |
920 | if child != item and self.IsExpanded(child): |
921 | self.Collapse(child) |
922 | |
923 | - def on_left_down(self,event): |
924 | + def on_left_down(self, event): |
925 | self.close_popup() |
926 | event.Skip() |
927 | |
928 | - def on_item_activated(self,event): |
929 | - item = event.GetItem() |
930 | + def on_item_activated(self, event): |
931 | + item = event.GetItem() |
932 | if self.is_form(item): |
933 | self.toggle_form_item(item, event) |
934 | else: |
935 | self.on_sel_changed(event) |
936 | |
937 | - def on_sel_changing(self,event): |
938 | + def on_sel_changing(self, event): |
939 | self.close_popup() |
940 | |
941 | - def on_sel_changed(self,event): |
942 | + def on_sel_changed(self, event): |
943 | self.close_popup() |
944 | - item = event.GetItem() |
945 | - self._field_selected = self.is_field(item) |
946 | + item = event.GetItem() |
947 | + self._field_selected = self.is_field(item) |
948 | if self._field_selected: |
949 | self.create_popup(item) |
950 | elif self.collapse_automatic: |
951 | - #maybe better always |
952 | + # maybe better always |
953 | self.Expand(item) |
954 | |
955 | - def on_select(self,event): |
956 | + def on_select(self, event): |
957 | self.on_sel_changing(event) |
958 | - self.SelectItem(event.GetItem(),True) |
959 | + self.SelectItem(event.GetItem(), True) |
960 | event.Skip() |
961 | |
962 | - #---checks |
963 | - def is_field(self,item): |
964 | - return self.GetItemParent(item)!= self.GetRootItem() and \ |
965 | + # ---checks |
966 | + def is_field(self, item): |
967 | + return self.GetItemParent(item) != self.GetRootItem() and \ |
968 | item != self.GetRootItem() |
969 | |
970 | def is_field_selected(self): |
971 | return self._field_selected |
972 | |
973 | - def is_form(self,item): |
974 | - return self.GetItemParent(item)== self.GetRootItem() |
975 | + def is_form(self, item): |
976 | + return self.GetItemParent(item) == self.GetRootItem() |
977 | |
978 | - def is_form_enabled(self,item): |
979 | - form = self.GetPyData(item) |
980 | - return self.GetItemImage(item,wx.TreeItemIcon_Normal) == form.icon_tree_id[True] |
981 | + def is_form_enabled(self, item): |
982 | + form = self.GetPyData(item) |
983 | + return self.GetItemImage(item, wx.TreeItemIcon_Normal) ==\ |
984 | + form.icon_tree_id[True] |
985 | |
986 | def is_form_selected(self): |
987 | return not self._field_selected |
988 | |
989 | + |
990 | def example(): |
991 | global _ |
992 | _ = str |
993 | import sys |
994 | |
995 | class Form1(formField.Form): |
996 | - label = 'form1' |
997 | + label = 'form1' |
998 | + |
999 | def __init__(self): |
1000 | formField.Form.__init__(self, |
1001 | - foo1=formField.ChoiceField(value='a',choices=('a','b'))) |
1002 | + foo1=formField.ChoiceField(value='a', choices=('a', 'b'))) |
1003 | |
1004 | class Form2(formField.Form): |
1005 | - label = 'form2' |
1006 | + label = 'form2' |
1007 | + |
1008 | def __init__(self): |
1009 | formField.Form.__init__(self, |
1010 | foo2=formField.PixelField(value='100')) |
1011 | |
1012 | class Form3(formField.Form): |
1013 | - label = 'form3' |
1014 | + label = 'form3' |
1015 | + |
1016 | def __init__(self): |
1017 | formField.Form.__init__(self, |
1018 | foo2=formField.FileSizeField(value='100')) |
1019 | |
1020 | - form_factory = { |
1021 | - 'form1' : Form1, |
1022 | - 'form2' : Form2, |
1023 | - 'form3' : Form3, |
1024 | + form_factory = { |
1025 | + 'form1': Form1, |
1026 | + 'form2': Form2, |
1027 | + 'form3': Form3, |
1028 | } |
1029 | - form4 = formField.Form(foo3=formField.SliderField(value='100', |
1030 | - minValue=0,maxValue=100)) |
1031 | - forms = [x() for x in form_factory.values()] #+ [form4] |
1032 | - |
1033 | - class Tree(wx.TreeCtrl,TreeMixin): |
1034 | - |
1035 | - def __init__(self,parent,form_factory,*args,**keyw): |
1036 | + form4 = formField.Form(foo3=formField.SliderField(value='100', |
1037 | + minValue=0, maxValue=100)) |
1038 | + forms = [x() for x in form_factory.values()] # + [form4] |
1039 | + |
1040 | + class Tree(wx.TreeCtrl, TreeMixin): |
1041 | + |
1042 | + def __init__(self, parent, form_factory, *args, **keyw): |
1043 | |
1044 | class I18n_CtrlMixin: |
1045 | """Fake example of a Mixin""" |
1046 | - _to_local = str |
1047 | + _to_local = str |
1048 | _to_english = str |
1049 | - _to_local = staticmethod(_to_local) |
1050 | + _to_local = staticmethod(_to_local) |
1051 | _to_english = staticmethod(_to_english) |
1052 | |
1053 | - wx.TreeCtrl.__init__(self,parent,style=TR_DEFAULT_STYLE,*args,**keyw) |
1054 | + wx.TreeCtrl.__init__(self, parent, style=TR_DEFAULT_STYLE, *args,\ |
1055 | + **keyw) |
1056 | TreeMixin.__init__(self, |
1057 | - form_factory= form_factory, |
1058 | - CtrlMixin = I18n_CtrlMixin, |
1059 | - icon_size = (28,28), |
1060 | - show_error = parent.show_error, |
1061 | - set_dirty = parent.set_dirty, |
1062 | - ) |
1063 | + form_factory=form_factory, |
1064 | + CtrlMixin=I18n_CtrlMixin, |
1065 | + icon_size=(28, 28), |
1066 | + show_error=parent.show_error, |
1067 | + set_dirty=parent.set_dirty,) |
1068 | |
1069 | class Frame(wx.Frame): |
1070 | - def show_error(self,message): |
1071 | + def show_error(self, message): |
1072 | sys.stdout.write(message + '\n') |
1073 | |
1074 | - def set_dirty(self,bool): |
1075 | - self.SetTitle(['','*'][bool] + 'treeEdit test') |
1076 | + def set_dirty(self, bool): |
1077 | + self.SetTitle(['', '*'][bool] + 'treeEdit test') |
1078 | |
1079 | class App(wx.App): |
1080 | - def OnInit(self,*args,**keyw): |
1081 | - frame = Frame(None) |
1082 | + def OnInit(self, *args, **keyw): |
1083 | + frame = Frame(None) |
1084 | frame.set_dirty(False) |
1085 | |
1086 | - sizer = wx.BoxSizer(wx.VERTICAL) |
1087 | - self.tree = Tree(frame,form_factory) |
1088 | + sizer = wx.BoxSizer(wx.VERTICAL) |
1089 | + self.tree = Tree(frame, form_factory) |
1090 | self.tree.append_forms(forms) |
1091 | - sizer.Add(self.tree,proportion=1, flag=wx.EXPAND) |
1092 | + sizer.Add(self.tree, proportion=1, flag=wx.EXPAND) |
1093 | frame.SetSizer(sizer) |
1094 | sizer.Fit(frame) |
1095 | |
1096 | - frame.SetSize((300,300)) |
1097 | + frame.SetSize((300, 300)) |
1098 | frame.Layout() |
1099 | frame.Show() |
1100 | self.SetTopWindow(frame) |
1101 | return True |
1102 | |
1103 | - |
1104 | app = App(0) |
1105 | app.MainLoop() |
1106 | |
1107 | -#---disabled |
1108 | +# ---disabled |
1109 | ICON_DISABLED = \ |
1110 | 'x\xda\x01I\x03\xb6\xfc\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x1c\ |
1111 | \x00\x00\x00\x1c\x08\x06\x00\x00\x00r\r\xdf\x94\x00\x00\x00\x04sBIT\x08\x08\ |
1112 | |
1113 | === modified file 'phatch/lib/pyWx/wildcard.py' |
1114 | --- phatch/lib/pyWx/wildcard.py 2010-03-06 18:12:03 +0000 |
1115 | +++ phatch/lib/pyWx/wildcard.py 2010-03-07 00:55:24 +0000 |
1116 | @@ -12,7 +12,8 @@ |
1117 | # |
1118 | # You should have received a copy of the GNU General Public License |
1119 | # along with this program. If not, see http://www.gnu.org/licenses/ |
1120 | - |
1121 | +# |
1122 | +# Follow PEP8 |
1123 | import sys |
1124 | |
1125 | |
1126 | |
1127 | === modified file 'phatch/lib/pyWx/wxcheck.py' |
1128 | --- phatch/lib/pyWx/wxcheck.py 2010-02-24 21:00:07 +0000 |
1129 | +++ phatch/lib/pyWx/wxcheck.py 2010-03-07 00:55:24 +0000 |
1130 | @@ -9,22 +9,26 @@ |
1131 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
1132 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1133 | # GNU General Public License for more details. |
1134 | -# |
1135 | +# |
1136 | # You should have received a copy of the GNU General Public License |
1137 | # along with this program. If not, see http://www.gnu.org/licenses/ |
1138 | +# |
1139 | +# Follow PEP8 |
1140 | |
1141 | import os |
1142 | import sys |
1143 | from subprocess import call |
1144 | from lib.unicoding import ENCODING |
1145 | |
1146 | + |
1147 | def _t(x): |
1148 | - return _(x).encode(ENCODING,'replace') |
1149 | - |
1150 | -def ensure(recommended,minimal): |
1151 | + return _(x).encode(ENCODING, 'replace') |
1152 | + |
1153 | + |
1154 | +def ensure(recommended, minimal): |
1155 | """Ensures the minimal version of wxPython is installed. |
1156 | - minimal: as string (eg. '2.6')""" |
1157 | - |
1158 | + |
1159 | #wxversion |
1160 | try: |
1161 | import wxversion |
1162 | @@ -36,31 +40,42 @@ |
1163 | return wx |
1164 | except ImportError: |
1165 | sys.stdout.write(_t('Warning: python-wxversion is not installed.\n')) |
1166 | - |
1167 | + |
1168 | #wxversion failed, import wx anyway |
1169 | - params = {'recommended':recommended, 'minimal':minimal} |
1170 | + params = {'recommended': recommended, 'minimal': minimal} |
1171 | try: |
1172 | import wx |
1173 | except ImportError: |
1174 | - message = _t('Error: wxPython %(recommended)s (or at least %(minimal)s) can not be found, but is required.')%params +\ |
1175 | + message = _t('Error: wxPython %(recommended)s' + \ |
1176 | + ' (or at least %(minimal)s) can not' + \ |
1177 | + ' be found, but is required.' |
1178 | + ) % params +\ |
1179 | '\n\n' + _t('Please (re)install it.') |
1180 | sys.stderr.write(message) |
1181 | if sys.platform.startswith('linux') and \ |
1182 | os.path.exists('/usr/bin/zenity'): |
1183 | - call('''zenity --error --text="%s"\n\n'''%message +\ |
1184 | - _t('''This application needs 'python-wxversion' and 'python-wxgtk%(recommended)s' (or at least 'python-wxgtk%(minimal)s').''')%params,shell=True) |
1185 | + call('''zenity --error --text="%s"\n\n''' % message + \ |
1186 | + _t('''This application needs 'python-wxversion' ''' + \ |
1187 | + '''and 'python-wxgtk%(recommended)s' ''' + \ |
1188 | + '''(or at least 'python-wxgtk%(minimal)s').''' |
1189 | + ) % params, shell=True) |
1190 | sys.exit() |
1191 | - |
1192 | + |
1193 | #wxversion failed but wx is available, check version again |
1194 | - params['version'] = wx.VERSION_STRING |
1195 | - if wx.VERSION_STRING < minimal: |
1196 | + params['version'] = wx.VERSION_STRING |
1197 | + if wx.VERSION_STRING < minimal: |
1198 | + |
1199 | class MyApp(wx.App): |
1200 | def OnInit(self): |
1201 | result = wx.MessageBox( |
1202 | - _t("This application is known to be compatible with\nwxPython version(s) %(recommended)s (or at least %(minimal)s),\nbut you have %(version)s installed.")%params + "\n\n" +\ |
1203 | + _t("This application is known to be compatible" + \ |
1204 | + " with\nwxPython version(s) %(recommended)s" + \ |
1205 | + " (or at least %(minimal)s),\nbut you have " + \ |
1206 | + "%(version)s installed." |
1207 | + ) % params + "\n\n" +\ |
1208 | _t("Please upgrade your wxPython."), |
1209 | _t("wxPython Version Error"), |
1210 | - style = wx.ICON_ERROR) |
1211 | + style=wx.ICON_ERROR) |
1212 | return False |
1213 | app = MyApp() |
1214 | app.MainLoop() |
1215 | |
1216 | === modified file 'phatch/pyWx/__init__.py' |
1217 | --- phatch/pyWx/__init__.py 2010-03-06 17:13:56 +0000 |
1218 | +++ phatch/pyWx/__init__.py 2010-03-07 00:55:24 +0000 |
1219 | @@ -15,3 +15,5 @@ |
1220 | # along with this program. If not, see http://www.gnu.org/licenses/ |
1221 | # |
1222 | # Phatch recommends SPE (http://pythonide.stani.be) for editing python files. |
1223 | +# |
1224 | +# Follow PEP8 |
1225 | |
1226 | === modified file 'phatch/pyWx/images.py' |
1227 | --- phatch/pyWx/images.py 2010-03-06 17:40:31 +0000 |
1228 | +++ phatch/pyWx/images.py 2010-03-07 00:55:24 +0000 |
1229 | @@ -15,7 +15,7 @@ |
1230 | # along with this program. If not, see http://www.gnu.org/licenses/ |
1231 | # |
1232 | # Phatch recommends SPE (http://pythonide.stani.be) for editing python files. |
1233 | - |
1234 | +# Follow PEP8 |
1235 | # Embedded images are specially designed by Igor Kekeljevic for Phatch. |
1236 | |
1237 | import sys |
1238 | |
1239 | === modified file 'phatch/pyWx/nuovext.py' |
1240 | --- phatch/pyWx/nuovext.py 2010-03-06 17:13:32 +0000 |
1241 | +++ phatch/pyWx/nuovext.py 2010-03-07 00:55:24 +0000 |
1242 | @@ -21,6 +21,8 @@ |
1243 | # - Icon download: http://www.gnome-look.org/content/download.php? |
1244 | # content=26448&id=1&tan=15504822&PHPSESSID=34ec3de1af33e253ee03357a124bfbeb |
1245 | # - License: GPL |
1246 | +# |
1247 | +# Follow PEP8 |
1248 | |
1249 | import wx |
1250 | from lib.pyWx import graphics |
1251 | |
1252 | === modified file 'phatch/pyWx/plugin.py' |
1253 | --- phatch/pyWx/plugin.py 2010-03-06 17:10:25 +0000 |
1254 | +++ phatch/pyWx/plugin.py 2010-03-07 00:55:24 +0000 |
1255 | @@ -17,6 +17,9 @@ |
1256 | # along with this program. If not, see http://www.gnu.org/licenses/ |
1257 | # |
1258 | # Phatch recommends SPE (http://pythonide.stani.be) for editing python files. |
1259 | +# |
1260 | +# Follow PEP8 |
1261 | + |
1262 | import os |
1263 | import sys |
1264 | import wx |
1265 | |
1266 | === modified file 'phatch/pyWx/wxGlade/__init__.py' |
1267 | --- phatch/pyWx/wxGlade/__init__.py 2010-03-06 17:14:22 +0000 |
1268 | +++ phatch/pyWx/wxGlade/__init__.py 2010-03-07 00:55:24 +0000 |
1269 | @@ -15,3 +15,5 @@ |
1270 | # along with this program. If not, see http://www.gnu.org/licenses/ |
1271 | # |
1272 | # Phatch recommends SPE (http://pythonide.stani.be) for editing python files. |
1273 | +# |
1274 | +# Follow PEP8 |