Merge lp:~elachuni/software-center/pep8-test-part8 into lp:software-center
- pep8-test-part8
- Merge into trunk
Proposed by
Anthony Lenton
Status: | Merged |
---|---|
Merged at revision: | 2846 |
Proposed branch: | lp:~elachuni/software-center/pep8-test-part8 |
Merge into: | lp:software-center |
Diff against target: |
1027 lines (+152/-161) 4 files modified
softwarecenter/ui/gtk3/widgets/actionbar.py (+20/-24) softwarecenter/ui/gtk3/widgets/apptreeview.py (+68/-56) softwarecenter/ui/gtk3/widgets/buttons.py (+63/-80) test/test_pep8.py (+1/-1) |
To merge this branch: | bzr merge lp:~elachuni/software-center/pep8-test-part8 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
software-store-developers | Pending | ||
Review via email: mp+97260@code.launchpad.net |
Commit message
Description of the change
All files in softwarecenter.
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 'softwarecenter/ui/gtk3/widgets/actionbar.py' |
2 | --- softwarecenter/ui/gtk3/widgets/actionbar.py 2011-09-22 23:05:08 +0000 |
3 | +++ softwarecenter/ui/gtk3/widgets/actionbar.py 2012-03-13 17:40:55 +0000 |
4 | @@ -22,24 +22,26 @@ |
5 | |
6 | LOG = logging.getLogger(__name__) |
7 | |
8 | + |
9 | class ActionBar(Gtk.HBox): |
10 | """ |
11 | This is a gtk box wrapped so that all child widgets, save one, align |
12 | to the right. The widget does not show by default when its parent |
13 | calls show_all(), but rather autoshows and autohides when buttons |
14 | - (or a left-aligned label) are added and removed. |
15 | + (or a left-aligned label) are added and removed. |
16 | |
17 | The widget is only intended to hold buttons and a label, for which |
18 | it has specific methods; general add and pack are not implemented. |
19 | |
20 | - See: https://wiki.ubuntu.com/SoftwareCenter#Main%20window |
21 | - https://wiki.ubuntu.com/SoftwareCenter#Custom%20package%20lists |
22 | - https://wiki.ubuntu.com/SoftwareCenter#software-list-view-disclosure |
23 | - https://wiki.ubuntu.com/SoftwareCenter#Learning_how_to_launch_an_application |
24 | + See: |
25 | +https://wiki.ubuntu.com/SoftwareCenter#Main%20window |
26 | +https://wiki.ubuntu.com/SoftwareCenter#Custom%20package%20lists |
27 | +https://wiki.ubuntu.com/SoftwareCenter#software-list-view-disclosure |
28 | +https://wiki.ubuntu.com/SoftwareCenter#Learning_how_to_launch_an_application |
29 | """ |
30 | - |
31 | + |
32 | PADDING = 4 |
33 | - |
34 | + |
35 | ANIMATE_START_DELAY = 50 |
36 | ANIMATE_STEP_INTERVAL = 10 |
37 | ANIMATE_STEP = 8 |
38 | @@ -52,7 +54,7 @@ |
39 | self._label.set_border_width(self.PADDING) |
40 | # So that all buttons children right align |
41 | self._btn_bin = Gtk.Alignment.new(1.0, 0.0, 1.0, 1.0) |
42 | - self._btn_bin.set_padding(0,0,0,10) |
43 | + self._btn_bin.set_padding(0, 0, 0, 10) |
44 | self._btn_bin.add(self._btns) |
45 | # Buttons go on the right, labels on the left (in LTR mode) |
46 | super(ActionBar, self).pack_start(self._label, False, False, 10) |
47 | @@ -63,7 +65,7 @@ |
48 | self._label.show_all() |
49 | self._btn_bin.show_all() |
50 | self._visible = False |
51 | - |
52 | + |
53 | # listen for size allocation events, used for implementing the |
54 | # action bar slide in/out animation effect |
55 | self.connect('size-allocate', self._on_size_allocate) |
56 | @@ -100,8 +102,9 @@ |
57 | children = self._btns.get_children() |
58 | for child in children: |
59 | if child.id == id: |
60 | - # lock the height of the action bar when removing buttons to prevent |
61 | - # an unsightly resize if a label remains but all buttons are removed |
62 | + # lock the height of the action bar when removing buttons to |
63 | + # prevent an unsightly resize if a label remains but all |
64 | + # buttons are removed |
65 | self.set_size_request(-1, self.get_allocation().height) |
66 | self._btns.remove(child) |
67 | if len(children) == 1 and not len(self._label): |
68 | @@ -234,7 +237,7 @@ |
69 | self._slide_in() |
70 | else: |
71 | super(ActionBar, self).show() |
72 | - |
73 | + |
74 | def _hide(self, animate): |
75 | if not self._visible or self._is_sliding_out: |
76 | return |
77 | @@ -244,8 +247,7 @@ |
78 | self.set_size_request(-1, -1) |
79 | self._visible = False |
80 | super(ActionBar, self).hide() |
81 | - return |
82 | - |
83 | + |
84 | def _slide_in(self): |
85 | self._is_sliding_in = True |
86 | self._target_height = self.get_size_request()[1] |
87 | @@ -254,7 +256,6 @@ |
88 | super(ActionBar, self).show() |
89 | GObject.timeout_add(self.ANIMATE_START_DELAY, |
90 | self._slide_in_cb) |
91 | - return |
92 | |
93 | def _slide_out(self): |
94 | self._is_sliding_out = True |
95 | @@ -262,8 +263,7 @@ |
96 | self._current_height = self.get_size_request()[1] |
97 | GObject.timeout_add(self.ANIMATE_START_DELAY, |
98 | self._slide_out_cb) |
99 | - return |
100 | - |
101 | + |
102 | def _slide_in_cb(self): |
103 | if (self._is_sliding_in and |
104 | self._current_height < self._target_height): |
105 | @@ -273,8 +273,7 @@ |
106 | self.set_size_request(-1, new_height) |
107 | else: |
108 | self._is_sliding_in = False |
109 | - return |
110 | - |
111 | + |
112 | def _slide_out_cb(self): |
113 | if (self._is_sliding_out and |
114 | self._current_height > self._target_height): |
115 | @@ -287,8 +286,7 @@ |
116 | super(ActionBar, self).hide() |
117 | else: |
118 | self.set_size_request(-1, new_height) |
119 | - return |
120 | - |
121 | + |
122 | def _on_size_allocate(self, widget, allocation): |
123 | # FIXME: mvo: allocation.height is no longer accessable with gtk3 |
124 | # THIS SEEMS TO BREAK THE ANIMATION |
125 | @@ -306,7 +304,6 @@ |
126 | priority=100) |
127 | else: |
128 | self.queue_draw() |
129 | - return |
130 | |
131 | def _on_draw(self, widget, cr): |
132 | a = widget.get_allocation() |
133 | @@ -320,9 +317,8 @@ |
134 | cr.set_source_rgba(color.red, color.green, color.blue, 0.5) |
135 | cr.set_line_width(1) |
136 | cr.move_to(0.5, 0.5) |
137 | - cr.rel_line_to(a.width-1, 0) |
138 | + cr.rel_line_to(a.width - 1, 0) |
139 | cr.stroke() |
140 | - return |
141 | |
142 | def _callback(self, function, args): |
143 | # Disposes of the 'widget' argument that |
144 | |
145 | === modified file 'softwarecenter/ui/gtk3/widgets/apptreeview.py' |
146 | --- softwarecenter/ui/gtk3/widgets/apptreeview.py 2012-03-08 15:22:19 +0000 |
147 | +++ softwarecenter/ui/gtk3/widgets/apptreeview.py 2012-03-13 17:40:55 +0000 |
148 | @@ -43,7 +43,7 @@ |
149 | self._action_block_list = [] |
150 | self._needs_collapse = [] |
151 | self.expanded_path = None |
152 | - |
153 | + |
154 | # pixbuf for the icon that is displayed in the selected row |
155 | self.selected_row_icon = None |
156 | |
157 | @@ -54,7 +54,8 @@ |
158 | self.set_property("ubuntu-almost-fixed-height-mode", True) |
159 | self.set_fixed_height_mode(True) |
160 | except: |
161 | - self._logger.warn("ubuntu-almost-fixed-height-mode extension not available") |
162 | + self._logger.warn( |
163 | + "ubuntu-almost-fixed-height-mode extension not available") |
164 | |
165 | self.set_headers_visible(False) |
166 | |
167 | @@ -122,7 +123,7 @@ |
168 | if isinstance(model, Gtk.TreeModelFilter): |
169 | return model.get_model() |
170 | return model |
171 | - |
172 | + |
173 | def clear_model(self): |
174 | vadjustment = self.get_scrolled_window_vadjustment() |
175 | if vadjustment: |
176 | @@ -134,7 +135,7 @@ |
177 | |
178 | def expand_path(self, path): |
179 | if path is not None and not isinstance(path, Gtk.TreePath): |
180 | - raise TypeError, ("Expects Gtk.TreePath or None, got %s" % |
181 | + raise TypeError("Expects Gtk.TreePath or None, got %s" % |
182 | type(path)) |
183 | |
184 | model = self.get_model() |
185 | @@ -154,34 +155,35 @@ |
186 | "path is an invalid tree path: '%s'" % old) |
187 | logging.debug(msg) |
188 | |
189 | - if path == None: return |
190 | + if path == None: |
191 | + return |
192 | |
193 | model.row_changed(path, model.get_iter(path)) |
194 | - return |
195 | |
196 | def get_scrolled_window_vadjustment(self): |
197 | ancestor = self.get_ancestor(Gtk.ScrolledWindow) |
198 | if ancestor: |
199 | return ancestor.get_vadjustment() |
200 | - return None |
201 | |
202 | def get_rowref(self, model, path): |
203 | - if path == None: |
204 | - return None |
205 | - return model[path][AppGenericStore.COL_ROW_DATA] |
206 | + if path is not None: |
207 | + return model[path][AppGenericStore.COL_ROW_DATA] |
208 | |
209 | def rowref_is_category(self, rowref): |
210 | return isinstance(rowref, CategoryRowReference) |
211 | |
212 | def _on_realize(self, widget, tr): |
213 | - # connect to backend events once self is realized so handlers |
214 | + # connect to backend events once self is realized so handlers |
215 | # have access to the TreeView's initialised Gdk.Window |
216 | - if self._transactions_connected: return |
217 | - self.backend.connect("transaction-started", self._on_transaction_started, tr) |
218 | - self.backend.connect("transaction-finished", self._on_transaction_finished, tr) |
219 | - self.backend.connect("transaction-stopped", self._on_transaction_stopped, tr) |
220 | + if self._transactions_connected: |
221 | + return |
222 | + self.backend.connect("transaction-started", |
223 | + self._on_transaction_started, tr) |
224 | + self.backend.connect("transaction-finished", |
225 | + self._on_transaction_finished, tr) |
226 | + self.backend.connect("transaction-stopped", |
227 | + self._on_transaction_stopped, tr) |
228 | self._transactions_connected = True |
229 | - return |
230 | |
231 | def _calc_row_heights(self, tr): |
232 | ypad = StockEms.SMALL |
233 | @@ -194,13 +196,11 @@ |
234 | |
235 | btn_h = btn.height |
236 | |
237 | - tr.normal_height = max(32 + 2*ypad, em(2.5) + ypad) |
238 | + tr.normal_height = max(32 + 2 * ypad, em(2.5) + ypad) |
239 | tr.selected_height = tr.normal_height + btn_h + StockEms.MEDIUM |
240 | - return |
241 | |
242 | def _on_style_updated(self, widget, tr): |
243 | self._calc_row_heights(tr) |
244 | - return |
245 | |
246 | def _on_motion(self, tree, event, tr): |
247 | window = self.get_window() |
248 | @@ -215,7 +215,8 @@ |
249 | return |
250 | |
251 | rowref = self.get_rowref(tree.get_model(), path[0]) |
252 | - if not rowref: return |
253 | + if not rowref: |
254 | + return |
255 | |
256 | if self.rowref_is_category(rowref): |
257 | window.set_cursor(None) |
258 | @@ -248,7 +249,6 @@ |
259 | window.set_cursor(self._cursor_hand) |
260 | else: |
261 | window.set_cursor(None) |
262 | - return |
263 | |
264 | def _on_cursor_changed(self, view, tr): |
265 | model = view.get_model() |
266 | @@ -256,9 +256,11 @@ |
267 | path = view.get_cursor()[0] |
268 | |
269 | rowref = self.get_rowref(model, path) |
270 | - if not rowref: return |
271 | + if not rowref: |
272 | + return |
273 | |
274 | - if self.has_focus(): self.grab_focus() |
275 | + if self.has_focus(): |
276 | + self.grab_focus() |
277 | |
278 | if self.rowref_is_category(rowref): |
279 | self.expand_path(None) |
280 | @@ -266,7 +268,6 @@ |
281 | |
282 | sel.select_path(path) |
283 | self._update_selected_row(view, tr, path) |
284 | - return |
285 | |
286 | def _update_selected_row(self, view, tr, path=None): |
287 | # keep track of the currently selected row renderer for use when |
288 | @@ -278,7 +279,7 @@ |
289 | if not sel: |
290 | return False |
291 | model, rows = sel.get_selected_rows() |
292 | - if not rows: |
293 | + if not rows: |
294 | return False |
295 | row = rows[0] |
296 | if self.rowref_is_category(row): |
297 | @@ -343,53 +344,60 @@ |
298 | |
299 | x, y = self.get_pointer() |
300 | for btn in tr.get_buttons(): |
301 | - if btn.point_in(x, y): |
302 | + if btn.point_in(x, y): |
303 | return |
304 | |
305 | app = self.appmodel.get_application(rowref) |
306 | if app: |
307 | self.app_view.emit("application-activated", app) |
308 | - return |
309 | |
310 | def _on_button_event_get_path(self, view, event): |
311 | - if event.button != 1: return False |
312 | + if event.button != 1: |
313 | + return False |
314 | |
315 | res = view.get_path_at_pos(int(event.x), int(event.y)) |
316 | - if not res: return False |
317 | + if not res: |
318 | + return False |
319 | |
320 | # check the path is valid and is not a category row |
321 | path = res[0] |
322 | - is_cat = self.rowref_is_category(self.get_rowref(view.get_model(), path)) |
323 | - if path is None or is_cat: return False |
324 | + is_cat = self.rowref_is_category(self.get_rowref(view.get_model(), |
325 | + path)) |
326 | + if path is None or is_cat: |
327 | + return False |
328 | |
329 | # only act when the selection is already there |
330 | selection = view.get_selection() |
331 | - if not selection.path_is_selected(path): return False |
332 | + if not selection.path_is_selected(path): |
333 | + return False |
334 | |
335 | return path |
336 | |
337 | def _on_button_press_event(self, view, event, tr): |
338 | - if not self._on_button_event_get_path(view, event): return |
339 | + if not self._on_button_event_get_path(view, event): |
340 | + return |
341 | |
342 | self.pressed = True |
343 | x, y = int(event.x), int(event.y) |
344 | for btn in tr.get_buttons(): |
345 | - if btn.point_in(x, y) and (btn.state != Gtk.StateFlags.INSENSITIVE): |
346 | + if (btn.point_in(x, y) and |
347 | + (btn.state != Gtk.StateFlags.INSENSITIVE)): |
348 | self.focal_btn = btn |
349 | btn.set_state(Gtk.StateFlags.ACTIVE) |
350 | view.queue_draw() |
351 | return |
352 | self.focal_btn = None |
353 | - return |
354 | |
355 | def _on_button_release_event(self, view, event, tr): |
356 | path = self._on_button_event_get_path(view, event) |
357 | - if not path: return |
358 | + if not path: |
359 | + return |
360 | |
361 | self.pressed = False |
362 | x, y = int(event.x), int(event.y) |
363 | for btn in tr.get_buttons(): |
364 | - if btn.point_in(x, y) and (btn.state != Gtk.StateFlags.INSENSITIVE): |
365 | + if (btn.point_in(x, y) and |
366 | + (btn.state != Gtk.StateFlags.INSENSITIVE)): |
367 | btn.set_state(Gtk.StateFlags.NORMAL) |
368 | self.get_window().set_cursor(self._cursor_hand) |
369 | if self.focal_btn is not btn: |
370 | @@ -398,22 +406,23 @@ |
371 | view.queue_draw() |
372 | break |
373 | self.focal_btn = None |
374 | - return |
375 | |
376 | def _on_key_press_event(self, widget, event, tr): |
377 | kv = event.keyval |
378 | #print kv |
379 | r = False |
380 | - if kv == Gdk.KEY_Right: # right-key |
381 | + if kv == Gdk.KEY_Right: # right-key |
382 | btn = tr.get_button_by_name(CellButtonIDs.ACTION) |
383 | - if btn is None: return # Bug #846779 |
384 | + if btn is None: |
385 | + return # Bug #846779 |
386 | if btn.state != Gtk.StateFlags.INSENSITIVE: |
387 | btn.has_focus = True |
388 | btn = tr.get_button_by_name(CellButtonIDs.INFO) |
389 | btn.has_focus = False |
390 | - elif kv == Gdk.KEY_Left: # left-key |
391 | + elif kv == Gdk.KEY_Left: # left-key |
392 | btn = tr.get_button_by_name(CellButtonIDs.ACTION) |
393 | - if btn is None: return # Bug #846779 |
394 | + if btn is None: |
395 | + return # Bug #846779 |
396 | btn.has_focus = False |
397 | btn = tr.get_button_by_name(CellButtonIDs.INFO) |
398 | btn.has_focus = True |
399 | @@ -462,7 +471,6 @@ |
400 | app, |
401 | model, |
402 | path) |
403 | - return |
404 | |
405 | def _cell_data_func_cb(self, col, cell, model, it, user_data): |
406 | |
407 | @@ -488,12 +496,11 @@ |
408 | return |
409 | |
410 | cell.set_property('isactive', path == self.expanded_path) |
411 | - return |
412 | |
413 | def _app_activated_cb(self, btn, btn_id, app, store, path): |
414 | - if self.rowref_is_category(app): |
415 | + if self.rowref_is_category(app): |
416 | return |
417 | - |
418 | + |
419 | # FIXME: would be nice if that would be more elegant |
420 | # because we use a treefilter we need to get the "real" |
421 | # model first |
422 | @@ -526,7 +533,7 @@ |
423 | action = AppActions.INSTALL |
424 | |
425 | store.notify_action_request(app, path) |
426 | - |
427 | + |
428 | app_manager.request_action( |
429 | self.appmodel.get_application(app), [], [], |
430 | action) |
431 | @@ -540,15 +547,20 @@ |
432 | if btn.point_in(x, y): |
433 | window.set_cursor(cursor) |
434 | |
435 | - def _on_transaction_started(self, backend, pkgname, appname, trans_id, trans_type, tr): |
436 | - """ callback when an application install/remove transaction has started """ |
437 | + def _on_transaction_started(self, backend, pkgname, appname, trans_id, |
438 | + trans_type, tr): |
439 | + """callback when an application install/remove transaction has |
440 | + started |
441 | + """ |
442 | action_btn = tr.get_button_by_name(CellButtonIDs.ACTION) |
443 | if action_btn: |
444 | action_btn.set_sensitive(False) |
445 | self._set_cursor(action_btn, None) |
446 | |
447 | def _on_transaction_finished(self, backend, result, tr): |
448 | - """ callback when an application install/remove transaction has finished """ |
449 | + """callback when an application install/remove transaction has |
450 | + finished |
451 | + """ |
452 | # need to send a cursor-changed so the row button is properly updated |
453 | self.emit("cursor-changed") |
454 | # remove pkg from the block list |
455 | @@ -560,13 +572,15 @@ |
456 | self._set_cursor(action_btn, self._cursor_hand) |
457 | |
458 | def _on_transaction_stopped(self, backend, result, tr): |
459 | - """ callback when an application install/remove transaction has stopped """ |
460 | + """callback when an application install/remove transaction has |
461 | + stopped |
462 | + """ |
463 | # remove pkg from the block list |
464 | self._check_remove_pkg_from_blocklist(result.pkgname) |
465 | |
466 | action_btn = tr.get_button_by_name(CellButtonIDs.ACTION) |
467 | if action_btn: |
468 | - # this should be a function that decides action button state label... |
469 | + # this should be a function that decides action button state label |
470 | if action_btn.current_variant == self.VARIANT_INSTALL: |
471 | action_btn.set_markup(self.VARIANT_REMOVE) |
472 | action_btn.set_sensitive(True) |
473 | @@ -576,7 +590,6 @@ |
474 | self._update_selected_row(self, tr) |
475 | # queue a draw just to be sure the view is looking right |
476 | self.queue_draw() |
477 | - return |
478 | |
479 | def _check_remove_pkg_from_blocklist(self, pkgname): |
480 | if pkgname in self._action_block_list: |
481 | @@ -591,7 +604,6 @@ |
482 | return self.get_path_at_pos(x, y)[0] == self.get_cursor()[0] |
483 | |
484 | |
485 | - |
486 | def get_test_window(): |
487 | import softwarecenter.log |
488 | softwarecenter.log.root.setLevel(level=logging.DEBUG) |
489 | @@ -623,7 +635,7 @@ |
490 | with ExecutionTime("query cat '%s'" % cat.name): |
491 | docs = db.get_docs_from_query(cat.query) |
492 | store.set_category_documents(cat, docs) |
493 | - |
494 | + |
495 | # ok, this is confusing - the AppView contains the AppTreeView that |
496 | # is a tree or list depending on the model |
497 | from softwarecenter.ui.gtk3.views.appview import AppView |
498 | @@ -640,7 +652,7 @@ |
499 | win.show_all() |
500 | |
501 | return win |
502 | - |
503 | + |
504 | |
505 | if __name__ == "__main__": |
506 | win = get_test_window() |
507 | |
508 | === modified file 'softwarecenter/ui/gtk3/widgets/buttons.py' |
509 | --- softwarecenter/ui/gtk3/widgets/buttons.py 2012-02-20 15:59:17 +0000 |
510 | +++ softwarecenter/ui/gtk3/widgets/buttons.py 2012-03-13 17:40:55 +0000 |
511 | @@ -46,7 +46,7 @@ |
512 | |
513 | class _Tile(object): |
514 | |
515 | - MIN_WIDTH = em(7) |
516 | + MIN_WIDTH = em(7) |
517 | |
518 | def __init__(self): |
519 | self.set_focus_on_click(False) |
520 | @@ -54,7 +54,6 @@ |
521 | self.box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) |
522 | self.box.set_size_request(self.MIN_WIDTH, -1) |
523 | self.add(self.box) |
524 | - return |
525 | |
526 | def build_default(self, label, icon, icon_size): |
527 | if icon is not None: |
528 | @@ -67,7 +66,6 @@ |
529 | |
530 | self.label = Gtk.Label.new(label) |
531 | self.box.pack_start(self.label, True, True, 0) |
532 | - return |
533 | |
534 | |
535 | class TileButton(Gtk.Button, _Tile): |
536 | @@ -75,7 +73,6 @@ |
537 | def __init__(self): |
538 | Gtk.Button.__init__(self) |
539 | _Tile.__init__(self) |
540 | - return |
541 | |
542 | |
543 | class TileToggleButton(Gtk.RadioButton, _Tile): |
544 | @@ -84,7 +81,6 @@ |
545 | Gtk.RadioButton.__init__(self) |
546 | self.set_mode(False) |
547 | _Tile.__init__(self) |
548 | - return |
549 | |
550 | |
551 | class LabelTile(TileButton): |
552 | @@ -101,7 +97,6 @@ |
553 | |
554 | self.connect("enter-notify-event", self.on_enter) |
555 | self.connect("leave-notify-event", self.on_leave) |
556 | - return |
557 | |
558 | def do_draw(self, cr): |
559 | cr.save() |
560 | @@ -111,22 +106,20 @@ |
561 | Gtk.render_focus(self.get_style_context(), |
562 | cr, |
563 | 3, 3, |
564 | - A.width-6, A.height-6) |
565 | + A.width - 6, A.height - 6) |
566 | |
567 | - for child in self: self.propagate_draw(child, cr) |
568 | + for child in self: |
569 | + self.propagate_draw(child, cr) |
570 | |
571 | cr.restore() |
572 | - return |
573 | |
574 | def on_enter(self, widget, event): |
575 | window = self.get_window() |
576 | window.set_cursor(_HAND) |
577 | - return |
578 | |
579 | def on_leave(self, widget, event): |
580 | window = self.get_window() |
581 | window.set_cursor(None) |
582 | - return |
583 | |
584 | |
585 | class CategoryTile(TileButton): |
586 | @@ -145,7 +138,6 @@ |
587 | |
588 | self.connect("enter-notify-event", self.on_enter) |
589 | self.connect("leave-notify-event", self.on_leave) |
590 | - return |
591 | |
592 | def do_draw(self, cr): |
593 | cr.save() |
594 | @@ -155,25 +147,25 @@ |
595 | Gtk.render_focus(self.get_style_context(), |
596 | cr, |
597 | 3, 3, |
598 | - A.width-6, A.height-6) |
599 | + A.width - 6, A.height - 6) |
600 | |
601 | - for child in self: self.propagate_draw(child, cr) |
602 | + for child in self: |
603 | + self.propagate_draw(child, cr) |
604 | |
605 | cr.restore() |
606 | - return |
607 | |
608 | def on_enter(self, widget, event): |
609 | window = self.get_window() |
610 | window.set_cursor(_HAND) |
611 | - return |
612 | |
613 | def on_leave(self, widget, event): |
614 | window = self.get_window() |
615 | window.set_cursor(None) |
616 | - return |
617 | |
618 | |
619 | _global_featured_tile_width = em(11) |
620 | + |
621 | + |
622 | class FeaturedTile(TileButton): |
623 | |
624 | INSTALLED_OVERLAY_SIZE = 22 |
625 | @@ -191,12 +183,13 @@ |
626 | self.is_installed = helper.is_installed(doc) |
627 | self._overlay = helper.icons.load_icon(Icons.INSTALLED_OVERLAY, |
628 | self.INSTALLED_OVERLAY_SIZE, |
629 | - 0) # flags |
630 | + 0) # flags |
631 | |
632 | self.box.set_orientation(Gtk.Orientation.HORIZONTAL) |
633 | self.box.set_spacing(StockEms.SMALL) |
634 | |
635 | - self.content_left = Gtk.Box.new(Gtk.Orientation.VERTICAL, StockEms.MEDIUM) |
636 | + self.content_left = Gtk.Box.new(Gtk.Orientation.VERTICAL, |
637 | + StockEms.MEDIUM) |
638 | self.content_right = Gtk.Box.new(Gtk.Orientation.VERTICAL, 1) |
639 | self.box.pack_start(self.content_left, False, False, 0) |
640 | self.box.pack_start(self.content_right, False, False, 0) |
641 | @@ -204,7 +197,8 @@ |
642 | _update_icon(self.image, icon, icon_size) |
643 | self.content_left.pack_start(self.image, False, False, 0) |
644 | |
645 | - self.title = Gtk.Label.new(self._MARKUP % GObject.markup_escape_text(label)) |
646 | + self.title = Gtk.Label.new(self._MARKUP % |
647 | + GObject.markup_escape_text(label)) |
648 | self.title.set_alignment(0.0, 0.5) |
649 | self.title.set_use_markup(True) |
650 | self.title.set_ellipsize(Pango.EllipsizeMode.END) |
651 | @@ -212,7 +206,8 @@ |
652 | |
653 | categories = helper.get_categories(doc) |
654 | if categories is not None: |
655 | - self.category = Gtk.Label.new('<span font_desc="%i">%s</span>' % (em(0.6), GObject.markup_escape_text(categories))) |
656 | + self.category = Gtk.Label.new('<span font_desc="%i">%s</span>' % |
657 | + (em(0.6), GObject.markup_escape_text(categories))) |
658 | self.category.set_use_markup(True) |
659 | self.category.set_alignment(0.0, 0.5) |
660 | self.category.set_ellipsize(Pango.EllipsizeMode.END) |
661 | @@ -223,10 +218,11 @@ |
662 | self.stars = Star(size=StarSize.SMALL) |
663 | self.stars.render_outline = True |
664 | self.stars.set_rating(stats.ratings_average) |
665 | - self.rating_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, StockEms.SMALL) |
666 | + self.rating_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, |
667 | + StockEms.SMALL) |
668 | self.rating_box.pack_start(self.stars, False, False, 0) |
669 | self.n_ratings = Gtk.Label.new( |
670 | - '<span font_desc="%i"> (%i)</span>' % ( |
671 | + '<span font_desc="%i"> (%i)</span>' % ( |
672 | em(0.45), stats.ratings_total)) |
673 | self.n_ratings.set_use_markup(True) |
674 | self.n_ratings.set_name("subtle-label") |
675 | @@ -237,8 +233,9 @@ |
676 | # is not visible in the ui |
677 | stats_a11y = _('%(stars)d stars - %(reviews)d reviews') % { |
678 | 'stars': stats.ratings_average, 'reviews': stats.ratings_total} |
679 | - |
680 | - #work out width tile needs to be to ensure ratings text is all visible |
681 | + |
682 | + # work out width tile needs to be to ensure ratings text is all |
683 | + # visible |
684 | req_width = (self.stars.size_request().width + |
685 | self.image.size_request().width + |
686 | self.n_ratings.size_request().width + |
687 | @@ -254,7 +251,7 @@ |
688 | if price == '0.00': |
689 | # TRANSLATORS: Free here means Gratis |
690 | price = _("Free") |
691 | - # TRANSLATORS: Free here means Gratis |
692 | + # TRANSLATORS: Free here means Gratis |
693 | if price != _("Free"): |
694 | price = 'US$ ' + price |
695 | self.price = Gtk.Label.new( |
696 | @@ -266,7 +263,8 @@ |
697 | |
698 | self.set_name("featured-tile") |
699 | |
700 | - a11y_name = '. '.join([t for t in [label, categories, stats_a11y, price] if t]) |
701 | + a11y_name = '. '.join([t |
702 | + for t in [label, categories, stats_a11y, price] if t]) |
703 | self.get_accessible().set_name(a11y_name) |
704 | |
705 | backend = get_install_backend() |
706 | @@ -278,12 +276,10 @@ |
707 | self.connect("leave-notify-event", self.on_leave) |
708 | self.connect("button-press-event", self.on_press) |
709 | self.connect("button-release-event", self.on_release) |
710 | - return |
711 | |
712 | def _on_needs_refresh(self, helper, pkgname, doc, icon_size): |
713 | icon = helper.get_icon_at_size(doc, icon_size, icon_size) |
714 | _update_icon(self.image, icon, icon_size) |
715 | - |
716 | |
717 | def do_get_preferred_width(self): |
718 | w = _global_featured_tile_width |
719 | @@ -299,9 +295,10 @@ |
720 | Gtk.render_focus(self.get_style_context(), |
721 | cr, |
722 | 3, 3, |
723 | - A.width-6, A.height-6) |
724 | + A.width - 6, A.height - 6) |
725 | |
726 | - for child in self: self.propagate_draw(child, cr) |
727 | + for child in self: |
728 | + self.propagate_draw(child, cr) |
729 | |
730 | if self.is_installed: |
731 | # paint installed tick overlay |
732 | @@ -315,18 +312,17 @@ |
733 | cr.paint() |
734 | |
735 | cr.restore() |
736 | - return |
737 | |
738 | def on_transaction_finished(self, backend, result, helper, doc): |
739 | trans_pkgname = str(result.pkgname) |
740 | pkgname = helper.get_pkgname(doc) |
741 | - if trans_pkgname != pkgname: return |
742 | + if trans_pkgname != pkgname: |
743 | + return |
744 | |
745 | # update installed state |
746 | helper.update_availability(doc) |
747 | self.is_installed = helper.is_installed(doc) |
748 | self.queue_draw() |
749 | - return |
750 | |
751 | def on_enter(self, widget, event): |
752 | window = self.get_window() |
753 | @@ -341,13 +337,12 @@ |
754 | |
755 | def on_press(self, widget, event): |
756 | self._pressed = True |
757 | - return |
758 | |
759 | def on_release(self, widget, event): |
760 | - if not self._pressed: return |
761 | + if not self._pressed: |
762 | + return |
763 | self.emit("clicked") |
764 | self._pressed = False |
765 | - return |
766 | |
767 | |
768 | class ChannelSelector(Gtk.Button): |
769 | @@ -368,7 +363,6 @@ |
770 | self.section_button = section_button |
771 | self.popup = None |
772 | self.connect("button-press-event", self.on_button_press) |
773 | - return |
774 | |
775 | def do_draw(self, cr): |
776 | cr.save() |
777 | @@ -381,7 +375,7 @@ |
778 | cr.set_line_width(1) |
779 | |
780 | a = self.get_allocation() |
781 | - lin = cairo.LinearGradient(0,0,0,a.height) |
782 | + lin = cairo.LinearGradient(0, 0, 0, a.height) |
783 | lin.add_color_stop_rgba(0.1, |
784 | color.red, |
785 | color.green, |
786 | @@ -409,24 +403,22 @@ |
787 | |
788 | cr.restore() |
789 | |
790 | - for child in self: self.propagate_draw(child, cr) |
791 | - return |
792 | + for child in self: |
793 | + self.propagate_draw(child, cr) |
794 | |
795 | def on_button_press(self, button, event): |
796 | if self.popup is None: |
797 | self.build_channel_selector() |
798 | self.show_channel_sel_popup(self, event) |
799 | - return |
800 | -#~ |
801 | +#~ |
802 | #~ def on_style_updated(self, widget): |
803 | #~ context = widget.get_style_context() |
804 | #~ context.save() |
805 | #~ context.add_class("menu") |
806 | #~ bgcolor = context.get_background_color(Gtk.StateFlags.NORMAL) |
807 | #~ context.restore() |
808 | -#~ |
809 | +#~ |
810 | #~ self._dark_color = darken(bgcolor, 0.5) |
811 | - #~ return |
812 | |
813 | def show_channel_sel_popup(self, widget, event): |
814 | |
815 | @@ -443,23 +435,20 @@ |
816 | window = self.section_button.get_window() |
817 | self.popup.popup(None, None, position_func, (window, a), |
818 | event.button, event.time) |
819 | - return |
820 | |
821 | def set_build_func(self, build_func): |
822 | self.build_func = build_func |
823 | - return |
824 | |
825 | def build_channel_selector(self): |
826 | self.popup = Gtk.Menu() |
827 | self.popup.set_name('toolbar-popup') # to set 'padding: 0;' |
828 | self.popup.get_style_context().add_class('primary-toolbar') |
829 | self.build_func(self.popup) |
830 | - return |
831 | |
832 | |
833 | class SectionSelector(TileToggleButton): |
834 | |
835 | - MIN_WIDTH = em(5) |
836 | + MIN_WIDTH = em(5) |
837 | _MARKUP = '<small>%s</small>' |
838 | |
839 | def __init__(self, label, icon, icon_size=Gtk.IconSize.DIALOG): |
840 | @@ -471,7 +460,7 @@ |
841 | |
842 | context = self.get_style_context() |
843 | context.add_class("section-sel-bg") |
844 | - |
845 | + |
846 | context = self.label.get_style_context() |
847 | context.add_class("section-sel") |
848 | |
849 | @@ -481,23 +470,20 @@ |
850 | |
851 | self.connect('size-allocate', self.on_size_allocate) |
852 | self.connect('style-updated', self.on_style_updated) |
853 | - return |
854 | |
855 | def on_size_allocate(self, *args): |
856 | alloc = self.get_allocation() |
857 | - |
858 | + |
859 | if (self._alloc is None or |
860 | self._alloc.width != alloc.width or |
861 | self._alloc.height != alloc.height): |
862 | self._alloc = alloc |
863 | # reset the bg cache |
864 | self._bg_cache = {} |
865 | - return |
866 | |
867 | def on_style_updated(self, *args): |
868 | # also reset the bg cache |
869 | self._bg_cache = {} |
870 | - return |
871 | |
872 | def _cache_bg_for_state(self, state): |
873 | a = self.get_allocation() |
874 | @@ -512,9 +498,9 @@ |
875 | context.set_state(state) |
876 | |
877 | Gtk.render_background(context, cr, |
878 | - -5, -5, a.width+10, a.height+10) |
879 | + -5, -5, a.width + 10, a.height + 10) |
880 | Gtk.render_frame(context, cr, |
881 | - -5, -5, a.width+10, a.height+10) |
882 | + -5, -5, a.width + 10, a.height + 10) |
883 | del cr |
884 | |
885 | # new surface which will be cached which |
886 | @@ -524,11 +510,11 @@ |
887 | |
888 | # gradient for masking |
889 | lin = cairo.LinearGradient(0, 0, 0, a.height) |
890 | - lin.add_color_stop_rgba(0.0, 1,1,1, 0.1) |
891 | - lin.add_color_stop_rgba(0.25, 1,1,1, 0.7) |
892 | - lin.add_color_stop_rgba(0.5, 1,1,1, 1.0) |
893 | - lin.add_color_stop_rgba(0.75, 1,1,1, 0.7) |
894 | - lin.add_color_stop_rgba(1.0, 1,1,1, 0.1) |
895 | + lin.add_color_stop_rgba(0.0, 1, 1, 1, 0.1) |
896 | + lin.add_color_stop_rgba(0.25, 1, 1, 1, 0.7) |
897 | + lin.add_color_stop_rgba(0.5, 1, 1, 1, 1.0) |
898 | + lin.add_color_stop_rgba(0.75, 1, 1, 1, 0.7) |
899 | + lin.add_color_stop_rgba(1.0, 1, 1, 1, 0.1) |
900 | |
901 | cr.set_source_surface(_surf, 0, 0) |
902 | cr.mask(lin) |
903 | @@ -536,7 +522,6 @@ |
904 | |
905 | # cache the resulting surf... |
906 | self._bg_cache[state] = surf |
907 | - return |
908 | |
909 | def do_draw(self, cr): |
910 | state = self.get_state_flags() |
911 | @@ -547,30 +532,29 @@ |
912 | cr.set_source_surface(self._bg_cache[state], 0, 0) |
913 | cr.paint() |
914 | |
915 | - for child in self: self.propagate_draw(child, cr) |
916 | - return |
917 | + for child in self: |
918 | + self.propagate_draw(child, cr) |
919 | |
920 | |
921 | class Link(Gtk.Label): |
922 | |
923 | __gsignals__ = { |
924 | - "clicked" : (GObject.SignalFlags.RUN_LAST, |
925 | - None, |
926 | - (),) |
927 | + "clicked": (GObject.SignalFlags.RUN_LAST, |
928 | + None, |
929 | + (),) |
930 | } |
931 | |
932 | def __init__(self, markup="", uri="none"): |
933 | Gtk.Label.__init__(self) |
934 | self._handler = 0 |
935 | self.set_markup(markup, uri) |
936 | - return |
937 | |
938 | def set_markup(self, markup="", uri="none"): |
939 | markup = '<a href="%s">%s</a>' % (uri, markup) |
940 | Gtk.Label.set_markup(self, markup) |
941 | if self._handler == 0: |
942 | - self._handler = self.connect("activate-link", self.on_activate_link) |
943 | - return |
944 | + self._handler = self.connect("activate-link", |
945 | + self.on_activate_link) |
946 | |
947 | # synonyms for set_markup |
948 | def set_label(self, label): |
949 | @@ -581,7 +565,6 @@ |
950 | |
951 | def on_activate_link(self, uri, data): |
952 | self.emit("clicked") |
953 | - return |
954 | |
955 | def disable(self): |
956 | self.set_sensitive(False) |
957 | @@ -591,6 +574,7 @@ |
958 | self.set_sensitive(True) |
959 | self.set_name("label") |
960 | |
961 | + |
962 | class MoreLink(Gtk.Button): |
963 | |
964 | _MARKUP = '<b>%s</b>' |
965 | @@ -605,7 +589,6 @@ |
966 | self._init_event_handling() |
967 | context = self.get_style_context() |
968 | context.add_class("more-link") |
969 | - return |
970 | |
971 | def _init_event_handling(self): |
972 | self.connect("enter-notify-event", self.on_enter) |
973 | @@ -619,21 +602,20 @@ |
974 | e = layout.get_pixel_extents()[1] |
975 | xo, yo = self.label.get_layout_offsets() |
976 | Gtk.render_focus(self.get_style_context(), cr, |
977 | - xo-a.x-3, yo-a.y-1, |
978 | - e.width+6, e.height+2) |
979 | + xo - a.x - 3, yo - a.y - 1, |
980 | + e.width + 6, e.height + 2) |
981 | |
982 | - for child in self: self.propagate_draw(child, cr) |
983 | - return |
984 | + for child in self: |
985 | + self.propagate_draw(child, cr) |
986 | |
987 | def on_enter(self, widget, event): |
988 | window = self.get_window() |
989 | window.set_cursor(_HAND) |
990 | - return |
991 | |
992 | def on_leave(self, widget, event): |
993 | window = self.get_window() |
994 | window.set_cursor(None) |
995 | - return |
996 | + |
997 | |
998 | def _build_channels_list(popup): |
999 | for i in range(3): |
1000 | @@ -643,11 +625,12 @@ |
1001 | box.pack_start(label, False, False, 0) |
1002 | item.add(box) |
1003 | item.show_all() |
1004 | - popup.attach(item, 0, 1, i, i+1) |
1005 | + popup.attach(item, 0, 1, i, i + 1) |
1006 | + |
1007 | |
1008 | def get_test_buttons_window(): |
1009 | win = Gtk.Window() |
1010 | - win.set_size_request(200,200) |
1011 | + win.set_size_request(200, 200) |
1012 | |
1013 | vb = Gtk.VBox(spacing=12) |
1014 | win.add(vb) |
1015 | |
1016 | === modified file 'test/test_pep8.py' |
1017 | --- test/test_pep8.py 2012-03-12 12:43:52 +0000 |
1018 | +++ test/test_pep8.py 2012-03-13 17:40:55 +0000 |
1019 | @@ -16,7 +16,7 @@ |
1020 | packages = [softwarecenter.ui.qml, |
1021 | softwarecenter.ui.gtk3.widgets, |
1022 | softwarecenter.db.pkginfo_impl] |
1023 | - exclude = ['buttons.py', 'apptreeview.py', 'actionbar.py'] |
1024 | + exclude = [] |
1025 | |
1026 | def message(self, text): |
1027 | self.errors.append(text) |