Merge lp:~elachuni/software-center/pep8-test-part2 into lp:software-center
- pep8-test-part2
- Merge into trunk
Proposed by
Anthony Lenton
Status: | Merged |
---|---|
Merged at revision: | 2823 |
Proposed branch: | lp:~elachuni/software-center/pep8-test-part2 |
Merge into: | lp:software-center |
Diff against target: |
1039 lines (+155/-205) 2 files modified
softwarecenter/ui/gtk3/widgets/unused__pathbar.py (+144/-203) test/test_pep8.py (+11/-2) |
To merge this branch: | bzr merge lp:~elachuni/software-center/pep8-test-part2 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Kiwinote | Approve | ||
Review via email: mp+96579@code.launchpad.net |
Commit message
Description of the change
This branch makes the pep8 test pass for a single file: softwarecenter/
I realize this file is currently unused, but the test will still complain about it as it's a .py file in the source :)
Besides fixing the style issues pointed out by the test I removed leftover argument-less "return" statements at the end of functions, the plan would be to remove these across the board too, please let me know if you prefer them as is.
To post a comment you must log in.
Revision history for this message
Gary Lasker (gary-lasker) wrote : | # |
Definitely no argument from me on the removal of argument-less returns. :)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'softwarecenter/ui/gtk3/widgets/unused__pathbar.py' |
2 | --- softwarecenter/ui/gtk3/widgets/unused__pathbar.py 2011-08-10 07:35:53 +0000 |
3 | +++ softwarecenter/ui/gtk3/widgets/unused__pathbar.py 2012-03-08 14:18:22 +0000 |
4 | @@ -13,7 +13,7 @@ |
5 | # pi constants |
6 | from math import pi |
7 | |
8 | -PI = pi |
9 | +PI = pi |
10 | PI_OVER_180 = pi / 180 |
11 | |
12 | |
13 | @@ -30,7 +30,7 @@ |
14 | |
15 | If the Shape is direction dependent, the Shape MUST |
16 | implement <_layout_ltr> and <_layout_rtl> methods. |
17 | - |
18 | + |
19 | If the Shape is not direction dependent, then it simply can |
20 | override the <layout> method. |
21 | |
22 | @@ -51,7 +51,6 @@ |
23 | self.name = 'Shapeless' |
24 | self.hadjustment = 0 |
25 | self._color = 1, 0, 0 |
26 | - return |
27 | |
28 | def __eq__(self, other): |
29 | return self.name == other.name |
30 | @@ -61,7 +60,6 @@ |
31 | self._layout_ltr(cr, x, y, w, h, r, aw) |
32 | else: |
33 | self._layout_rtl(cr, x, y, w, h, r, aw) |
34 | - return |
35 | |
36 | |
37 | class ShapeRoundedRect(Shape): |
38 | @@ -79,16 +77,14 @@ |
39 | def __init__(self, direction=Gtk.TextDirection.LTR): |
40 | Shape.__init__(self, direction) |
41 | self.name = 'RoundedRect' |
42 | - return |
43 | |
44 | def layout(self, cr, x, y, w, h, r, aw): |
45 | cr.new_sub_path() |
46 | - cr.arc(r+x, r+y, r, PI, 270*PI_OVER_180) |
47 | - cr.arc(x+w-r, r+y, r, 270*PI_OVER_180, 0) |
48 | - cr.arc(x+w-r, y+h-r, r, 0, 90*PI_OVER_180) |
49 | - cr.arc(r+x, y+h-r, r, 90*PI_OVER_180, PI) |
50 | + cr.arc(r + x, r + y, r, PI, 270 * PI_OVER_180) |
51 | + cr.arc(x + w - r, r + y, r, 270 * PI_OVER_180, 0) |
52 | + cr.arc(x + w - r, y + h - r, r, 0, 90 * PI_OVER_180) |
53 | + cr.arc(r + x, y + h - r, r, 90 * PI_OVER_180, PI) |
54 | cr.close_path() |
55 | - return |
56 | |
57 | |
58 | class ShapeStartArrow(Shape): |
59 | @@ -96,34 +92,31 @@ |
60 | def __init__(self, direction=Gtk.TextDirection.LTR): |
61 | Shape.__init__(self, direction) |
62 | self.name = 'StartArrow' |
63 | - return |
64 | |
65 | def _layout_ltr(self, cr, x, y, w, h, r, aw): |
66 | - haw = aw/2 |
67 | + haw = aw / 2 |
68 | |
69 | cr.new_sub_path() |
70 | - cr.arc(r+x, r+y, r, PI, 270*PI_OVER_180) |
71 | + cr.arc(r + x, r + y, r, PI, 270 * PI_OVER_180) |
72 | |
73 | # arrow head |
74 | - cr.line_to(x+w-haw, y) |
75 | - cr.line_to(x+w+haw, y+(h/2)) |
76 | - cr.line_to(x+w-haw, y+h) |
77 | - |
78 | - cr.arc(r+x, y+h-r, r, 90*PI_OVER_180, PI) |
79 | + cr.line_to(x + w - haw, y) |
80 | + cr.line_to(x + w + haw, y + (h / 2)) |
81 | + cr.line_to(x + w - haw, y + h) |
82 | + |
83 | + cr.arc(r + x, y + h - r, r, 90 * PI_OVER_180, PI) |
84 | cr.close_path() |
85 | - return |
86 | |
87 | def _layout_rtl(self, cr, x, y, w, h, r, aw): |
88 | - haw = aw/2 |
89 | + haw = aw / 2 |
90 | |
91 | cr.new_sub_path() |
92 | - cr.move_to(x-haw, (y+h)/2) |
93 | - cr.line_to(x+aw-haw, y) |
94 | - cr.arc(x+w-r, r+y, r, 270*PI_OVER_180, 0) |
95 | - cr.arc(x+w-r, y+h-r, r, 0, 90*PI_OVER_180) |
96 | - cr.line_to(x+aw-haw, y+h) |
97 | + cr.move_to(x - haw, (y + h) / 2) |
98 | + cr.line_to(x + aw - haw, y) |
99 | + cr.arc(x + w - r, r + y, r, 270 * PI_OVER_180, 0) |
100 | + cr.arc(x + w - r, y + h - r, r, 0, 90 * PI_OVER_180) |
101 | + cr.line_to(x + aw - haw, y + h) |
102 | cr.close_path() |
103 | - return |
104 | |
105 | |
106 | class ShapeMidArrow(Shape): |
107 | @@ -133,33 +126,30 @@ |
108 | #~ self.draw_xoffset = -2 |
109 | self._color = 0, 1, 0 |
110 | self.name = 'MidArrow' |
111 | - return |
112 | |
113 | def _layout_ltr(self, cr, x, y, w, h, r, aw): |
114 | - self.hadjustment = haw = aw/2 |
115 | - cr.move_to(x-haw-1, y) |
116 | + self.hadjustment = haw = aw / 2 |
117 | + cr.move_to(x - haw - 1, y) |
118 | # arrow head |
119 | - cr.line_to(x+w-haw, y) |
120 | - cr.line_to(x+w+haw, y+(h/2)) |
121 | - cr.line_to(x+w-haw, y+h) |
122 | - cr.line_to(x-haw-1, y+h) |
123 | + cr.line_to(x + w - haw, y) |
124 | + cr.line_to(x + w + haw, y + (h / 2)) |
125 | + cr.line_to(x + w - haw, y + h) |
126 | + cr.line_to(x - haw - 1, y + h) |
127 | |
128 | - cr.line_to(x+haw-1, y+(h/2)) |
129 | + cr.line_to(x + haw - 1, y + (h / 2)) |
130 | |
131 | cr.close_path() |
132 | - return |
133 | |
134 | def _layout_rtl(self, cr, x, y, w, h, r, aw): |
135 | - self.hadjustment = haw = -aw/2 |
136 | + self.hadjustment = haw = -aw / 2 |
137 | |
138 | - cr.move_to(x+haw, (h+y)/2) |
139 | - cr.line_to(x+aw+haw, y) |
140 | - cr.line_to(x+w-haw+1, y) |
141 | - cr.line_to(x+w-aw-haw+1, (y+h)/2) |
142 | - cr.line_to(x+w-haw+1, y+h) |
143 | - cr.line_to(x+aw+haw, y+h) |
144 | + cr.move_to(x + haw, (h + y) / 2) |
145 | + cr.line_to(x + aw + haw, y) |
146 | + cr.line_to(x + w - haw + 1, y) |
147 | + cr.line_to(x + w - aw - haw + 1, (y + h) / 2) |
148 | + cr.line_to(x + w - haw + 1, y + h) |
149 | + cr.line_to(x + aw + haw, y + h) |
150 | cr.close_path() |
151 | - return |
152 | |
153 | |
154 | class ShapeEndCap(Shape): |
155 | @@ -169,49 +159,42 @@ |
156 | #~ self.draw_xoffset = -2 |
157 | self._color = 0, 0, 1 |
158 | self.name = 'EndCap' |
159 | - return |
160 | |
161 | def _layout_ltr(self, cr, x, y, w, h, r, aw): |
162 | - self.hadjustment = haw = aw/2 |
163 | + self.hadjustment = haw = aw / 2 |
164 | |
165 | - cr.move_to(x-haw-1, y) |
166 | + cr.move_to(x - haw - 1, y) |
167 | # rounded end |
168 | - cr.arc(x+w-r, r+y, r, 270*PI_OVER_180, 0) |
169 | - cr.arc(x+w-r, y+h-r, r, 0, 90*PI_OVER_180) |
170 | + cr.arc(x + w - r, r + y, r, 270 * PI_OVER_180, 0) |
171 | + cr.arc(x + w - r, y + h - r, r, 0, 90 * PI_OVER_180) |
172 | # arrow |
173 | - cr.line_to(x-haw-1, y+h) |
174 | - cr.line_to(x+haw-1, y+(h/2)) |
175 | + cr.line_to(x - haw - 1, y + h) |
176 | + cr.line_to(x + haw - 1, y + (h / 2)) |
177 | cr.close_path() |
178 | - return |
179 | |
180 | def _layout_rtl(self, cr, x, y, w, h, r, aw): |
181 | - self.hadjustment = haw = -aw/2 |
182 | + self.hadjustment = haw = -aw / 2 |
183 | |
184 | - cr.arc(r+x, r+y, r, PI, 270*PI_OVER_180) |
185 | - cr.line_to(x+w-haw+1, y) |
186 | - cr.line_to(x+w-haw-aw+1, (y+h)/2) |
187 | - cr.line_to(x+w-haw+1, y+h) |
188 | - cr.arc(r+x, y+h-r, r, 90*PI_OVER_180, PI) |
189 | + cr.arc(r + x, r + y, r, PI, 270 * PI_OVER_180) |
190 | + cr.line_to(x + w - haw + 1, y) |
191 | + cr.line_to(x + w - haw - aw + 1, (y + h) / 2) |
192 | + cr.line_to(x + w - haw + 1, y + h) |
193 | + cr.arc(r + x, y + h - r, r, 90 * PI_OVER_180, PI) |
194 | cr.close_path() |
195 | - return |
196 | |
197 | |
198 | class AnimationClock(GObject.GObject): |
199 | - |
200 | _1SECOND = 1000 |
201 | - |
202 | - |
203 | __gsignals__ = { |
204 | - "animation-frame" : (GObject.SignalFlags.RUN_LAST, |
205 | + "animation-frame": (GObject.SignalFlags.RUN_LAST, |
206 | None, |
207 | (float,),), |
208 | |
209 | - "animation-finished" : (GObject.SignalFlags.RUN_FIRST, |
210 | + "animation-finished": (GObject.SignalFlags.RUN_FIRST, |
211 | None, |
212 | (bool,),), |
213 | } |
214 | |
215 | - |
216 | def __init__(self, fps, duration): |
217 | GObject.GObject.__init__(self) |
218 | |
219 | @@ -221,7 +204,6 @@ |
220 | |
221 | self._clock = None |
222 | self._progress = 0 # progress as an msec offset |
223 | - return |
224 | |
225 | def _get_timstep(self): |
226 | d = self.duration |
227 | @@ -245,7 +227,6 @@ |
228 | def set_duration(self, duration): |
229 | self.duration = float(duration) |
230 | self._timestep = self._get_timstep() |
231 | - return |
232 | |
233 | def stop(self, who_called='?'): |
234 | |
235 | @@ -257,29 +238,27 @@ |
236 | self._clock = None |
237 | self._progress = 0 |
238 | self.in_progress = False |
239 | - return |
240 | |
241 | def start(self): |
242 | self.stop(who_called='start') |
243 | - if not self.sequence: return |
244 | + if not self.sequence: |
245 | + return |
246 | |
247 | self._clock = GObject.timeout_add(self._timestep, |
248 | self._schedule_animation_frame, |
249 | priority=100) |
250 | self.in_progress = True |
251 | - return |
252 | |
253 | |
254 | class PathBarAnimator(AnimationClock): |
255 | - |
256 | # animation display constants |
257 | - FPS = 50 |
258 | + FPS = 50 |
259 | DURATION = 150 # spec says 150ms |
260 | |
261 | # animation modes |
262 | - NONE = 'animation-none' |
263 | - OUT = 'animation-out' |
264 | - IN = 'animation-in' |
265 | + NONE = 'animation-none' |
266 | + OUT = 'animation-out' |
267 | + IN = 'animation-in' |
268 | WIDTH_CHANGE = 'animation-width-change' |
269 | |
270 | def __init__(self, pathbar): |
271 | @@ -290,7 +269,6 @@ |
272 | |
273 | self.connect('animation-frame', self._on_animation_frame) |
274 | self.connect('animation-finished', self._on_animation_finished) |
275 | - return |
276 | |
277 | def _animate_out(self, part, progress, kwargs): |
278 | real_alloc = part.get_allocation() |
279 | @@ -300,13 +278,12 @@ |
280 | xo *= -1 |
281 | |
282 | anim_alloc = Gdk.Rectangle() |
283 | - anim_alloc.x = real_alloc.x-xo |
284 | + anim_alloc.x = real_alloc.x - xo |
285 | anim_alloc.y = real_alloc.y |
286 | anim_alloc.width = real_alloc.width |
287 | anim_alloc.height = real_alloc.height |
288 | |
289 | part.new_frame(anim_alloc) |
290 | - return |
291 | |
292 | def _animate_in(self, part, progress, kwargs): |
293 | real_alloc = part.get_allocation() |
294 | @@ -316,13 +293,12 @@ |
295 | xo *= -1 |
296 | |
297 | anim_alloc = Gdk.Rectangle() |
298 | - anim_alloc.x = real_alloc.x-xo |
299 | + anim_alloc.x = real_alloc.x - xo |
300 | anim_alloc.y = real_alloc.y |
301 | anim_alloc.width = real_alloc.width |
302 | anim_alloc.height = real_alloc.height |
303 | |
304 | part.new_frame(anim_alloc) |
305 | - return |
306 | |
307 | def _animate_width_change(self, part, progress, kwargs): |
308 | start_w = kwargs['start_width'] |
309 | @@ -330,14 +306,14 @@ |
310 | |
311 | width = int(round(start_w + (end_w - start_w) * progress)) |
312 | part.set_size_request(width, part.get_height_request()) |
313 | - return |
314 | |
315 | def _on_animation_frame(self, clock, progress): |
316 | - if not self.sequence: return |
317 | + if not self.sequence: |
318 | + return |
319 | |
320 | for actor, animation, kwargs in self.sequence: |
321 | - |
322 | - if animation == PathBarAnimator.NONE: continue |
323 | + if animation == PathBarAnimator.NONE: |
324 | + continue |
325 | |
326 | if animation == PathBarAnimator.OUT: |
327 | self._animate_out(actor, progress, kwargs) |
328 | @@ -348,8 +324,6 @@ |
329 | elif animation == PathBarAnimator.WIDTH_CHANGE: |
330 | self._animate_width_change(actor, progress, kwargs) |
331 | |
332 | - return |
333 | - |
334 | def _on_animation_finished(self, clock, interrupted): |
335 | for actor, animation, kwargs in self.sequence: |
336 | actor.animation_finished() |
337 | @@ -357,21 +331,18 @@ |
338 | self.sequence = [] |
339 | self.pathbar.psuedo_parts = [] |
340 | self.pathbar.queue_draw() |
341 | - return |
342 | |
343 | def append_animation(self, actor, animation, **kwargs): |
344 | self.sequence.append((actor, animation, kwargs)) |
345 | - return |
346 | |
347 | def reset(self, who_called='?'): |
348 | - AnimationClock.stop(self, who_called=who_called+'.reset') |
349 | + AnimationClock.stop(self, who_called=who_called + '.reset') |
350 | self.sequence = [] |
351 | - return |
352 | |
353 | |
354 | class PathBar(Gtk.HBox): |
355 | |
356 | - MIN_PART_WIDTH = 25 # pixels |
357 | + MIN_PART_WIDTH = 25 # pixels |
358 | |
359 | def __init__(self): |
360 | GObject.GObject.__init__(self) |
361 | @@ -405,7 +376,6 @@ |
362 | # les signales! |
363 | self.connect('size-allocate', self._on_allocate) |
364 | self.connect('draw', self._on_draw) |
365 | - return |
366 | |
367 | # sugar |
368 | def __len__(self): |
369 | @@ -454,7 +424,6 @@ |
370 | self.animator.start() |
371 | else: |
372 | self.queue_draw() |
373 | - return |
374 | |
375 | def _on_draw(self, widget, cr): |
376 | # always paint psuedo parts first |
377 | @@ -467,7 +436,7 @@ |
378 | |
379 | # paint a frame around the entire pathbar |
380 | width = self.get_parts_width() |
381 | - Gtk.render_background(context, cr, 1, 1, width-2, a.height-2) |
382 | + Gtk.render_background(context, cr, 1, 1, width - 2, a.height - 2) |
383 | |
384 | self._paint_widget_parts(cr, context, a.x, a.y) |
385 | |
386 | @@ -486,7 +455,6 @@ |
387 | part.animation_allocation or part.get_allocation(), |
388 | context, |
389 | xo, yo) |
390 | - return |
391 | |
392 | def _paint_psuedo_parts(self, cr, context, xo, yo): |
393 | # a special case: paint psuedo parts paint first, |
394 | @@ -496,7 +464,6 @@ |
395 | part.animation_allocation or part.get_allocation(), |
396 | context, |
397 | xo, yo) |
398 | - return |
399 | |
400 | def _shrink_parts(self, overhang): |
401 | self.out_of_width = True |
402 | @@ -505,7 +472,7 @@ |
403 | old_width = part.get_width_request() |
404 | new_width = max(self.MIN_PART_WIDTH, old_width - overhang) |
405 | |
406 | - if False:#self.use_animations: |
407 | + if False: # self.use_animations: |
408 | self.animator.append_animation(part, |
409 | PathBarAnimator.WIDTH_CHANGE, |
410 | start_width=old_width, |
411 | @@ -515,8 +482,8 @@ |
412 | part.get_height_request()) |
413 | |
414 | overhang -= old_width - new_width |
415 | - if overhang <= 0: break |
416 | - return |
417 | + if overhang <= 0: |
418 | + break |
419 | |
420 | def _grow_parts(self, claim): |
421 | children = self.get_children() |
422 | @@ -528,7 +495,8 @@ |
423 | continue |
424 | |
425 | growth = min(claim, (part.get_natural_width() - part.width)) |
426 | - if growth <= 0: break |
427 | + if growth <= 0: |
428 | + break |
429 | |
430 | claim -= growth |
431 | |
432 | @@ -540,11 +508,11 @@ |
433 | else: |
434 | part.set_size_request(part.width + growth, |
435 | part.get_height_request()) |
436 | - return |
437 | |
438 | def _make_space(self, part): |
439 | children = self.get_children() |
440 | - if not children: return |
441 | + if not children: |
442 | + return |
443 | |
444 | cur_width = self.get_parts_width() |
445 | incomming_width = cur_width + part.get_width_request() |
446 | @@ -553,14 +521,13 @@ |
447 | if overhang > 0: |
448 | print 'shrink parts by:', overhang |
449 | self._shrink_parts(overhang) |
450 | - return |
451 | |
452 | def _reclaim_space(self, part): |
453 | - if not self.out_of_width: return |
454 | + if not self.out_of_width: |
455 | + return |
456 | |
457 | claim = part.get_width_request() |
458 | self._grow_parts(claim) |
459 | - return |
460 | |
461 | def _append_compose_parts(self, new_part): |
462 | d = self.get_direction() |
463 | @@ -574,11 +541,11 @@ |
464 | else: |
465 | new_part.set_shape(ShapeRoundedRect(d)) |
466 | |
467 | - if not n_parts > 1: return |
468 | + if not n_parts > 1: |
469 | + return |
470 | |
471 | new_mid = children[-1] |
472 | new_mid.set_shape(ShapeMidArrow(d)) |
473 | - return |
474 | |
475 | def _remove_compose_parts(self): |
476 | d = self.get_direction() |
477 | @@ -595,31 +562,29 @@ |
478 | last = children[-1] |
479 | last.set_shape(ShapeEndCap(d)) |
480 | self.queue_draw() |
481 | - return |
482 | |
483 | def _cleanup_revealer(self): |
484 | - if not self._revealer: return |
485 | + if not self._revealer: |
486 | + return |
487 | GObject.source_remove(self._revealer) |
488 | self._revealer = None |
489 | - return |
490 | |
491 | def _theme(self, part): |
492 | #~ part.set_padding(self.theme['xpad'], self.theme['ypad']) |
493 | part.set_padding(12, 4) |
494 | - return |
495 | |
496 | # public methods |
497 | @property |
498 | def first_part(self): |
499 | children = self.get_children() |
500 | - if not children: return None |
501 | - return children[0] |
502 | + if children: |
503 | + return children[0] |
504 | |
505 | @property |
506 | def last_part(self): |
507 | children = self.get_children() |
508 | - if not children: return None |
509 | - return children[-1] |
510 | + if children: |
511 | + return children[-1] |
512 | |
513 | def reveal_part(self, part, animate=True): |
514 | # do not do here: |
515 | @@ -629,7 +594,8 @@ |
516 | part_old_width = part.get_width_request() |
517 | part_new_width = part.get_natural_width() |
518 | |
519 | - if part_new_width == part_old_width: return |
520 | + if part_new_width == part_old_width: |
521 | + return |
522 | |
523 | change_amount = part_new_width - part_old_width |
524 | |
525 | @@ -639,7 +605,8 @@ |
526 | old_width = part_old_width |
527 | new_width = part_new_width |
528 | else: |
529 | - if change_amount <= 0: continue |
530 | + if change_amount <= 0: |
531 | + continue |
532 | |
533 | old_width = p.get_width_request() |
534 | new_width = max(self.MIN_PART_WIDTH, old_width - change_amount) |
535 | @@ -655,7 +622,6 @@ |
536 | p.get_height_request()) |
537 | |
538 | self.animator.start() |
539 | - return |
540 | |
541 | def queue_reveal_part(self, part): |
542 | |
543 | @@ -667,11 +633,11 @@ |
544 | self._revealer = GObject.timeout_add(self._timeout_reveal, |
545 | reveal_part_cb, |
546 | part) |
547 | - return |
548 | |
549 | def get_parts_width(self): |
550 | last = self.last_part |
551 | - if not last: return 0 |
552 | + if not last: |
553 | + return 0 |
554 | |
555 | if self.get_direction() != Gtk.TextDirection.RTL: |
556 | return last.x + last.width - self.first_part.x |
557 | @@ -682,7 +648,8 @@ |
558 | def get_visual_width(self): |
559 | last = self.last_part |
560 | first = self.first_part |
561 | - if not last: return 0 |
562 | + if not last: |
563 | + return 0 |
564 | |
565 | la = last.animation_allocation or last.get_allocation() |
566 | fa = first.animation_allocation or first.get_allocation() |
567 | @@ -691,13 +658,11 @@ |
568 | return la.x + la.width - fa.x |
569 | |
570 | return fa.x + fa.width - la.x |
571 | - |
572 | |
573 | def set_use_animations(self, use_animations): |
574 | self.use_animations = use_animations |
575 | if not use_animations and self.animator.in_progress: |
576 | self.animator.reset() |
577 | - return |
578 | |
579 | def append(self, part): |
580 | print 'append', part |
581 | @@ -721,11 +686,11 @@ |
582 | else: |
583 | part.set_nopaint(False) |
584 | part.queue_draw() |
585 | - return |
586 | |
587 | def pop(self): |
588 | children = self.get_children() |
589 | - if not children: return |
590 | + if not children: |
591 | + return |
592 | |
593 | self.animator.reset('pop') |
594 | |
595 | @@ -744,11 +709,11 @@ |
596 | |
597 | last.destroy() |
598 | |
599 | - if not self.use_animations: return |
600 | + if not self.use_animations: |
601 | + return |
602 | |
603 | self.animator.append_animation(part, PathBarAnimator.IN) |
604 | self.animator.start() |
605 | - return |
606 | |
607 | def navigate_up(self): |
608 | """ just another name for pop() """ |
609 | @@ -760,7 +725,6 @@ |
610 | def __init__(self): |
611 | self.animation_in_progress = False |
612 | self.animation_allocation = None |
613 | - return |
614 | |
615 | @property |
616 | def x(self): |
617 | @@ -786,41 +750,41 @@ |
618 | |
619 | self.animation_allocation = allocation |
620 | self.queue_draw() |
621 | - return |
622 | |
623 | def animation_finished(self): |
624 | self.animation_in_progress = False |
625 | self.animation_allocation = None |
626 | - if self.get_parent(): self.get_parent().queue_draw() |
627 | - return |
628 | + if self.get_parent(): |
629 | + self.get_parent().queue_draw() |
630 | |
631 | def paint(self, cr, a, context, xo, yo): |
632 | - if self.is_nopaint: return |
633 | + if self.is_nopaint: |
634 | + return |
635 | |
636 | cr.save() |
637 | |
638 | x, y = 0, 0 |
639 | w, h = a.width, a.height |
640 | - arrow_width = 12#theme['arrow-width'] |
641 | + arrow_width = 12 # theme['arrow-width'] |
642 | |
643 | if isinstance(self, PathPart): |
644 | _a = self.get_allocation() |
645 | self.shape.layout(cr, |
646 | - _a.x-xo+1, _a.y-yo, |
647 | + _a.x - xo + 1, _a.y - yo, |
648 | w, h, 3, arrow_width) |
649 | cr.clip() |
650 | else: |
651 | Gtk.render_background(context, cr, |
652 | - a.x-xo-10, a.y-yo, |
653 | - a.width+10, a.height) |
654 | + a.x - xo - 10, a.y - yo, |
655 | + a.width + 10, a.height) |
656 | |
657 | - cr.translate(a.x-xo, a.y-yo) |
658 | + cr.translate(a.x - xo, a.y - yo) |
659 | |
660 | if self.shape.name.find('Arrow') != -1: |
661 | # draw arrow head |
662 | - cr.move_to(w-arrow_width/2, 2) |
663 | - cr.line_to(w+5, h/2) |
664 | - cr.line_to(w-arrow_width/2, h-2) |
665 | + cr.move_to(w - arrow_width / 2, 2) |
666 | + cr.line_to(w + 5, h / 2) |
667 | + cr.line_to(w - arrow_width / 2, h - 2) |
668 | # fetch the line color and stroke |
669 | rgba = context.get_border_color(Gtk.StateFlags.NORMAL) |
670 | cr.set_source_rgb(rgba.red, rgba.green, rgba.blue) |
671 | @@ -831,13 +795,13 @@ |
672 | e = self.layout.get_pixel_extents()[1] |
673 | lw, lh = e.width, e.height |
674 | pw, ph = a.width, a.height |
675 | - |
676 | - x = min(self.xpadding, (pw-lw)/2) |
677 | - y = (ph-lh)/2 |
678 | + |
679 | + x = min(self.xpadding, (pw - lw) / 2) |
680 | + y = (ph - lh) / 2 |
681 | |
682 | # layout area |
683 | Gtk.render_layout(context, |
684 | - cr, |
685 | + cr, |
686 | int(x), |
687 | int(y), |
688 | self.layout) |
689 | @@ -845,11 +809,10 @@ |
690 | # paint the focus frame if need be |
691 | if isinstance(self, PathPart) and self.has_focus(): |
692 | # layout area |
693 | - x, w, h = x-2, lw+4, lh+1 |
694 | + x, w, h = x - 2, lw + 4, lh + 1 |
695 | Gtk.render_focus(context, cr, x, y, w, h) |
696 | |
697 | cr.restore() |
698 | - return |
699 | |
700 | |
701 | class PsuedoPathPart(PathPartCommon): |
702 | @@ -872,7 +835,6 @@ |
703 | self.layout = real_part.create_pango_layout(self.label) |
704 | |
705 | self.is_nopaint = False |
706 | - return |
707 | |
708 | def get_allocation(self): |
709 | return self.allocation |
710 | @@ -887,20 +849,19 @@ |
711 | return self.size_request[1] |
712 | |
713 | def animation_finished(self): |
714 | - return |
715 | + pass |
716 | |
717 | def queue_draw(self): |
718 | a = self.allocation |
719 | aw = 12 |
720 | - self.parent.queue_draw_area(a.x-aw/2, a.y, |
721 | - a.width+aw, a.height) |
722 | - return |
723 | + self.parent.queue_draw_area(a.x - aw / 2, a.y, |
724 | + a.width + aw, a.height) |
725 | |
726 | |
727 | class PathPart(Gtk.EventBox, PathPartCommon): |
728 | |
729 | __gsignals__ = { |
730 | - "clicked" : (GObject.SignalFlags.RUN_LAST, |
731 | + "clicked": (GObject.SignalFlags.RUN_LAST, |
732 | None, |
733 | (),), |
734 | } |
735 | @@ -924,7 +885,6 @@ |
736 | |
737 | self.set_label(label) |
738 | self._init_event_handling() |
739 | - return |
740 | |
741 | def __repr__(self): |
742 | return "PathPart: '%s'" % self.label |
743 | @@ -940,23 +900,22 @@ |
744 | else: |
745 | part.set_state(Gtk.StateFlags.PRELIGHT) |
746 | self.queue_draw() |
747 | - return |
748 | |
749 | def _on_leave_notify(self, part, event): |
750 | self.pathbar.queue_reveal_part(self.pathbar.last_part) |
751 | part.set_state(Gtk.StateFlags.NORMAL) |
752 | self.queue_draw() |
753 | - return |
754 | |
755 | def _on_button_press(self, part, event): |
756 | - if event.button != 1: return |
757 | + if event.button != 1: |
758 | + return |
759 | self.pathbar._press_origin = part |
760 | part.set_state(Gtk.StateFlags.ACTIVE) |
761 | self.queue_draw() |
762 | - return |
763 | |
764 | def _on_button_release(self, part, event): |
765 | - if event.button != 1: return |
766 | + if event.button != 1: |
767 | + return |
768 | |
769 | if self.pathbar._press_origin != part: |
770 | self.pathbar._press_origin = None |
771 | @@ -971,13 +930,11 @@ |
772 | self.emit, 'clicked') |
773 | |
774 | self.queue_draw() |
775 | - return |
776 | |
777 | def _on_key_press(self, part, event): |
778 | if event.keyval in (Gdk.KEY_space, Gdk.KEY_Return, Gdk.KEY_KP_Enter): |
779 | part.set_state(Gtk.StateFlags.ACTIVE) |
780 | self.queue_draw() |
781 | - return |
782 | |
783 | def _on_key_release(self, part, event): |
784 | if event.keyval in (Gdk.KEY_space, Gdk.KEY_Return, Gdk.KEY_KP_Enter): |
785 | @@ -985,24 +942,21 @@ |
786 | GObject.timeout_add(self.pathbar._timeout_initial, |
787 | self.emit, 'clicked') |
788 | self.queue_draw() |
789 | - return |
790 | |
791 | def _on_focus_in(self, part, event): |
792 | self.pathbar.reveal_part(self) |
793 | - return |
794 | |
795 | def _on_focus_out(self, part, event): |
796 | self.queue_draw() |
797 | - return |
798 | |
799 | # private methods |
800 | def _init_event_handling(self): |
801 | self.set_property("can-focus", True) |
802 | - self.set_events(Gdk.EventMask.BUTTON_PRESS_MASK| |
803 | - Gdk.EventMask.BUTTON_RELEASE_MASK| |
804 | - Gdk.EventMask.KEY_RELEASE_MASK| |
805 | - Gdk.EventMask.KEY_PRESS_MASK| |
806 | - Gdk.EventMask.ENTER_NOTIFY_MASK| |
807 | + self.set_events(Gdk.EventMask.BUTTON_PRESS_MASK | |
808 | + Gdk.EventMask.BUTTON_RELEASE_MASK | |
809 | + Gdk.EventMask.KEY_RELEASE_MASK | |
810 | + Gdk.EventMask.KEY_PRESS_MASK | |
811 | + Gdk.EventMask.ENTER_NOTIFY_MASK | |
812 | Gdk.EventMask.LEAVE_NOTIFY_MASK) |
813 | |
814 | self.connect("enter-notify-event", self._on_enter_notify) |
815 | @@ -1013,18 +967,16 @@ |
816 | self.connect("key-release-event", self._on_key_release) |
817 | self.connect("focus-in-event", self._on_focus_in) |
818 | self.connect("focus-out-event", self._on_focus_out) |
819 | - return |
820 | |
821 | def _calc_natural_size(self, who_called='?'): |
822 | ne = self.natural_extents |
823 | nw, nh = ne.width, ne.height |
824 | |
825 | - nw += self.shape.hadjustment + 2*self.xpadding |
826 | - nh += 2*self.ypadding |
827 | + nw += self.shape.hadjustment + 2 * self.xpadding |
828 | + nh += 2 * self.ypadding |
829 | |
830 | self.natural_size = nw, nh |
831 | self.set_size_request(nw, nh) |
832 | - return |
833 | |
834 | # public methods |
835 | @property |
836 | @@ -1035,26 +987,23 @@ |
837 | self.xpadding = xpadding |
838 | self.ypadding = ypadding |
839 | self._calc_natural_size() |
840 | - return |
841 | |
842 | def set_size_request(self, width, height): |
843 | - width = max(2*self.xpadding+1, width) |
844 | - height = max(2*self.ypadding+1, height) |
845 | - self.layout.set_width(Pango.SCALE * (width - 2*self.xpadding)) |
846 | + width = max(2 * self.xpadding + 1, width) |
847 | + height = max(2 * self.ypadding + 1, height) |
848 | + self.layout.set_width(Pango.SCALE * (width - 2 * self.xpadding)) |
849 | Gtk.Widget.set_size_request(self, width, height) |
850 | - return |
851 | |
852 | def set_nopaint(self, is_nopaint): |
853 | self.is_nopaint = is_nopaint |
854 | self.queue_draw() |
855 | - return |
856 | |
857 | def set_shape(self, shape): |
858 | - if shape == self.shape: return |
859 | + if shape == self.shape: |
860 | + return |
861 | self.shape = shape |
862 | self._calc_natural_size() |
863 | self.queue_draw() |
864 | - return |
865 | |
866 | def set_label(self, label): |
867 | self.label = label |
868 | @@ -1068,7 +1017,6 @@ |
869 | |
870 | self._calc_natural_size() |
871 | self.queue_draw() |
872 | - return |
873 | |
874 | def get_natural_size(self): |
875 | return self.natural_size |
876 | @@ -1092,9 +1040,8 @@ |
877 | aw = 12 |
878 | else: |
879 | aw = 0 |
880 | - self.queue_draw_area(a.x-aw/2, a.y, |
881 | - a.width+aw, a.height) |
882 | - return |
883 | + self.queue_draw_area(a.x - aw / 2, a.y, |
884 | + a.width + aw, a.height) |
885 | |
886 | |
887 | class NavigationBar(PathBar): |
888 | @@ -1103,11 +1050,9 @@ |
889 | PathBar.__init__(self) |
890 | self.id_to_part = {} |
891 | self._callback_id = None |
892 | - return |
893 | |
894 | def _on_part_clicked(self, part): |
895 | part.callback(self, part) |
896 | - return |
897 | |
898 | def add_with_id(self, label, callback, id, do_callback=True, animate=True): |
899 | """ |
900 | @@ -1149,13 +1094,12 @@ |
901 | self._callback_id = None |
902 | |
903 | # if i do not have call the callback in an idle, |
904 | - # all hell breaks loose |
905 | + # all hell breaks loose |
906 | self._callback_id = GObject.idle_add(callback, |
907 | self, # pathbar |
908 | part) |
909 | |
910 | self.append(part) |
911 | - return |
912 | |
913 | def remove_ids(self, *ids, **kwargs): |
914 | parts = self.get_parts() |
915 | @@ -1169,14 +1113,16 @@ |
916 | index = len(parts) |
917 | |
918 | for id, part in self.id_to_part.iteritems(): |
919 | - if id not in ids: continue |
920 | + if id not in ids: |
921 | + continue |
922 | if part not in parts: |
923 | cleanup_ids.append(id) |
924 | part.destroy() |
925 | else: |
926 | index = min(index, parts.index(part)) |
927 | |
928 | - if index == len(parts): return |
929 | + if index == len(parts): |
930 | + return |
931 | |
932 | # cleanup any stale id:part pairs in the id_to_part dict |
933 | for id in cleanup_ids: |
934 | @@ -1192,7 +1138,7 @@ |
935 | |
936 | # the index is used to remove all parts after the index but we |
937 | # keep one part around to animate its removal |
938 | - for part in parts[index+1:]: |
939 | + for part in parts[index + 1:]: |
940 | part.destroy() |
941 | |
942 | animate = True |
943 | @@ -1207,36 +1153,33 @@ |
944 | if 'do_callback' in kwargs and kwargs['do_callback']: |
945 | part = self[-1] |
946 | part.callback(self, part) |
947 | - return |
948 | |
949 | def remove_all(self, **kwargs): |
950 | - if len(self) <= 1: return |
951 | + if len(self) <= 1: |
952 | + return |
953 | ids = filter(lambda k: k != 'category', |
954 | self.id_to_part.keys()) |
955 | self.remove_ids(*ids, **kwargs) |
956 | - return |
957 | |
958 | def has_id(self, id): |
959 | - return self.id_to_part.has_key(id) |
960 | + return id in self.id_to_part |
961 | |
962 | def get_parts(self): |
963 | return self.get_children() |
964 | |
965 | def get_active(self): |
966 | parts = self.get_parts() |
967 | - if not parts: return None |
968 | - return parts[-1] |
969 | + if parts: |
970 | + return parts[-1] |
971 | |
972 | def get_button_from_id(self, id): |
973 | """ |
974 | return the button for the given id (or None) |
975 | """ |
976 | - if not id in self.id_to_part: |
977 | - return None |
978 | - return self.id_to_part[id] |
979 | + return self.id_to_part.get(id) |
980 | |
981 | def set_active_no_callback(self, part): |
982 | - return |
983 | + pass |
984 | |
985 | |
986 | class TestIt: |
987 | @@ -1247,11 +1190,9 @@ |
988 | t = entry.get_text() or 'no label %s' % len(pathbar) |
989 | part = PathPart(t) |
990 | pathbar.append(part) |
991 | - return |
992 | |
993 | def remove(button, entry, pathbar): |
994 | pathbar.pop() |
995 | - return |
996 | |
997 | win = Gtk.Window() |
998 | win.set_border_width(30) |
999 | @@ -1284,6 +1225,7 @@ |
1000 | self.win = win |
1001 | self.win.pb = pb |
1002 | |
1003 | + |
1004 | def get_test_pathbar_window(): |
1005 | t = TestIt() |
1006 | return t.win |
1007 | @@ -1291,4 +1233,3 @@ |
1008 | if __name__ == '__main__': |
1009 | win = get_test_pathbar_window() |
1010 | Gtk.main() |
1011 | - |
1012 | |
1013 | === modified file 'test/test_pep8.py' |
1014 | --- test/test_pep8.py 2012-03-07 20:08:53 +0000 |
1015 | +++ test/test_pep8.py 2012-03-08 14:18:22 +0000 |
1016 | @@ -8,12 +8,21 @@ |
1017 | |
1018 | # Only test these two packages for now: |
1019 | import softwarecenter.db.pkginfo_impl |
1020 | +import softwarecenter.ui.gtk3.widgets |
1021 | import softwarecenter.ui.qml |
1022 | |
1023 | class PackagePep8TestCase(unittest.TestCase): |
1024 | maxDiff = None |
1025 | - packages = [softwarecenter.ui.qml, softwarecenter.db.pkginfo_impl] |
1026 | - exclude = [] |
1027 | + packages = [softwarecenter.ui.qml, |
1028 | + softwarecenter.ui.gtk3.widgets, |
1029 | + softwarecenter.db.pkginfo_impl] |
1030 | + exclude = ['reviews.py', 'symbolic_icons.py', 'stars.py', 'spinner.py', |
1031 | + 'weblivedialog.py', 'viewport.py', 'videoplayer.py', 'sections.py', |
1032 | + 'thumbnail.py', 'separators.py', 'searchentry.py', 'searchaid.py', |
1033 | + 'recommendations.py', 'oneconfviews.py', 'menubutton.py', 'labels.py', |
1034 | + 'imagedialog.py', 'exhibits.py', 'description.py', 'containers.py', |
1035 | + 'cellrenderers.py', 'buttons.py', 'backforward.py', 'apptreeview.py', |
1036 | + 'animatedimage.py', 'actionbar.py'] |
1037 | |
1038 | def message(self, text): |
1039 | self.errors.append(text) |
looks good - much thanks for this! I think the removal of argument-less returns makes a lot of sense.