Merge lp:~robin-gloster/ubuntu-accomplishments-viewer/pep8 into lp:ubuntu-accomplishments-viewer
- pep8
- Merge into accomplishments-viewer
Status: | Merged |
---|---|
Merged at revision: | 223 |
Proposed branch: | lp:~robin-gloster/ubuntu-accomplishments-viewer/pep8 |
Merge into: | lp:ubuntu-accomplishments-viewer |
Diff against target: |
2812 lines (+637/-620) 16 files modified
Changelog (+3/-1) accomplishments_viewer/AboutAccomplishmentsViewerDialog.py (+18/-16) accomplishments_viewer/AccomplishmentsViewerWindow.py (+365/-354) accomplishments_viewer/EditExtrainfoDialog.py (+74/-79) accomplishments_viewer/PreferencesAccomplishmentsViewerDialog.py (+23/-26) accomplishments_viewer/__init__.py (+18/-15) accomplishments_viewer_lib/AboutDialog.py (+13/-13) accomplishments_viewer_lib/Builder.py (+20/-21) accomplishments_viewer_lib/PreferencesDialog.py (+13/-13) accomplishments_viewer_lib/Window.py (+20/-19) accomplishments_viewer_lib/__init__.py (+8/-9) accomplishments_viewer_lib/accomplishments_viewerconfig.py (+9/-10) accomplishments_viewer_lib/helpers.py (+18/-12) bin/accomplishments-viewer (+11/-11) tests/test_example.py (+13/-10) tests/test_lint.py (+11/-11) |
To merge this branch: | bzr merge lp:~robin-gloster/ubuntu-accomplishments-viewer/pep8 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Rafał Cieślak | Approve | ||
Matt Fischer | Approve | ||
Review via email: mp+136211@code.launchpad.net |
Commit message
Description of the change
Fixed most pep8 issues
Matt Fischer (mfisch) wrote : | # |
Matt Fischer (mfisch) wrote : | # |
Looks fine to me, but Cielak should also look, also what testing did you do?
Robin Gloster (robin-gloster) wrote : | # |
Visited all pages and changed everything in the viewer i could find and
think of.
From what I could tell it should work exactly as before except for the k ->
kid fix which should have killed the viewer before.
2012/11/26 Matt Fischer <email address hidden>
> Review: Approve
>
> Looks fine to me, but Cielak should also look, also what testing did you
> do?
> --
>
> https:/
> You are the owner of lp:~robin-gloster/ubuntu-accomplishments-viewer/pep8.
>
Rafał Cieślak (rafalcieslak256) wrote : | # |
I have carefully reviewed these changes, and they seem perfectly fine. I have also did a bunch of tests for the viewer, and as expected - nothing suspicious could be detected. Thanks Robin for these fixes!
- 221. By Rafał Cieślak
-
Merging in the branch that introduces use of GtkInfoBars for notifications
- 222. By Rafał Cieślak
-
Fixed #1084058.
Matt Fischer (mfisch) wrote : | # |
Rafal,
Are you going to merge this?
- 223. By Rafał Cieślak
-
Merged in Robin's PEP fixes
Rafał Cieślak (rafalcieslak256) wrote : | # |
Just merged it in.
Preview Diff
1 | === modified file 'Changelog' |
2 | --- Changelog 2012-11-22 10:45:38 +0000 |
3 | +++ Changelog 2012-11-26 16:03:25 +0000 |
4 | @@ -6,7 +6,7 @@ |
5 | Add items using the following format: |
6 | |
7 | [Name] |
8 | - * What you did |
9 | + * What you did |
10 | * If a bug (LP: #BUGNUMBER) |
11 | |
12 | For example: |
13 | @@ -30,4 +30,6 @@ |
14 | * Fix lintian issues |
15 | * Added a manpage (LP: #1069264) |
16 | |
17 | + [Robin Gloster] |
18 | + * Fixed most PEP8 issues |
19 | ------------------------------------------------------------------------- |
20 | |
21 | === modified file 'accomplishments_viewer/AboutAccomplishmentsViewerDialog.py' |
22 | --- accomplishments_viewer/AboutAccomplishmentsViewerDialog.py 2012-09-13 19:19:11 +0000 |
23 | +++ accomplishments_viewer/AboutAccomplishmentsViewerDialog.py 2012-11-26 16:03:25 +0000 |
24 | @@ -1,24 +1,25 @@ |
25 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
26 | ### BEGIN LICENSE |
27 | # Copyright (C) 2012 Jono Bacon <jono@ubuntu.com> |
28 | -# This program is free software: you can redistribute it and/or modify it |
29 | -# under the terms of the GNU General Public License version 3, as published |
30 | +# This program is free software: you can redistribute it and/or modify it |
31 | +# under the terms of the GNU General Public License version 3, as published |
32 | # by the Free Software Foundation. |
33 | -# |
34 | -# This program is distributed in the hope that it will be useful, but |
35 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
36 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
37 | +# |
38 | +# This program is distributed in the hope that it will be useful, but |
39 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
40 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
41 | # PURPOSE. See the GNU General Public License for more details. |
42 | -# |
43 | -# You should have received a copy of the GNU General Public License along |
44 | +# |
45 | +# You should have received a copy of the GNU General Public License along |
46 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
47 | ### END LICENSE |
48 | |
49 | -import gettext, locale |
50 | +import gettext |
51 | +import locale |
52 | from locale import gettext as _ |
53 | from accomplishments.util.paths import locale_dir |
54 | locale.bindtextdomain('accomplishments-viewer', locale_dir) |
55 | -gettext.bindtextdomain('accomplishments-viewer',locale_dir) |
56 | +gettext.bindtextdomain('accomplishments-viewer', locale_dir) |
57 | locale.textdomain('accomplishments-viewer') |
58 | |
59 | from accomplishments.daemon import dbusapi |
60 | @@ -28,11 +29,12 @@ |
61 | |
62 | from accomplishments_viewer_lib.AboutDialog import AboutDialog |
63 | |
64 | + |
65 | # See accomplishments_viewer_lib.AboutDialog.py for more details about how this class works. |
66 | class AboutAccomplishmentsViewerDialog(AboutDialog): |
67 | __gtype_name__ = "AboutAccomplishmentsViewerDialog" |
68 | - |
69 | - def finish_initializing(self, builder): # pylint: disable=E1002 |
70 | + |
71 | + def finish_initializing(self, builder): # pylint: disable=E1002 |
72 | """Set up the about dialog""" |
73 | super(AboutAccomplishmentsViewerDialog, self).finish_initializing(builder) |
74 | |
75 | @@ -41,17 +43,17 @@ |
76 | self.libaccom = dbusapi.Accomplishments() |
77 | |
78 | # add app authors |
79 | - authors = sorted([ "Jono Bacon <jono@ubuntu.com>", "Rafal Cieślak <rafalcieslak256@gmail.com>", "Matt Fischer <matt@mattfischer.com>", "Stuart Langridge <sil@kryogenix.org>"]) |
80 | - |
81 | + authors = sorted(["Jono Bacon <jono@ubuntu.com>", "Rafal Cieślak <rafalcieslak256@gmail.com>", "Matt Fischer <matt@mattfischer.com>", "Stuart Langridge <sil@kryogenix.org>"]) |
82 | + |
83 | for col in self.libaccom.list_collections(): |
84 | authors.append(" ") |
85 | authors.append("'" + self.libaccom.get_collection_name(col) + "' " + _("Collection Authors:")) |
86 | authors.append(" ") |
87 | - |
88 | + |
89 | tempauthors = [] |
90 | for a in self.libaccom.get_collection_authors(col): |
91 | tempauthors.append(a) |
92 | |
93 | authors = authors + sorted(tempauthors) |
94 | - |
95 | + |
96 | self.set_authors(authors) |
97 | |
98 | === modified file 'accomplishments_viewer/AccomplishmentsViewerWindow.py' |
99 | --- accomplishments_viewer/AccomplishmentsViewerWindow.py 2012-11-22 10:04:35 +0000 |
100 | +++ accomplishments_viewer/AccomplishmentsViewerWindow.py 2012-11-26 16:03:25 +0000 |
101 | @@ -1,25 +1,27 @@ |
102 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
103 | ### BEGIN LICENSE |
104 | # Copyright (C) 2012 Jono Bacon <jono@ubuntu.com> |
105 | -# This program is free software: you can redistribute it and/or modify it |
106 | -# under the terms of the GNU General Public License version 3, as published |
107 | +# This program is free software: you can redistribute it and/or modify it |
108 | +# under the terms of the GNU General Public License version 3, as published |
109 | # by the Free Software Foundation. |
110 | -# |
111 | -# This program is distributed in the hope that it will be useful, but |
112 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
113 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
114 | +# |
115 | +# This program is distributed in the hope that it will be useful, but |
116 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
117 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
118 | # PURPOSE. See the GNU General Public License for more details. |
119 | -# |
120 | -# You should have received a copy of the GNU General Public License along |
121 | +# |
122 | +# You should have received a copy of the GNU General Public License along |
123 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
124 | ### END LICENSE |
125 | |
126 | import urllib2 |
127 | -import gettext, locale, datetime |
128 | +import gettext |
129 | +import locale |
130 | +import datetime |
131 | from locale import gettext as _ |
132 | from accomplishments.util.paths import locale_dir |
133 | locale.bindtextdomain('accomplishments-viewer', locale_dir) |
134 | -gettext.bindtextdomain('accomplishments-viewer',locale_dir) |
135 | +gettext.bindtextdomain('accomplishments-viewer', locale_dir) |
136 | locale.textdomain('accomplishments-viewer') |
137 | |
138 | import traceback |
139 | @@ -32,7 +34,7 @@ |
140 | import dbus.service |
141 | from dbus.mainloop.glib import DBusGMainLoop |
142 | |
143 | -from gi.repository import Gtk, GObject, GdkPixbuf, WebKit # pylint: disable=E0611 |
144 | +from gi.repository import Gtk, GObject, GdkPixbuf, WebKit # pylint: disable=E0611 |
145 | from gi.repository import Unity |
146 | |
147 | import logging |
148 | @@ -96,23 +98,24 @@ |
149 | |
150 | TROPHY_GALLERY_URL = 'http://213.138.100.229:8000' |
151 | |
152 | + |
153 | # See accomplishments_viewer_lib.Window.py for more details about how this class works |
154 | class AccomplishmentsViewerWindow(Window): |
155 | __gtype_name__ = "AccomplishmentsViewerWindow" |
156 | - |
157 | - def finish_initializing(self, builder): # pylint: disable=E1002 |
158 | + |
159 | + def finish_initializing(self, builder): # pylint: disable=E1002 |
160 | """Set up the main window.""" |
161 | - |
162 | + |
163 | super(AccomplishmentsViewerWindow, self).finish_initializing(builder) |
164 | |
165 | self.AboutDialog = AboutAccomplishmentsViewerDialog |
166 | - self.PreferencesDialog = PreferencesAccomplishmentsViewerDialog #class |
167 | - self.preferences_dialog = None #instance |
168 | + self.PreferencesDialog = PreferencesAccomplishmentsViewerDialog # class |
169 | + self.preferences_dialog = None # instance |
170 | self.EditExtraDialog = EditExtrainfoDialog() |
171 | self.EditExtraDialog.parent = self |
172 | self.curr_height = 0 |
173 | self.curr_width = 0 |
174 | - |
175 | + |
176 | # Following variables store current display settings. |
177 | self.display_mytrophies_filtermode = MYTROPHIES_FILTER_ALL |
178 | self.display_mode = DISPLAY_MODE_OPPORTUNITIES |
179 | @@ -121,13 +124,12 @@ |
180 | self.display_filter_category = "" |
181 | self.display_filter_subcat = "" |
182 | self.display_filter_search = "" |
183 | - |
184 | + |
185 | # These two store list of pairs [filter, iconview] for all accomplishment groups in mytrophies view. |
186 | self.trophies_collection_filters = [] |
187 | self.mytrophies_latest_boxes = [] |
188 | # Code for other initialization actions should be added here. |
189 | |
190 | - |
191 | # set up autostart dir |
192 | self.autostartdir = None |
193 | |
194 | @@ -144,7 +146,7 @@ |
195 | # reference to the Unity Launchcher |
196 | self.launcher = Unity.LauncherEntry.get_for_desktop_id("accomplishments-viewer.desktop") |
197 | self.newtrophies = 0 |
198 | - |
199 | + |
200 | # set up all of the different UI references |
201 | self.tb_mytrophies = self.builder.get_object("tb_mytrophies") |
202 | self.tb_opportunities = self.builder.get_object("tb_opportunities") |
203 | @@ -192,38 +194,38 @@ |
204 | sb_v = self.subcats_scroll.get_vscrollbar() |
205 | sb_h.set_child_visible(False) |
206 | sb_v.set_child_visible(False) |
207 | - |
208 | + |
209 | #h = self.subcats_scroll.get_hadjustment() |
210 | self.subcat = None |
211 | self.subcats_container.hide() |
212 | - |
213 | + |
214 | # make the toolbar black in Ubuntu |
215 | context = self.toolbar.get_style_context() |
216 | context.add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR) |
217 | |
218 | # Create stores and corelated filters |
219 | |
220 | - self.oppstore = Gtk.ListStore(str, GdkPixbuf.Pixbuf, bool, bool, str, str, str, str, str) # title, icon, accomplished, locked, col, accomplishment, date-accomplished, categories, keywords |
221 | + self.oppstore = Gtk.ListStore(str, GdkPixbuf.Pixbuf, bool, bool, str, str, str, str, str) # title, icon, accomplished, locked, col, accomplishment, date-accomplished, categories, keywords |
222 | self.oppstore.set_sort_column_id(COL_TITLE, Gtk.SortType.ASCENDING) |
223 | self.oppstore_filtered = self.oppstore.filter_new() |
224 | # The following sets the function for tree model filter. That function has |
225 | # to return true if a given row has to be visible. This way we can control |
226 | # which opportunities are displayed, and which are not. |
227 | self.oppstore_filtered.set_visible_func(self._opp_visible_func) |
228 | - |
229 | - self.trophiesstore = Gtk.ListStore(str, GdkPixbuf.Pixbuf, bool, bool, str, str, str, str, str) # title, icon, accomplished, locked, col, accomplishment, date-accomplished, categories, keywords |
230 | + |
231 | + self.trophiesstore = Gtk.ListStore(str, GdkPixbuf.Pixbuf, bool, bool, str, str, str, str, str) # title, icon, accomplished, locked, col, accomplishment, date-accomplished, categories, keywords |
232 | self.trophiesstore.set_sort_column_id(COL_TITLE, Gtk.SortType.ASCENDING) |
233 | self.trophiesstore_filter_today = self.trophiesstore.filter_new() |
234 | - self.trophiesstore_filter_today.set_visible_func(self._trophy_recent_visible_func,TROPHIES_FILTER_TODAY) |
235 | + self.trophiesstore_filter_today.set_visible_func(self._trophy_recent_visible_func, TROPHIES_FILTER_TODAY) |
236 | self.trophiesstore_filter_week = self.trophiesstore.filter_new() |
237 | - self.trophiesstore_filter_week.set_visible_func(self._trophy_recent_visible_func,TROPHIES_FILTER_WEEK) |
238 | + self.trophiesstore_filter_week.set_visible_func(self._trophy_recent_visible_func, TROPHIES_FILTER_WEEK) |
239 | self.trophiesstore_filter_month = self.trophiesstore.filter_new() |
240 | - self.trophiesstore_filter_month.set_visible_func(self._trophy_recent_visible_func,TROPHIES_FILTER_MONTH) |
241 | + self.trophiesstore_filter_month.set_visible_func(self._trophy_recent_visible_func, TROPHIES_FILTER_MONTH) |
242 | self.trophiesstore_filter_sixmonths = self.trophiesstore.filter_new() |
243 | - self.trophiesstore_filter_sixmonths.set_visible_func(self._trophy_recent_visible_func,TROPHIES_FILTER_SIXMONTHS) |
244 | + self.trophiesstore_filter_sixmonths.set_visible_func(self._trophy_recent_visible_func, TROPHIES_FILTER_SIXMONTHS) |
245 | self.trophiesstore_filter_earlier = self.trophiesstore.filter_new() |
246 | - self.trophiesstore_filter_earlier.set_visible_func(self._trophy_recent_visible_func,TROPHIES_FILTER_EARLIER) |
247 | - |
248 | + self.trophiesstore_filter_earlier.set_visible_func(self._trophy_recent_visible_func, TROPHIES_FILTER_EARLIER) |
249 | + |
250 | self.opp_icon.set_model(self.oppstore_filtered) |
251 | self.opp_icon.set_text_column(COL_TITLE) |
252 | self.opp_icon.set_pixbuf_column(COL_PIXBUF) |
253 | @@ -232,13 +234,13 @@ |
254 | self.webview = WebKit.WebView() |
255 | self.scrolledwindow.add(self.webview) |
256 | self.webview.props.settings.props.enable_default_context_menu = False |
257 | - self.webkitlink = self.webview.connect("navigation-policy-decision-requested",self.webkit_link_clicked) |
258 | + self.webkitlink = self.webview.connect("navigation-policy-decision-requested", self.webkit_link_clicked) |
259 | |
260 | self.webview.show() |
261 | - |
262 | + |
263 | if GWIBBER_OK: |
264 | - self.messageentry = GwibberGtk.Entry() |
265 | - self.messageentry.text_view.connect("submit",self.close_gwibber_window) |
266 | + self.messageentry = GwibberGtk.Entry() |
267 | + self.messageentry.text_view.connect("submit", self.close_gwibber_window) |
268 | self.messagewindow = Gtk.Window() |
269 | self.messagewindow.set_transient_for(self) |
270 | self.messagevbox = Gtk.VBox() |
271 | @@ -246,15 +248,15 @@ |
272 | self.messagewindow.set_icon_name("gwibber") |
273 | self.messagewindow.resize(400, 150) |
274 | self.messagewindow.set_resizable(False) |
275 | - self.messagevbox.pack_start(self.messageentry,True,True,0) |
276 | + self.messagevbox.pack_start(self.messageentry, True, True, 0) |
277 | self.messagelabel = Gtk.Label() |
278 | self.messagelabel.set_markup(_("<b>Always add the link to your trophy on the web when sharing a trophy.</b>\nThis link works as a <b>proof</b> that you have really accomplished this trophy.")) |
279 | - self.messagevbox.pack_start(self.messagelabel,False,False,0) |
280 | + self.messagevbox.pack_start(self.messagelabel, False, False, 0) |
281 | self.messagewindow.add(self.messagevbox) |
282 | - self.messagevbox.show_all() |
283 | + self.messagevbox.show_all() |
284 | self.messagewindow.hide() |
285 | - self.messagewindow.connect("delete-event",self.close_gwibber_window) |
286 | - |
287 | + self.messagewindow.connect("delete-event", self.close_gwibber_window) |
288 | + |
289 | self.opp_col_store = Gtk.ListStore(str, str) |
290 | self.col_combo_renderer_text = Gtk.CellRendererText() |
291 | self.opp_combo_col.pack_start(self.col_combo_renderer_text, True) |
292 | @@ -291,26 +293,23 @@ |
293 | os.makedirs(os.path.join(self.dir_cache, "logs")) |
294 | |
295 | # IMPORTANT: This function should do no initialisations that depend |
296 | - # on having the daemon running. This is because if the daemon is not |
297 | - # yet started it will take some time to connect to it. Such |
298 | + # on having the daemon running. This is because if the daemon is not |
299 | + # yet started it will take some time to connect to it. Such |
300 | # initialistions should land in appropriate place in finalise_daemon_connection(...). |
301 | |
302 | self.datapath = get_data_path() |
303 | |
304 | self.update_widgets_sensitivity() |
305 | |
306 | - |
307 | - |
308 | def add_no_collections_installed(self): |
309 | """Display the message that no collections are installed.""" |
310 | - |
311 | + |
312 | ### Commented out the following as it is confusing, and opens a lot of |
313 | ### possible scenarios where these buttons are left insensitive. |
314 | ## set bits of the user interface to be insensitive |
315 | # self.tb_mytrophies.set_sensitive(False) |
316 | # self.opp_frame.set_visible(False) |
317 | - |
318 | - |
319 | + |
320 | # show the message |
321 | self.additional_no_collections.set_visible(True) |
322 | |
323 | @@ -322,28 +321,28 @@ |
324 | self.additional_no_collections.set_visible(False) |
325 | self.reload_accomplishments() |
326 | self.set_display(DISPLAY_MODE_OPPORTUNITIES) |
327 | - |
328 | + |
329 | def reload_accomplishments(self): |
330 | if not self.connected: |
331 | return |
332 | - |
333 | + |
334 | self.statusbar_reload_msg_start() |
335 | - Gtk.main_iteration_do(False) # Force UI refresh |
336 | + Gtk.main_iteration_do(False) # Force UI refresh |
337 | self.libaccom.reload_accom_database() |
338 | self.statusbar_reload_msg_stop() |
339 | - |
340 | + |
341 | self._load_accomplishments() |
342 | if len(self.accomdb) == 0: |
343 | self.add_no_collections_installed() |
344 | - |
345 | + |
346 | def statusbar_reload_msg_start(self): |
347 | self.statusbar.set_text(_("Reloading accomplishments collections...")) |
348 | self.spinner.start() |
349 | self.spinner.show() |
350 | self.statusbox.show() |
351 | self.statusbar_reload_msg = 0 |
352 | - GObject.timeout_add(1000,self.statusbar_reload_msg_stop) |
353 | - |
354 | + GObject.timeout_add(1000, self.statusbar_reload_msg_stop) |
355 | + |
356 | def statusbar_reload_msg_stop(self): |
357 | if self.statusbar_reload_msg is 0: |
358 | # That would be too quick and the user wouldn't even notice the message |
359 | @@ -351,23 +350,22 @@ |
360 | elif self.statusbar_reload_msg is 1: |
361 | self.spinner.hide() |
362 | self.statusbox.hide() |
363 | - |
364 | - |
365 | + |
366 | def trophy_received(self, message): |
367 | """Called when a new trophy is detected on the system.""" |
368 | - |
369 | + |
370 | self.newtrophies = self.newtrophies + 1 |
371 | - |
372 | + |
373 | # run this to refresh our accomplishments list |
374 | self._load_accomplishments() |
375 | - |
376 | + |
377 | #XXX: It would be MUCH faster if we determined the new accomID and added just it, not recreating whole trees! |
378 | self.prepare_models() |
379 | - |
380 | + |
381 | # set the Launcher icon to be urgent and show new trophy count |
382 | self.launcher.set_property("urgent", True) |
383 | self.launcher.set_property("count", self.newtrophies) |
384 | - |
385 | + |
386 | if self.newtrophies > 0: |
387 | self.launcher.set_property("count_visible", True) |
388 | else: |
389 | @@ -379,10 +377,10 @@ |
390 | def check_and_ask_for_info(self): |
391 | """Asks the daemon for additional info needed, and asks |
392 | the user for it, in case it has not been yet given""" |
393 | - |
394 | + |
395 | if self.connected is False: |
396 | return |
397 | - |
398 | + |
399 | self.has_u1 = self.libaccom.get_config_value("config", "has_u1") |
400 | self.has_verif = self.libaccom.get_config_value("config", "has_verif") |
401 | |
402 | @@ -397,90 +395,90 @@ |
403 | |
404 | def connect_to_daemon(self): |
405 | """Tries to connect to the daemon""" |
406 | - |
407 | + |
408 | self.connected = False |
409 | - |
410 | + |
411 | if dbusapi.daemon_is_registered(): |
412 | self.libaccom = dbusapi.Accomplishments() |
413 | else: |
414 | return False |
415 | - |
416 | + |
417 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
418 | |
419 | bus = dbus.SessionBus() |
420 | - |
421 | + |
422 | try: |
423 | - object = bus.get_object("org.ubuntu.accomplishments", |
424 | - "/org/ubuntu/accomplishments") |
425 | + object = bus.get_object("org.ubuntu.accomplishments", |
426 | + "/org/ubuntu/accomplishments") |
427 | object.connect_to_signal("trophy_recieved", |
428 | - self.trophy_received, |
429 | - dbus_interface="org.ubuntu.accomplishments", arg0="Hello") |
430 | + self.trophy_received, |
431 | + dbus_interface="org.ubuntu.accomplishments", arg0="Hello") |
432 | object.connect_to_signal("publish_trophies_online_completed", |
433 | - self.publish_trophies_online_completed, |
434 | - dbus_interface="org.ubuntu.accomplishments", arg0="Hello") |
435 | + self.publish_trophies_online_completed, |
436 | + dbus_interface="org.ubuntu.accomplishments", arg0="Hello") |
437 | object.connect_to_signal("scriptrunner_start", |
438 | - self.scriptrunner_start, |
439 | - dbus_interface="org.ubuntu.accomplishments") |
440 | + self.scriptrunner_start, |
441 | + dbus_interface="org.ubuntu.accomplishments") |
442 | object.connect_to_signal("scriptrunner_finish", |
443 | - self.scriptrunner_finish, |
444 | - dbus_interface="org.ubuntu.accomplishments") |
445 | + self.scriptrunner_finish, |
446 | + dbus_interface="org.ubuntu.accomplishments") |
447 | object.connect_to_signal("ubuntu_one_account_ready", |
448 | - self.ubuntu_one_account_ready, |
449 | - dbus_interface="org.ubuntu.accomplishments", arg0="Hello") |
450 | - |
451 | + self.ubuntu_one_account_ready, |
452 | + dbus_interface="org.ubuntu.accomplishments", arg0="Hello") |
453 | + |
454 | except dbus.DBusException: |
455 | print "DBus exception when connecting to daemon." |
456 | traceback.print_exc() |
457 | return False |
458 | |
459 | bus.add_signal_receiver(self.trophy_received, |
460 | - dbus_interface = "org.ubuntu.accomplishments", |
461 | - signal_name = "trophy_received") |
462 | + dbus_interface="org.ubuntu.accomplishments", |
463 | + signal_name="trophy_received") |
464 | bus.add_signal_receiver(self.publish_trophies_online_completed, |
465 | - dbus_interface = "org.ubuntu.accomplishments", |
466 | - signal_name = "publish_trophies_online_completed") |
467 | + dbus_interface="org.ubuntu.accomplishments", |
468 | + signal_name="publish_trophies_online_completed") |
469 | bus.add_signal_receiver(self.scriptrunner_start, |
470 | - dbus_interface = "org.ubuntu.accomplishments", |
471 | - signal_name = "scriptrunner_start") |
472 | + dbus_interface="org.ubuntu.accomplishments", |
473 | + signal_name="scriptrunner_start") |
474 | bus.add_signal_receiver(self.scriptrunner_finish, |
475 | - dbus_interface = "org.ubuntu.accomplishments", |
476 | - signal_name = "scriptrunner_finish") |
477 | + dbus_interface="org.ubuntu.accomplishments", |
478 | + signal_name="scriptrunner_finish") |
479 | bus.add_signal_receiver(self.ubuntu_one_account_ready, |
480 | - dbus_interface = "org.ubuntu.accomplishments", |
481 | - signal_name = "ubuntu_one_account_ready") |
482 | - |
483 | + dbus_interface="org.ubuntu.accomplishments", |
484 | + signal_name="ubuntu_one_account_ready") |
485 | + |
486 | self.connected = True |
487 | - |
488 | + |
489 | self.check_daemon_session() |
490 | - |
491 | + |
492 | return True |
493 | |
494 | def publish_trophies_online_completed(self, url): |
495 | webbrowser.open(url) |
496 | |
497 | - def ubuntu_one_account_ready(self): |
498 | + def ubuntu_one_account_ready(self): |
499 | if not self.has_u1 == 1: |
500 | self.register_with_verif(None) |
501 | - |
502 | + |
503 | def run_daemon(self): |
504 | - """Starts the daemon process""" |
505 | - |
506 | - # Not importing this globally, as it will be very rarely used. |
507 | - import subprocess |
508 | - import threading |
509 | - |
510 | - # Starting the daemon is realised in a separete thread, it can |
511 | - # wait for launcher to exit without blocking gtk main event loop. |
512 | - def run_in_thread_and_call_when_done(args,onexit): |
513 | - launcher_process = subprocess.Popen(args.split(" ")) |
514 | - launcher_process.wait() |
515 | - GObject.idle_add(onexit) |
516 | - return |
517 | + """Starts the daemon process""" |
518 | + |
519 | + # Not importing this globally, as it will be very rarely used. |
520 | + import subprocess |
521 | + import threading |
522 | + |
523 | + # Starting the daemon is realised in a separete thread, it can |
524 | + # wait for launcher to exit without blocking gtk main event loop. |
525 | + def run_in_thread_and_call_when_done(args, onexit): |
526 | + launcher_process = subprocess.Popen(args.split(" ")) |
527 | + launcher_process.wait() |
528 | + GObject.idle_add(onexit) |
529 | + return |
530 | command = os.path.join(daemon_exec_dir, "accomplishments-daemon") + " --start" |
531 | print ("Starting the daemon using command `%s`" % command) |
532 | - th = threading.Thread(target=run_in_thread_and_call_when_done,args=(command, self.run_daemon_continue)) |
533 | + th = threading.Thread(target=run_in_thread_and_call_when_done, args=(command, self.run_daemon_continue)) |
534 | th.start() |
535 | - |
536 | + |
537 | self.statusbar.set_text(_("Starting the daemon...")) |
538 | self.spinner.start() |
539 | self.spinner.show() |
540 | @@ -489,26 +487,26 @@ |
541 | def run_daemon_continue(self): |
542 | """Called from run_daemon when the daemon launcher exits. |
543 | Finishes what run_daemon would do""" |
544 | - |
545 | + |
546 | self.connect_to_daemon() |
547 | - |
548 | + |
549 | self.statusbox.hide() |
550 | - |
551 | + |
552 | if self.connected is False: |
553 | #Either failed to start the daemon, or failed to connect to |
554 | #It may either be not installed, or may have crashed on startup |
555 | self.statusbar.set_text("Failed to connect to the daemon.") |
556 | self.spinner.hide() |
557 | self.statusbox.show() |
558 | - GObject.timeout_add(10000,self.run_daemon) |
559 | + GObject.timeout_add(10000, self.run_daemon) |
560 | else: |
561 | #successfully started and connected |
562 | self.finalise_daemon_connection() |
563 | - |
564 | + |
565 | self.update_widgets_sensitivity() |
566 | - |
567 | + |
568 | #returning false removes the timeout |
569 | - return False |
570 | + return False |
571 | |
572 | def finalise_daemon_connection(self): |
573 | self.libaccom.create_all_trophy_icons() |
574 | @@ -518,7 +516,6 @@ |
575 | if len(self.accomdb) == 0: |
576 | self.add_no_collections_installed() |
577 | self.set_display(DISPLAY_MODE_OPPORTUNITIES) |
578 | - |
579 | |
580 | def update_widgets_sensitivity(self): |
581 | """Disables/enables some GUI elemets, according to whether the client is connected to the daemon or nor""" |
582 | @@ -532,7 +529,7 @@ |
583 | self.mnu_edit_ident.set_sensitive(False) |
584 | return |
585 | |
586 | - def edit_identification_clicked(self,w): |
587 | + def edit_identification_clicked(self, w): |
588 | """Called when user clicks Edit->Identification...""" |
589 | if self.connected is False: |
590 | return |
591 | @@ -544,9 +541,9 @@ |
592 | pass |
593 | |
594 | self.EditExtraDialog.prepare(self.libaccom) |
595 | - result = self.EditExtraDialog.run() #the dialog's response handlers will take care about storing the result |
596 | + result = self.EditExtraDialog.run() # the dialog's response handlers will take care about storing the result |
597 | self.EditExtraDialog.hide() |
598 | - |
599 | + |
600 | # re-load accoms and show the opps view, which will update both views |
601 | # XXX we should probably do this inside EditExtraInfoDialog.py |
602 | self._load_accomplishments() |
603 | @@ -558,7 +555,7 @@ |
604 | self.subcats_forward.set_sensitive(True) |
605 | |
606 | def subcat_clicked(self, button, data): |
607 | - self.set_display(filter_subcat = data) |
608 | + self.set_display(filter_subcat=data) |
609 | |
610 | def subcats_back_button(self, widget): |
611 | h = self.subcats_scroll.get_hadjustment() |
612 | @@ -572,33 +569,33 @@ |
613 | h.set_value(new) |
614 | self.subcats_scroll.set_hadjustment(h) |
615 | |
616 | - def show_gwibber_widget(self,accomID,name): |
617 | + def show_gwibber_widget(self, accomID, name): |
618 | if GWIBBER_OK: |
619 | # Temporarily using trophies.ubuntu.com |
620 | #trophyURL = TROPHY_GALLERY_URL+'/gallery/trophies/'+name+'/'+accomID |
621 | - trophyURL = 'http://trophies.ubuntu.com/gallery/trophies/'+name+'/'+accomID |
622 | - trophy_name = self.libaccom.get_accom_title(accomID); |
623 | + trophyURL = 'http://trophies.ubuntu.com/gallery/trophies/' + name + '/' + accomID |
624 | + trophy_name = self.libaccom.get_accom_title(accomID) |
625 | self.messageentry.text_view.get_buffer().set_text(_("I've just got the trophy '%s' in #ubuntu accomplishments!") % (trophy_name)) |
626 | self.messagewindow.show() |
627 | self.messagewindow.present() |
628 | |
629 | - def close_gwibber_window(self,widget=None,event=None): |
630 | + def close_gwibber_window(self, widget=None, event=None): |
631 | self.messagewindow.hide() |
632 | return True |
633 | - |
634 | + |
635 | def webkit_link_clicked(self, view, frame, net_req, nav_act, pol_dec): |
636 | """Load a link from the webkit view in an external system browser.""" |
637 | |
638 | - uri=net_req.get_uri() |
639 | - if uri.startswith ('file:///gwibber-share'): |
640 | + uri = net_req.get_uri() |
641 | + if uri.startswith('file:///gwibber-share'): |
642 | if GWIBBER_OK: |
643 | share_name = self.libaccom.get_share_name() |
644 | share_name = urllib2.quote(share_name.encode('utf8')) |
645 | share_ID = self.libaccom.get_share_id() |
646 | - nameURL = TROPHY_GALLERY_URL+"/user/getusername?share_name="+share_name+"&share_id="+share_ID |
647 | + nameURL = TROPHY_GALLERY_URL + "/user/getusername?share_name=" + share_name + "&share_id=" + share_ID |
648 | |
649 | publish_status = self.libaccom.get_published_status() |
650 | - if publish_status==0: |
651 | + if publish_status == 0: |
652 | dialog = Gtk.MessageDialog(self, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, _("Your trophies are not yet published")) |
653 | dialog.format_secondary_text(_("You can do it from Edit->Preferences menu.")) |
654 | dialog.run() |
655 | @@ -608,9 +605,9 @@ |
656 | response = urllib2.urlopen(nameURL) |
657 | for line in response: |
658 | name = line.rstrip() |
659 | - break |
660 | - uri = uri.replace("file:///gwibber-share?accomID=", ''); |
661 | - gwibberPopup = self.show_gwibber_widget(uri,name) |
662 | + break |
663 | + uri = uri.replace("file:///gwibber-share?accomID=", '') |
664 | + gwibberPopup = self.show_gwibber_widget(uri, name) |
665 | except urllib2.HTTPError: |
666 | print 'HTTPError while getting username.' |
667 | return True |
668 | @@ -621,23 +618,23 @@ |
669 | return False |
670 | |
671 | if uri.startswith('file:'): |
672 | - return False |
673 | - |
674 | + return False |
675 | + |
676 | if uri.startswith('http'): |
677 | webbrowser.open_new_tab(uri) |
678 | return True |
679 | |
680 | if uri.startswith('accomplishment:'): |
681 | id = uri[17:] |
682 | - self.set_display(DISPLAY_MODE_DETAILS,accomID=id) |
683 | + self.set_display(DISPLAY_MODE_DETAILS, accomID=id) |
684 | return True |
685 | |
686 | pol_dec.ignore() |
687 | - return True |
688 | + return True |
689 | |
690 | def scriptrunner_start(self): |
691 | """Indicate that the script runner is starting.""" |
692 | - |
693 | + |
694 | self.statusbar.set_text("Checking for new accomplishments...") |
695 | self.spinner.start() |
696 | self.spinner.show() |
697 | @@ -645,7 +642,7 @@ |
698 | |
699 | def scriptrunner_finish(self): |
700 | """Indicate that the script runner has stopped.""" |
701 | - |
702 | + |
703 | self.statusbar.set_text("") |
704 | self.spinner.stop() |
705 | self.spinner.hide() |
706 | @@ -663,7 +660,7 @@ |
707 | def verify_u1_account(self): |
708 | ver = self.libaccom.verify_ubuntu_one_account() |
709 | |
710 | - if bool(ver) == True: |
711 | + if bool(ver) is True: |
712 | self.u1_button.disconnect(self.u1_button_sig) |
713 | self.u1_button.set_label("Click here to confirm your Ubuntu One account") |
714 | self.u1_button_sig = self.u1_button.connect("clicked", self.register_with_verif) |
715 | @@ -694,7 +691,7 @@ |
716 | def complete_share_process(self): |
717 | self.has_u1 = True |
718 | self.libaccom.write_config_file_item("config", "has_u1", True) |
719 | - |
720 | + |
721 | self.additional_ubuntu1.set_visible(False) |
722 | |
723 | # ACCOMPLISHMENT: Editing Credentials |
724 | @@ -702,7 +699,7 @@ |
725 | self.libaccom.accomplish("ubuntu-desktop/accomplishments-shared-with-validation-server") |
726 | except: |
727 | pass |
728 | - |
729 | + |
730 | self.check_for_extra_info_required() |
731 | |
732 | def register_with_verif(self, widget): |
733 | @@ -716,20 +713,20 @@ |
734 | self.u1_button.show() |
735 | self.additional_ubuntu1.set_visible(True) |
736 | |
737 | - def on_window_resized(self,widget): |
738 | - # Workaround for GtkIconView bug in precise |
739 | - if self.display_mode is DISPLAY_MODE_OPPORTUNITIES: |
740 | - self._update_opportunities_view() |
741 | - elif self.display_mode is DISPLAY_MODE_TROPHIES: |
742 | - self._update_mytrophy_view() |
743 | - |
744 | + def on_window_resized(self, widget): |
745 | + # Workaround for GtkIconView bug in precise |
746 | + if self.display_mode is DISPLAY_MODE_OPPORTUNITIES: |
747 | + self._update_opportunities_view() |
748 | + elif self.display_mode is DISPLAY_MODE_TROPHIES: |
749 | + self._update_mytrophy_view() |
750 | + |
751 | def populate_opp_combos(self): |
752 | temp = [] |
753 | for i in self.accomdb: |
754 | - temp.append({i["collection"] : i["collection-human"] }) |
755 | + temp.append({i["collection"]: i["collection-human"]}) |
756 | # uniqify the values |
757 | result = [dict(tupleized) for tupleized in set(tuple(item.items()) for item in temp)] |
758 | - |
759 | + |
760 | # set up app |
761 | self.opp_col_store.append(["", "All"]) |
762 | for i in sorted(result): |
763 | @@ -741,73 +738,73 @@ |
764 | # Prepare categories combo |
765 | self.opp_combo_cat.set_model(self.opp_cat_store) |
766 | self.opp_combo_cat.show() |
767 | - |
768 | - def on_filter_collection_changed(self,widget): |
769 | + |
770 | + def on_filter_collection_changed(self, widget): |
771 | tree_iter = widget.get_active_iter() |
772 | model = widget.get_model() |
773 | collection, name = model[tree_iter][:2] |
774 | - self.set_display(filter_collection = collection) |
775 | + self.set_display(filter_collection=collection) |
776 | |
777 | def on_filter_category_changed(self, widget): |
778 | tree_iter = widget.get_active_iter() |
779 | - if tree_iter == None: # Special case if the categories combo is not sensitive |
780 | + if tree_iter is None: # Special case if the categories combo is not sensitive |
781 | return |
782 | model = widget.get_model() |
783 | category, name = model[tree_iter][:2] |
784 | - self.set_display(filter_category = category) |
785 | - |
786 | + self.set_display(filter_category=category) |
787 | + |
788 | def on_filter_show_locked_clicked(self, widget): |
789 | - if widget.get_active(): |
790 | - self.set_display(filter_locked=DISPLAY_FILTER_LOCKED_SHOW) |
791 | - else: |
792 | - self.set_display(filter_locked=DISPLAY_FILTER_LOCKED_HIDE) |
793 | - |
794 | - def on_search_changed(self,widget): |
795 | - value = widget.get_text() |
796 | - self.set_display(search_query=value) |
797 | - |
798 | - def on_search_clear_clicked(self,widget,icon,data): |
799 | + if widget.get_active(): |
800 | + self.set_display(filter_locked=DISPLAY_FILTER_LOCKED_SHOW) |
801 | + else: |
802 | + self.set_display(filter_locked=DISPLAY_FILTER_LOCKED_HIDE) |
803 | + |
804 | + def on_search_changed(self, widget): |
805 | + value = widget.get_text() |
806 | + self.set_display(search_query=value) |
807 | + |
808 | + def on_search_clear_clicked(self, widget, icon, data): |
809 | self.searchbar.set_text("") |
810 | - |
811 | + |
812 | def check_accomplishments(self, widget): |
813 | """Called when Check Accomplishments is selected in the interface.""" |
814 | self.libaccom.run_scripts(True) |
815 | - |
816 | + |
817 | def on_mytrophies_filter_latest_toggled(self, widget): |
818 | - self.set_display(trophies_mode=MYTROPHIES_FILTER_LATEST) |
819 | + self.set_display(trophies_mode=MYTROPHIES_FILTER_LATEST) |
820 | |
821 | - def on_mytrophies_filter_all_toggled(self, widget): |
822 | - self.set_display(trophies_mode=MYTROPHIES_FILTER_ALL) |
823 | + def on_mytrophies_filter_all_toggled(self, widget): |
824 | + self.set_display(trophies_mode=MYTROPHIES_FILTER_ALL) |
825 | |
826 | def on_tb_mytrophies_clicked(self, widget): |
827 | """Called when the My Trophies button is clicked.""" |
828 | - |
829 | + |
830 | mytrophies_toggled = self.tb_mytrophies.get_active() |
831 | opportunities_toggled = self.tb_opportunities.get_active() |
832 | - |
833 | - if mytrophies_toggled == True: |
834 | + |
835 | + if mytrophies_toggled is True: |
836 | self.set_display(DISPLAY_MODE_TROPHIES) |
837 | else: |
838 | - self.tb_mytrophies.set_active(True) # This also fires the signal handler |
839 | + self.tb_mytrophies.set_active(True) # This also fires the signal handler |
840 | |
841 | def on_tb_opportunities_clicked(self, widget): |
842 | """Called when the Opportunities button is clicked.""" |
843 | - |
844 | + |
845 | self.launcher.set_property("urgent", False) |
846 | self.newtrophies = 0 |
847 | self.launcher.set_property("count_visible", False) |
848 | - |
849 | + |
850 | mytrophies_toggled = self.tb_mytrophies.get_active() |
851 | opportunities_toggled = self.tb_opportunities.get_active() |
852 | - |
853 | - if opportunities_toggled == True: |
854 | + |
855 | + if opportunities_toggled is True: |
856 | self.set_display(DISPLAY_MODE_OPPORTUNITIES) |
857 | else: |
858 | - self.tb_opportunities.set_active(True) # This also fires the signal handler |
859 | + self.tb_opportunities.set_active(True) # This also fires the signal handler |
860 | |
861 | - def menu_prefs_clicked(self,widget): |
862 | + def menu_prefs_clicked(self, widget): |
863 | """Display the preferences window.""" |
864 | - |
865 | + |
866 | # If the window already is in use, when user clicks the menu |
867 | # item, present() is used instead, to bring the window to front |
868 | # etc. |
869 | @@ -819,24 +816,24 @@ |
870 | self.preferences_dialog.prepare(self.libaccom) |
871 | self.preferences_dialog.connect('destroy', self.on_preferences_dialog_destroyed) |
872 | self.preferences_dialog.show() |
873 | - |
874 | - def on_preferences_dialog_destroyed(self,widget): |
875 | + |
876 | + def on_preferences_dialog_destroyed(self, widget): |
877 | self.preferences_dialog = None |
878 | - |
879 | + |
880 | def get_icon(self, name): |
881 | theme = Gtk.IconTheme.get_default() |
882 | return theme.load_icon(name, 48, 0) |
883 | |
884 | def check_for_extra_info_required(self): |
885 | """Check if the installed accomplishments require additional information to be gathered from the user.""" |
886 | - |
887 | + |
888 | infoneeded = self.libaccom.get_all_extra_information_required() |
889 | |
890 | if len(infoneeded) is not 0: |
891 | # kick of the process of gathering the information needed |
892 | try: |
893 | seen = self.libaccom.get_config_value("config", "extrainfo_seen") |
894 | - |
895 | + |
896 | if seen == "NoOption" or seen == 0: |
897 | self.additional_info_req.set_visible(True) |
898 | self.libaccom.write_config_file_item("config", "extrainfo_seen", 1) |
899 | @@ -857,22 +854,22 @@ |
900 | self.libaccom.set_daemon_session_start(True) |
901 | self.additional_daemon_session.set_visible(False) |
902 | |
903 | - def edit_auth_info(self,widget): |
904 | + def edit_auth_info(self, widget): |
905 | """Called when user clicks "Edit credentials" from notification""" |
906 | self.additional_info_req.set_visible(False) |
907 | - self.edit_identification_clicked(widget) #that's maily the same thing |
908 | + self.edit_identification_clicked(widget) # that's maily the same thing |
909 | return |
910 | |
911 | - def edit_auth_info_cancel(self,widget): |
912 | + def edit_auth_info_cancel(self, widget): |
913 | """Called when user clicks "Later" from extrainfo-needed notification""" |
914 | self.additional_info_req.set_visible(False) |
915 | return |
916 | - |
917 | + |
918 | def _load_accomplishments(self): |
919 | # clear the local cache of accomplishments |
920 | self.accomdb = [] |
921 | self.accomdb = self.libaccom.build_viewer_database() |
922 | - |
923 | + |
924 | def opp_clicked(self, widget): |
925 | selection = widget.get_selected_items() |
926 | if len(selection) is 0: |
927 | @@ -881,7 +878,7 @@ |
928 | widget.unselect_path(item) |
929 | model = widget.get_model() |
930 | accomID = model[item][COL_ID] |
931 | - self.set_display(DISPLAY_MODE_DETAILS,accomID=accomID) |
932 | + self.set_display(DISPLAY_MODE_DETAILS, accomID=accomID) |
933 | |
934 | def mytrophy_clicked(self, widget): |
935 | selection = widget.get_selected_items() |
936 | @@ -891,7 +888,7 @@ |
937 | widget.unselect_path(item) |
938 | model = widget.get_model() |
939 | accomID = model[item][COL_ID] |
940 | - self.set_display(DISPLAY_MODE_DETAILS,accomID=accomID) |
941 | + self.set_display(DISPLAY_MODE_DETAILS, accomID=accomID) |
942 | |
943 | def optparse_accomplishment(self, accom_id): |
944 | """Process the -a command line option""" |
945 | @@ -899,8 +896,8 @@ |
946 | # this accomplishment does not exist! aborting... |
947 | print "There is no accomplishment with this ID." |
948 | return |
949 | - |
950 | - self.set_display(DISPLAY_MODE_DETAILS,accomID=accom_id) |
951 | + |
952 | + self.set_display(DISPLAY_MODE_DETAILS, accomID=accom_id) |
953 | |
954 | def prepare_models(self): |
955 | """ |
956 | @@ -919,31 +916,31 @@ |
957 | # Prepare latest trophies iconviews |
958 | if len(self.mytrophies_box_latest.get_children()) == 0: |
959 | self.mytrophies_latest_boxes = [] |
960 | - box = self.add_mytrophies_view(self.mytrophies_box_latest,_("Today"), self.trophiesstore_filter_today) |
961 | - self.mytrophies_latest_boxes.append([self.trophiesstore_filter_today,box]) |
962 | - box = self.add_mytrophies_view(self.mytrophies_box_latest,_("This Week"), self.trophiesstore_filter_week) |
963 | - self.mytrophies_latest_boxes.append([self.trophiesstore_filter_week,box]) |
964 | - box = self.add_mytrophies_view(self.mytrophies_box_latest,_("This Month"), self.trophiesstore_filter_month) |
965 | - self.mytrophies_latest_boxes.append([self.trophiesstore_filter_month,box]) |
966 | - box = self.add_mytrophies_view(self.mytrophies_box_latest,_("Last Six Months"), self.trophiesstore_filter_sixmonths) |
967 | - self.mytrophies_latest_boxes.append([self.trophiesstore_filter_sixmonths,box]) |
968 | - box = self.add_mytrophies_view(self.mytrophies_box_latest,_("Earlier"), self.trophiesstore_filter_earlier) |
969 | - self.mytrophies_latest_boxes.append([self.trophiesstore_filter_earlier,box]) |
970 | - |
971 | + box = self.add_mytrophies_view(self.mytrophies_box_latest, _("Today"), self.trophiesstore_filter_today) |
972 | + self.mytrophies_latest_boxes.append([self.trophiesstore_filter_today, box]) |
973 | + box = self.add_mytrophies_view(self.mytrophies_box_latest, _("This Week"), self.trophiesstore_filter_week) |
974 | + self.mytrophies_latest_boxes.append([self.trophiesstore_filter_week, box]) |
975 | + box = self.add_mytrophies_view(self.mytrophies_box_latest, _("This Month"), self.trophiesstore_filter_month) |
976 | + self.mytrophies_latest_boxes.append([self.trophiesstore_filter_month, box]) |
977 | + box = self.add_mytrophies_view(self.mytrophies_box_latest, _("Last Six Months"), self.trophiesstore_filter_sixmonths) |
978 | + self.mytrophies_latest_boxes.append([self.trophiesstore_filter_sixmonths, box]) |
979 | + box = self.add_mytrophies_view(self.mytrophies_box_latest, _("Earlier"), self.trophiesstore_filter_earlier) |
980 | + self.mytrophies_latest_boxes.append([self.trophiesstore_filter_earlier, box]) |
981 | + |
982 | # Prepare all trophies iconviews |
983 | kids = self.mytrophies_box_all.get_children() |
984 | for kid in kids: |
985 | - self.mytrophies_box_all.remove(k) |
986 | + self.mytrophies_box_all.remove(kid) |
987 | for f in self.trophies_collection_filters: |
988 | - del f[0] #Remove the filter! |
989 | + del f[0] # Remove the filter! |
990 | self.trophies_collection_filters = [] |
991 | collections = self.libaccom.list_collections() |
992 | for c in collections: |
993 | new_filter = self.trophiesstore.filter_new() |
994 | - new_filter.set_visible_func(self._trophy_all_visible_func,c) |
995 | + new_filter.set_visible_func(self._trophy_all_visible_func, c) |
996 | box = self.add_mytrophies_view(self.mytrophies_box_all, self.libaccom.get_collection_name(c), new_filter) |
997 | - self.trophies_collection_filters.append([new_filter,box]) |
998 | - |
999 | + self.trophies_collection_filters.append([new_filter, box]) |
1000 | + |
1001 | def add_mytrophies_view(self, parent, section, model): |
1002 | """ |
1003 | This function is used for adding a new group of accomplishments in mytrophies view. |
1004 | @@ -961,95 +958,95 @@ |
1005 | separator = Gtk.Separator() |
1006 | separator.set_property("margin_left", 10) |
1007 | separator.set_property("margin_right", 10) |
1008 | - |
1009 | + |
1010 | iconview = Gtk.IconView() |
1011 | iconview.set_model(model) |
1012 | iconview.set_text_column(COL_TITLE) |
1013 | iconview.set_pixbuf_column(COL_PIXBUF) |
1014 | iconview.set_item_width(120) |
1015 | iconview.set_columns(-1) |
1016 | - iconview.connect("selection-changed",self.mytrophy_clicked) |
1017 | + iconview.connect("selection-changed", self.mytrophy_clicked) |
1018 | |
1019 | outerbox.pack_start(header, False, False, 0) |
1020 | outerbox.pack_start(separator, False, False, 0) |
1021 | outerbox.pack_start(iconview, False, False, 0) |
1022 | outerbox.show_all() |
1023 | - |
1024 | + |
1025 | parent.add(outerbox) |
1026 | return outerbox |
1027 | |
1028 | - def set_display(self, |
1029 | - mode = DISPLAY_MODE_UNSPECIFIED, |
1030 | - accomID = "", |
1031 | - trophies_mode = MYTROPHIES_FILTER_UNSPECIFIED, |
1032 | - filter_locked = DISPLAY_FILTER_LOCKED_UNSPECIFIED, |
1033 | - filter_collection = DISPLAY_FILTER_COLLECTION_UNSPECIFIED, |
1034 | - filter_category = DISPLAY_FILTER_CATEGORY_UNSPECIFIED, |
1035 | - filter_subcat = DISPLAY_FILTER_SUBCAT_UNSPECIFIED, |
1036 | - search_query = DISPLAY_FILTER_SEARCH_UNSPECIFIED): |
1037 | - """ |
1038 | - Switches display mode as specified in arguments. |
1039 | + def set_display(self, |
1040 | + mode=DISPLAY_MODE_UNSPECIFIED, |
1041 | + accomID="", |
1042 | + trophies_mode=MYTROPHIES_FILTER_UNSPECIFIED, |
1043 | + filter_locked=DISPLAY_FILTER_LOCKED_UNSPECIFIED, |
1044 | + filter_collection=DISPLAY_FILTER_COLLECTION_UNSPECIFIED, |
1045 | + filter_category=DISPLAY_FILTER_CATEGORY_UNSPECIFIED, |
1046 | + filter_subcat=DISPLAY_FILTER_SUBCAT_UNSPECIFIED, |
1047 | + search_query=DISPLAY_FILTER_SEARCH_UNSPECIFIED): |
1048 | + """ |
1049 | + Switches display mode as specified in arguments. |
1050 | It takes care about flipping notebook pages, hiding unnecessary UI pieces etc. |
1051 | This function shouldn't be called with many arguments, pass only these that you want to override. |
1052 | - """ |
1053 | + """ |
1054 | # The ordering of following IF statements *IS* important! |
1055 | # For example, passing both collection and category to this function |
1056 | # may not result in skipping some of these data as they get cleared |
1057 | # later on. Therefore hierarhical order is desired. |
1058 | - if mode is not DISPLAY_MODE_UNSPECIFIED: |
1059 | - self.display_mode = mode |
1060 | + if mode is not DISPLAY_MODE_UNSPECIFIED: |
1061 | + self.display_mode = mode |
1062 | # Reflect changes in the UI |
1063 | if self.display_mode is DISPLAY_MODE_DETAILS: |
1064 | #Displaying details for an accomplishment |
1065 | - |
1066 | + |
1067 | if accomID == "": |
1068 | print "Unable to display details view, you probably forgot the accomID argument." |
1069 | return |
1070 | - |
1071 | + |
1072 | # Set togglable buttons to reflect current state |
1073 | - self.tb_mytrophies.handler_block_by_func(self.on_tb_mytrophies_clicked) |
1074 | - self.tb_opportunities.handler_block_by_func(self.on_tb_opportunities_clicked) |
1075 | - self.tb_mytrophies.set_active(False) |
1076 | + self.tb_mytrophies.handler_block_by_func(self.on_tb_mytrophies_clicked) |
1077 | + self.tb_opportunities.handler_block_by_func(self.on_tb_opportunities_clicked) |
1078 | + self.tb_mytrophies.set_active(False) |
1079 | self.tb_opportunities.set_active(False) |
1080 | self.tb_mytrophies.handler_unblock_by_func(self.on_tb_mytrophies_clicked) |
1081 | self.tb_opportunities.handler_unblock_by_func(self.on_tb_opportunities_clicked) |
1082 | - |
1083 | + |
1084 | # Select all characters in searchbar |
1085 | self.searchbar.grab_focus() |
1086 | - |
1087 | + |
1088 | self.notebook.set_current_page(0) |
1089 | self.searchbar_box.hide() |
1090 | - |
1091 | + |
1092 | elif self.display_mode is DISPLAY_MODE_TROPHIES: |
1093 | #Display the list of trophies |
1094 | - |
1095 | + |
1096 | # Set togglable buttons to reflect current state |
1097 | - self.tb_mytrophies.handler_block_by_func(self.on_tb_mytrophies_clicked) |
1098 | - self.tb_opportunities.handler_block_by_func(self.on_tb_opportunities_clicked) |
1099 | - self.tb_mytrophies.set_active(True) |
1100 | + self.tb_mytrophies.handler_block_by_func(self.on_tb_mytrophies_clicked) |
1101 | + self.tb_opportunities.handler_block_by_func(self.on_tb_opportunities_clicked) |
1102 | + self.tb_mytrophies.set_active(True) |
1103 | self.tb_opportunities.set_active(False) |
1104 | self.tb_mytrophies.handler_unblock_by_func(self.on_tb_mytrophies_clicked) |
1105 | self.tb_opportunities.handler_unblock_by_func(self.on_tb_opportunities_clicked) |
1106 | - |
1107 | + |
1108 | # Select all characters in searchbar |
1109 | self.searchbar.grab_focus() |
1110 | - |
1111 | + |
1112 | self.notebook.set_current_page(1) |
1113 | self.searchbar_box.show() |
1114 | - |
1115 | + |
1116 | elif self.display_mode is DISPLAY_MODE_OPPORTUNITIES: |
1117 | - |
1118 | + |
1119 | # Set togglable buttons to reflect current state |
1120 | - self.tb_mytrophies.handler_block_by_func(self.on_tb_mytrophies_clicked) |
1121 | - self.tb_opportunities.handler_block_by_func(self.on_tb_opportunities_clicked) |
1122 | - self.tb_mytrophies.set_active(False) |
1123 | + self.tb_mytrophies.handler_block_by_func(self.on_tb_mytrophies_clicked) |
1124 | + self.tb_opportunities.handler_block_by_func(self.on_tb_opportunities_clicked) |
1125 | + self.tb_mytrophies.set_active(False) |
1126 | self.tb_opportunities.set_active(True) |
1127 | self.tb_mytrophies.handler_unblock_by_func(self.on_tb_mytrophies_clicked) |
1128 | self.tb_opportunities.handler_unblock_by_func(self.on_tb_opportunities_clicked) |
1129 | - |
1130 | + |
1131 | self.notebook.set_current_page(2) |
1132 | self.searchbar_box.show() |
1133 | - |
1134 | + |
1135 | if trophies_mode is not MYTROPHIES_FILTER_UNSPECIFIED: |
1136 | self.display_mytrophies_filtermode = trophies_mode |
1137 | # Show/hide appropriate iconview |
1138 | @@ -1057,12 +1054,12 @@ |
1139 | self.mytrophies_notebook.set_current_page(0) |
1140 | elif self.display_mytrophies_filtermode is MYTROPHIES_FILTER_LATEST: |
1141 | self.mytrophies_notebook.set_current_page(1) |
1142 | - |
1143 | + |
1144 | if filter_locked is not DISPLAY_FILTER_LOCKED_UNSPECIFIED: |
1145 | self.display_filter_locked = filter_locked |
1146 | if filter_collection is not DISPLAY_FILTER_COLLECTION_UNSPECIFIED: |
1147 | self.display_filter_collection = filter_collection |
1148 | - |
1149 | + |
1150 | # As the requested collection changed, we need to update the categories combo. |
1151 | if filter_collection == "": |
1152 | self.opp_cat_store.clear() |
1153 | @@ -1075,28 +1072,27 @@ |
1154 | for i in sorted(cats): |
1155 | self.opp_cat_store.append([i, i]) |
1156 | self.opp_combo_cat.set_sensitive(True) |
1157 | - |
1158 | + |
1159 | # Set the active item to "everything". |
1160 | self.display_filter_category = "" |
1161 | self.opp_combo_cat.handler_block_by_func(self.on_filter_category_changed) |
1162 | self.opp_combo_cat.set_active(0) |
1163 | self.opp_combo_cat.handler_unblock_by_func(self.on_filter_category_changed) |
1164 | - |
1165 | + |
1166 | # It is likely that we need to update the subcategories. |
1167 | # A special case is when it needs to be hidden after collection change. |
1168 | self._update_subcats() |
1169 | - |
1170 | + |
1171 | if filter_category is not DISPLAY_FILTER_CATEGORY_UNSPECIFIED: |
1172 | self.display_filter_category = filter_category |
1173 | - |
1174 | + |
1175 | # Changing category, therefore we should display the subcats bar too. |
1176 | self._update_subcats() |
1177 | - |
1178 | + |
1179 | if filter_subcat is not DISPLAY_FILTER_SUBCAT_UNSPECIFIED: |
1180 | - self.display_filter_subcat = filter_subcat |
1181 | - if search_query is not DISPLAY_FILTER_SEARCH_UNSPECIFIED: |
1182 | - self.display_filter_search = search_query |
1183 | - |
1184 | + self.display_filter_subcat = filter_subcat |
1185 | + if search_query is not DISPLAY_FILTER_SEARCH_UNSPECIFIED: |
1186 | + self.display_filter_search = search_query |
1187 | |
1188 | # Finally, pass refreshing/rerendering to specialised functions |
1189 | if self.display_mode is DISPLAY_MODE_DETAILS: |
1190 | @@ -1105,7 +1101,7 @@ |
1191 | self._update_mytrophy_view() |
1192 | elif self.display_mode is DISPLAY_MODE_OPPORTUNITIES: |
1193 | self._update_opportunities_view() |
1194 | - |
1195 | + |
1196 | def _update_mytrophy_view(self): |
1197 | # Causes the treemodel to call visible_func for all rows. |
1198 | # It also hides/shows boxes depending on whether they are empty. |
1199 | @@ -1113,7 +1109,7 @@ |
1200 | filterlist = self.trophies_collection_filters |
1201 | elif self.display_mytrophies_filtermode is MYTROPHIES_FILTER_LATEST: |
1202 | filterlist = self.mytrophies_latest_boxes |
1203 | - |
1204 | + |
1205 | for f in filterlist: |
1206 | f[0].refilter() |
1207 | if len(f[0]) is 0: |
1208 | @@ -1124,7 +1120,7 @@ |
1209 | def _update_opportunities_view(self): |
1210 | # Causes the treemodel to call visible_func for all rows. |
1211 | self.oppstore_filtered.refilter() |
1212 | - |
1213 | + |
1214 | def _opp_visible_func(self, model, iterator, data): |
1215 | """ |
1216 | This function is crucial for filtering opportunities. It is called |
1217 | @@ -1133,26 +1129,29 @@ |
1218 | should be displayed or not. |
1219 | """ |
1220 | # If we are hiding locked accoms: |
1221 | - if (self.display_filter_locked is DISPLAY_FILTER_LOCKED_HIDE) and model.get_value(iterator,COL_LOCKED): |
1222 | + if (self.display_filter_locked is DISPLAY_FILTER_LOCKED_HIDE) and model.get_value(iterator, COL_LOCKED): |
1223 | return False |
1224 | # If we ale looking for a certain collection: |
1225 | - if (self.display_filter_collection != "") and (self.display_filter_collection != model.get_value(iterator,COL_COLLECTION)): |
1226 | + if (self.display_filter_collection != "") and (self.display_filter_collection != model.get_value(iterator, COL_COLLECTION)): |
1227 | return False |
1228 | # If we ale looking for a certain category... |
1229 | if (self.display_filter_category != ""): |
1230 | #...and a subcategory |
1231 | if (self.display_filter_subcat != ""): |
1232 | q = self.display_filter_category + ":" + self.display_filter_subcat |
1233 | - if not (q in model.get_value(iterator,COL_CATEGORIES)): |
1234 | + if not (q in model.get_value(iterator, COL_CATEGORIES)): |
1235 | return False |
1236 | - if not (self.display_filter_category in model.get_value(iterator,COL_CATEGORIES)): |
1237 | + if not (self.display_filter_category in model.get_value(iterator, COL_CATEGORIES)): |
1238 | return False |
1239 | # If there is a search term and this row does not match the query: |
1240 | - if (self.display_filter_search != "") and not (self.display_filter_search.lower() in model.get_value(iterator,COL_TITLE).lower()) and not (self.display_filter_search.lower() in model.get_value(iterator,COL_KEYWORDS).lower()) and not (self.display_filter_search.lower() in model.get_value(iterator,COL_ID).split("/")[1].lower()): |
1241 | - return False |
1242 | + if (self.display_filter_search != "") \ |
1243 | + and not (self.display_filter_search.lower() in model.get_value(iterator, COL_TITLE).lower()) \ |
1244 | + and not (self.display_filter_search.lower() in model.get_value(iterator, COL_KEYWORDS).lower()) \ |
1245 | + and not (self.display_filter_search.lower() in model.get_value(iterator, COL_ID).split("/")[1].lower()): |
1246 | + return False |
1247 | return True |
1248 | |
1249 | - def _trophy_recent_visible_func(self,model,iterator,data): |
1250 | + def _trophy_recent_visible_func(self, model, iterator, data): |
1251 | """ |
1252 | This function is crucial for filtering recently awarded trophies. It is called |
1253 | by some internal GTK callbacks, whenever the treemodel changes. |
1254 | @@ -1164,50 +1163,53 @@ |
1255 | |
1256 | #XXX: Making these constants global might save some filtering time. |
1257 | today = datetime.date.today() |
1258 | - margin_today = datetime.timedelta(days = 1) |
1259 | - margin_week = datetime.timedelta(days = 7) |
1260 | - margin_month = datetime.timedelta(days = 31) |
1261 | - margin_sixmonths = datetime.timedelta(days = 180) |
1262 | - |
1263 | - when = model.get_value(iterator,COL_DATE_ACCOMPLISHED) |
1264 | + margin_today = datetime.timedelta(days=1) |
1265 | + margin_week = datetime.timedelta(days=7) |
1266 | + margin_month = datetime.timedelta(days=31) |
1267 | + margin_sixmonths = datetime.timedelta(days=180) |
1268 | + |
1269 | + when = model.get_value(iterator, COL_DATE_ACCOMPLISHED) |
1270 | if when == "None": |
1271 | return False |
1272 | year, month, day = when.split("-") |
1273 | when = datetime.date(int(year), int(month), int(day.split(" ")[0])) |
1274 | - |
1275 | + |
1276 | if (today - margin_today <= when <= today + margin_today): |
1277 | if data is TROPHIES_FILTER_TODAY: |
1278 | - pass #proceed to further filtering |
1279 | + pass # proceed to further filtering |
1280 | else: |
1281 | return False |
1282 | elif (today - margin_week <= when <= today + margin_week): |
1283 | if data is TROPHIES_FILTER_WEEK: |
1284 | - pass #proceed to further filtering |
1285 | + pass # proceed to further filtering |
1286 | else: |
1287 | return False |
1288 | elif (today - margin_month <= when <= today + margin_month): |
1289 | if data is TROPHIES_FILTER_MONTH: |
1290 | - pass #proceed to further filtering |
1291 | + pass # proceed to further filtering |
1292 | else: |
1293 | return False |
1294 | elif (today - margin_sixmonths <= when <= today + margin_sixmonths): |
1295 | if data is TROPHIES_FILTER_SIXMONTHS: |
1296 | - pass #proceed to further filtering |
1297 | + pass # proceed to further filtering |
1298 | else: |
1299 | return False |
1300 | else: |
1301 | if data is TROPHIES_FILTER_EARLIER: |
1302 | - pass #proceed to further filtering |
1303 | + pass # proceed to further filtering |
1304 | else: |
1305 | return False |
1306 | - |
1307 | + |
1308 | # If there is a search term and this row does not match the query: |
1309 | - if (self.display_filter_search != "") and not (self.display_filter_search.lower() in model.get_value(iterator,COL_TITLE).lower()) and not (self.display_filter_search.lower() in model.get_value(iterator,COL_KEYWORDS).lower()) and not (self.display_filter_search.lower() in model.get_value(iterator,COL_ID).split("/")[1].lower()): |
1310 | - return False |
1311 | - |
1312 | + if (self.display_filter_search != "") \ |
1313 | + and not (self.display_filter_search.lower() in model.get_value(iterator, COL_TITLE).lower()) \ |
1314 | + and not (self.display_filter_search.lower() in model.get_value(iterator, COL_KEYWORDS).lower()) \ |
1315 | + and not (self.display_filter_search.lower() in model.get_value(iterator, COL_ID).split("/")[1].lower()): |
1316 | + return False |
1317 | + |
1318 | return True |
1319 | - |
1320 | - def _trophy_all_visible_func(self,model,iterator,collection): |
1321 | + |
1322 | + def _trophy_all_visible_func(self, model, iterator, collection): |
1323 | """ |
1324 | This function is crucial for filtering mytrophies. It is called |
1325 | by some internal GTK callbacks, whenever the treemodel changes. |
1326 | @@ -1216,14 +1218,16 @@ |
1327 | The @data argument specifies filtered collection. |
1328 | """ |
1329 | # If row's collection matches the desired for this filter |
1330 | - if (collection != model.get_value(iterator,COL_COLLECTION)): |
1331 | + if (collection != model.get_value(iterator, COL_COLLECTION)): |
1332 | return False |
1333 | # If there is a search term and this row does not match the query: |
1334 | - if (self.display_filter_search != "") and not (self.display_filter_search.lower() in model.get_value(iterator,COL_TITLE).lower()) and not (self.display_filter_search.lower() in model.get_value(iterator,COL_ID).split("/")[1].lower()): |
1335 | - return False |
1336 | + if (self.display_filter_search != "") \ |
1337 | + and not (self.display_filter_search.lower() in model.get_value(iterator, COL_TITLE).lower()) \ |
1338 | + and not (self.display_filter_search.lower() in model.get_value(iterator, COL_ID).split("/")[1].lower()): |
1339 | + return False |
1340 | return True |
1341 | |
1342 | - def _update_subcats(self): |
1343 | + def _update_subcats(self): |
1344 | """ |
1345 | This function creates the buttons for subcategories, requesting required data from the daemon. |
1346 | """ |
1347 | @@ -1238,15 +1242,17 @@ |
1348 | tempcats = cats[c] |
1349 | |
1350 | finalcats = [] |
1351 | - |
1352 | + |
1353 | for s in tempcats: |
1354 | for i in self.accomdb: |
1355 | - if i["collection"] == self.display_filter_collection and i["categories"][0] == self.display_filter_category + ":" + s and i["accomplished"] == False: |
1356 | + if i["collection"] == self.display_filter_collection \ |
1357 | + and i["categories"][0] == self.display_filter_category + ":" + s \ |
1358 | + and i["accomplished"] is False: |
1359 | finalcats.append(s) |
1360 | |
1361 | # convert to a set to remove dupes |
1362 | finalcats = set(finalcats) |
1363 | - |
1364 | + |
1365 | # remove previous buttons from the button box |
1366 | for b in self.subcats_buttonbox.get_children(): |
1367 | self.subcats_buttonbox.remove(b) |
1368 | @@ -1258,7 +1264,7 @@ |
1369 | button.connect("clicked", self.subcat_clicked, "") |
1370 | self.subcats_buttonbox.add(button) |
1371 | button.show() |
1372 | - |
1373 | + |
1374 | # fill the button box with the sub categories |
1375 | for s in finalcats: |
1376 | button = Gtk.Button(s) |
1377 | @@ -1266,34 +1272,37 @@ |
1378 | button.connect("clicked", self.subcat_clicked, s) |
1379 | self.subcats_buttonbox.add(button) |
1380 | button.show() |
1381 | - |
1382 | + |
1383 | self.subcats_buttonbox.show_all() |
1384 | self.subcats_container.show() |
1385 | else: |
1386 | self.subcats_container.hide() |
1387 | - |
1388 | + |
1389 | def _accomplishment_info(self, accomID): |
1390 | """Display information about the selected accomplishment.""" |
1391 | data = [] |
1392 | - |
1393 | + |
1394 | # determine dependencies |
1395 | - |
1396 | + |
1397 | deps = [] |
1398 | depstatus = [] |
1399 | - |
1400 | + |
1401 | deps = self.libaccom.get_accom_depends(accomID) |
1402 | - |
1403 | + |
1404 | for acc in self.accomdb: |
1405 | for d in deps: |
1406 | if acc["id"] == d: |
1407 | - depstatus.append({ "id" : acc["id"], "accomplished" : acc["accomplished"], "collection-human" : acc["collection-human"], "title" : acc["title"] }) |
1408 | - |
1409 | - |
1410 | + depstatus.append({ |
1411 | + "id": acc["id"], |
1412 | + "accomplished": acc["accomplished"], |
1413 | + "collection-human": acc["collection-human"], |
1414 | + "title": acc["title"] |
1415 | + }) |
1416 | + |
1417 | achieved = self.libaccom.get_accom_is_accomplished(accomID) |
1418 | data = self.libaccom.get_accom_data(accomID) |
1419 | if achieved: |
1420 | trophydata = self.libaccom.get_trophy_data(accomID) |
1421 | - |
1422 | |
1423 | html = None |
1424 | |
1425 | @@ -1311,17 +1320,16 @@ |
1426 | html = html + "<div id='header' class='grid_8'> \ |
1427 | <h1>" + data['title'] + "</h1> \ |
1428 | </div>" |
1429 | - |
1430 | - |
1431 | |
1432 | ## summary table |
1433 | html = html + "<div id='accomplishment' class='grid_8 clearfix'> \ |
1434 | <div id='accomplishment-badge' class='grid_8 clearfix'>" |
1435 | |
1436 | if achieved and GWIBBER_OK: |
1437 | - html = html + "<div id='social-share'><a href='gwibber-share?accomID="+accomID+"' id='gwibber-share'>+SHARE</a></div>" |
1438 | + html = html + "<div id='social-share'><a href='gwibber-share?accomID=" + accomID + \ |
1439 | + "' id='gwibber-share'>+SHARE</a></div>" |
1440 | |
1441 | - html = html +"<img class='icon' src='" + str(iconpath) + "'> \ |
1442 | + html = html + "<img class='icon' src='" + str(iconpath) + "'> \ |
1443 | <div class='grid_3 block'> \ |
1444 | <h4>" + _("Opportunity Information").decode('utf-8') + ":</h4> \ |
1445 | <ul class='none'> \ |
1446 | @@ -1332,53 +1340,59 @@ |
1447 | html = html + description |
1448 | else: |
1449 | html = html + _("No information available.").decode('utf-8') |
1450 | - |
1451 | - |
1452 | + |
1453 | html = html + "</li> \ |
1454 | </ul> \ |
1455 | </div>" |
1456 | |
1457 | if not achieved: |
1458 | - |
1459 | + |
1460 | html = html + "<div class='grid_3 block'> \ |
1461 | <h4>" + _("Getting Help").decode('utf-8') + ":</h4> \ |
1462 | <ul class='none'>" |
1463 | - |
1464 | + |
1465 | if "help" in data: |
1466 | help = data["help"] |
1467 | |
1468 | for l in help.split('\n'): |
1469 | - channelName = l[l.find("#")+1:l.find(" ")] |
1470 | - if l.startswith( '#'+channelName ): |
1471 | - l = "<a style='color:#FFF' href='http://webchat.freenode.net/?channels="+channelName+"'>"+'#'+channelName+" on freenode</a>" |
1472 | + channelName = l[l.find("#") + 1:l.find(" ")] |
1473 | + if l.startswith('#' + channelName): |
1474 | + l = "<a style='color:#FFF' href='http://webchat.freenode.net/?channels=" + channelName + "'>" \ |
1475 | + + '#' + channelName + " on freenode</a>" |
1476 | html = html + "<li>" + l + "</li>" |
1477 | else: |
1478 | - html = html + "<li>" + l + "</li>" |
1479 | + html = html + "<li>" + l + "</li>" |
1480 | else: |
1481 | html = html + "<li>" + _("No help available.").decode('utf-8') + "</li>" |
1482 | - |
1483 | + |
1484 | html = html + "</ul></div>" |
1485 | |
1486 | - |
1487 | html = html + "</div>" |
1488 | |
1489 | html = html + "<div id='accomplishment-conditions' class='grid_8'> \ |
1490 | <ul class='none'>" |
1491 | - |
1492 | + |
1493 | if "depends" in data: |
1494 | # check if it is locked |
1495 | if not self.libaccom.get_accom_is_unlocked(accomID): |
1496 | if len(depstatus) > 0: |
1497 | if len(depstatus) == 1: |
1498 | - html = html + "<li><i class='icon-key icon-large'></i>" + _("This opportunity is locked. You need to complete").decode('utf-8') + " <a href='accomplishment://" + depstatus[0]["id"] + "'><strong>" + depstatus[0]["title"] + "</strong></a> " + _("from").decode('utf-8') +" <strong>" + depstatus[0]["collection-human"] + "</strong> " + _("first").decode('utf-8') + ".</li>" |
1499 | + html = html + "<li><i class='icon-key icon-large'></i>" + \ |
1500 | + _("This opportunity is locked. You need to complete").decode('utf-8') + \ |
1501 | + " <a href='accomplishment://" + depstatus[0]["id"] + "'><strong>" + \ |
1502 | + depstatus[0]["title"] + "</strong></a> " + _("from").decode('utf-8') + \ |
1503 | + " <strong>" + depstatus[0]["collection-human"] + "</strong> " + \ |
1504 | + _("first").decode('utf-8') + ".</li>" |
1505 | else: |
1506 | html = html + "<li><i class='icon-key icon-large'></i>" + _("This opportunity is locked. You need to complete the following opportunities first:").decode('utf-8') + "</li>" |
1507 | for d in depstatus: |
1508 | - if d["accomplished"] == False: |
1509 | - html = html + "<li class='deps_child'><a href='accomplishment://" + d["id"] + "'><strong>" + d["title"] + "</strong></a> " + _("from").decode('utf-8') +" <strong>" + d["collection-human"] + "</strong></li>" |
1510 | + if d["accomplished"] is False: |
1511 | + html = html + "<li class='deps_child'><a href='accomplishment://" + d["id"] + \ |
1512 | + "'><strong>" + d["title"] + "</strong></a> " + _("from").decode('utf-8') + \ |
1513 | + " <strong>" + d["collection-human"] + "</strong></li>" |
1514 | if achieved: |
1515 | #achieved |
1516 | - |
1517 | + |
1518 | html = html + "<li><img src='" + str(get_media_file("verify-icon.png")) + "' height='20' />" + _("This trophy <strong>was awarded</strong>").decode('utf-8') |
1519 | |
1520 | if "date-accomplished" in trophydata: |
1521 | @@ -1389,10 +1403,10 @@ |
1522 | extrainfo = trophydata["needs-information"].split(" ") |
1523 | html = html + ", " + _("using the following credentials").decode('utf-8') + ":</li><li><ul class='big'>" |
1524 | for i in extrainfo: |
1525 | - e = self.libaccom.get_extra_information(accomID.split("/")[0],i) |
1526 | + e = self.libaccom.get_extra_information(accomID.split("/")[0], i) |
1527 | html = html + "<li>" + e[0]["label"] + ": " + trophydata[i] + "</li>" |
1528 | html = html + "</ul></li>" |
1529 | - else: |
1530 | + else: |
1531 | html = html + ".</li>" |
1532 | |
1533 | if "needs-signing" in data: |
1534 | @@ -1430,17 +1444,15 @@ |
1535 | else: |
1536 | #details not hidden by default |
1537 | html = html + "<div>" |
1538 | - |
1539 | - |
1540 | + |
1541 | if "summary" in data: |
1542 | html = html + "<div id='accompilshment-info' class='grid_8'>" |
1543 | summary = data["summary"] |
1544 | for l in summary.split('\n'): |
1545 | - html = html + "<p>" + l + "</p>" |
1546 | + html = html + "<p>" + l + "</p>" |
1547 | html = html + "</div>" |
1548 | |
1549 | - |
1550 | - html = html + "<div id='accomplishment-more' class='grid_8'>" |
1551 | + html = html + "<div id='accomplishment-more' class='grid_8'>" |
1552 | |
1553 | if "steps" in data: |
1554 | |
1555 | @@ -1448,7 +1460,7 @@ |
1556 | <i class='icon-list'></i> \ |
1557 | <h2>" + _("How to accomplish this opportunity").decode('utf-8') + "</h2> \ |
1558 | <ol>" |
1559 | - |
1560 | + |
1561 | steps = data["steps"] |
1562 | for l in steps.split('\n'): |
1563 | html = html + "<li class='icon-pushpin'>" + l + "</li>" |
1564 | @@ -1458,7 +1470,7 @@ |
1565 | showtipspitfalls = False |
1566 | haspitfalls = False |
1567 | hastips = False |
1568 | - |
1569 | + |
1570 | if "tips" in data or "pitfalls" in data: |
1571 | try: |
1572 | if not data["tips"] == "None": |
1573 | @@ -1466,51 +1478,51 @@ |
1574 | hastips = True |
1575 | except: |
1576 | hastips = False |
1577 | - |
1578 | + |
1579 | try: |
1580 | if not data["pitfalls"] == "None": |
1581 | - showtipspitfalls = True |
1582 | + showtipspitfalls = True |
1583 | haspitfalls = True |
1584 | except: |
1585 | haspitfalls = False |
1586 | - |
1587 | - if showtipspitfalls == True: |
1588 | + |
1589 | + if showtipspitfalls is True: |
1590 | html = html + " <div id='tipspitfalls' class='grid_8 clearfix'>" |
1591 | else: |
1592 | - showtipspitfalls == False |
1593 | - |
1594 | - if showtipspitfalls == True: |
1595 | + showtipspitfalls is False |
1596 | + |
1597 | + if showtipspitfalls is True: |
1598 | html = html + "<div class='grid_4 block left' id='tips'>" |
1599 | html = html + "<h2>" + _("Tips and Tricks").decode('utf-8') + ":</h2>" |
1600 | - |
1601 | - if hastips == True: |
1602 | + |
1603 | + if hastips is True: |
1604 | tips = data["tips"] |
1605 | else: |
1606 | tips = None |
1607 | - |
1608 | + |
1609 | html = html + "<ul>" |
1610 | |
1611 | - if tips == None: |
1612 | + if tips is None: |
1613 | html = html + "<li class='icon-ok'>" + _("None.").decode('utf-8') + "</li>" |
1614 | else: |
1615 | for t in tips.split('\n'): |
1616 | html = html + "<li class='icon-ok'>" + t + "</li>" |
1617 | - |
1618 | + |
1619 | html = html + "</ul>" |
1620 | html = html + "</div>" |
1621 | |
1622 | html = html + "<div id='divider' class='left'> </div>" |
1623 | html = html + "<div class='grid_3 block left' id='pitfals'>" |
1624 | html = html + "<h2>" + _("Pitfalls To Avoid").decode('utf-8') + ":</h2>" |
1625 | - |
1626 | - if haspitfalls == True: |
1627 | + |
1628 | + if haspitfalls is True: |
1629 | pitfalls = data["pitfalls"] |
1630 | else: |
1631 | pitfalls = None |
1632 | - |
1633 | + |
1634 | html = html + "<ul>" |
1635 | |
1636 | - if pitfalls == None: |
1637 | + if pitfalls is None: |
1638 | html = html + "<li class='icon-remove'>" + _("None.").decode('utf-8') + "</li>" |
1639 | else: |
1640 | for p in pitfalls.split('\n'): |
1641 | @@ -1537,4 +1549,3 @@ |
1642 | |
1643 | self.webview.load_html_string(html, "file:///") |
1644 | self.webview.show() |
1645 | - |
1646 | |
1647 | === modified file 'accomplishments_viewer/EditExtrainfoDialog.py' |
1648 | --- accomplishments_viewer/EditExtrainfoDialog.py 2012-11-22 10:42:15 +0000 |
1649 | +++ accomplishments_viewer/EditExtrainfoDialog.py 2012-11-26 16:03:25 +0000 |
1650 | @@ -1,48 +1,45 @@ |
1651 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
1652 | ### BEGIN LICENSE |
1653 | # Copyright (C) 2012 Jono Bacon <jono@ubuntu.com> |
1654 | -# This program is free software: you can redistribute it and/or modify it |
1655 | -# under the terms of the GNU General Public License version 3, as published |
1656 | +# This program is free software: you can redistribute it and/or modify it |
1657 | +# under the terms of the GNU General Public License version 3, as published |
1658 | # by the Free Software Foundation. |
1659 | -# |
1660 | -# This program is distributed in the hope that it will be useful, but |
1661 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
1662 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
1663 | +# |
1664 | +# This program is distributed in the hope that it will be useful, but |
1665 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
1666 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
1667 | # PURPOSE. See the GNU General Public License for more details. |
1668 | -# |
1669 | -# You should have received a copy of the GNU General Public License along |
1670 | +# |
1671 | +# You should have received a copy of the GNU General Public License along |
1672 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
1673 | ### END LICENSE |
1674 | -import logging |
1675 | |
1676 | -from gi.repository import Gtk # pylint: disable=E0611 |
1677 | +from gi.repository import Gtk # pylint: disable=E0611 |
1678 | from operator import itemgetter |
1679 | from accomplishments_viewer_lib.helpers import get_builder |
1680 | -from accomplishments.daemon import dbusapi |
1681 | |
1682 | -import gettext, locale |
1683 | -from locale import gettext as _ |
1684 | +import gettext |
1685 | +import locale |
1686 | from accomplishments.util.paths import locale_dir |
1687 | locale.bindtextdomain('accomplishments-viewer', locale_dir) |
1688 | -gettext.bindtextdomain('accomplishments-viewer',locale_dir) |
1689 | +gettext.bindtextdomain('accomplishments-viewer', locale_dir) |
1690 | locale.textdomain('accomplishments-viewer') |
1691 | - |
1692 | - |
1693 | - |
1694 | + |
1695 | + |
1696 | class EditExtrainfoDialog(Gtk.Dialog): |
1697 | __gtype_name__ = "EditExtrainfoDialog" |
1698 | - |
1699 | + |
1700 | def __new__(cls): |
1701 | - """Special static method that's automatically called by Python when |
1702 | + """Special static method that's automatically called by Python when |
1703 | constructing a new instance of this class. |
1704 | - |
1705 | + |
1706 | Returns a fully instantiated EditExtrainfoDialog object. |
1707 | """ |
1708 | builder = get_builder('EditExtrainfoDialog') |
1709 | new_object = builder.get_object('edit_extrainfo_dialog') |
1710 | new_object.finish_initializing(builder) |
1711 | return new_object |
1712 | - |
1713 | + |
1714 | def finish_initializing(self, builder): |
1715 | """Called when we're finished initializing. |
1716 | |
1717 | @@ -54,33 +51,33 @@ |
1718 | # Get a reference to the builder and set up the signals. |
1719 | self.builder = builder |
1720 | self.ui = builder.get_ui(self) |
1721 | - self.auth_box = builder.get_object('auth_box') |
1722 | - self.btn_ok = builder.get_object('btn_ok') |
1723 | - |
1724 | - def prepare(self,libaccom): |
1725 | + self.auth_box = builder.get_object('auth_box') |
1726 | + self.btn_ok = builder.get_object('btn_ok') |
1727 | + |
1728 | + def prepare(self, libaccom): |
1729 | """Called before run()nig, setups the window""" |
1730 | # use self.parent.libaccom for calling |
1731 | # use self.parent.connected to check if connected to daemon |
1732 | self.libaccom = libaccom |
1733 | - |
1734 | + |
1735 | i = self.libaccom.get_all_extra_information() |
1736 | - |
1737 | + |
1738 | self.entries_map = {} |
1739 | - |
1740 | + |
1741 | #remove all widgets that are contained in the auth_box |
1742 | #they will be there since the previous prepare() call |
1743 | c = self.auth_box.get_child() |
1744 | if c is not None: |
1745 | self.auth_box.remove(c) |
1746 | - |
1747 | + |
1748 | if len(i) is not 0: |
1749 | #there what to ask for |
1750 | self.main_box = Gtk.VBox() |
1751 | self.auth_box.add(self.main_box) |
1752 | - |
1753 | + |
1754 | #essential. It ensures we'll append items to section_dict, in an unchanging order. |
1755 | infoneeded = sorted(i, key=itemgetter('collection')) |
1756 | - |
1757 | + |
1758 | section_dict = {} |
1759 | extrainfo_dict = {} |
1760 | #section dict looks like: { "launchpad-email" : ["ubuntu-community","ubuntu-community-italy"], |
1761 | @@ -96,43 +93,42 @@ |
1762 | extrainfo_dict[i["needs-information"]] = i |
1763 | for a in section_dict: |
1764 | section_dict[a] = tuple(section_dict[a]) |
1765 | - |
1766 | - |
1767 | + |
1768 | rev_section_dict = {} |
1769 | #the rev_section_dict shal be the grouped inverse of section_dict: |
1770 | # { ("ubuntu-community","ubuntu-community-italy",) : ["launchpad-email","magic-token"], |
1771 | # ("askubuntu",) : ["askubuntu-login"], |
1772 | # ("openshot", "otherapp",) : ["github-id"] } |
1773 | - # |
1774 | - |
1775 | + # |
1776 | + |
1777 | for i in section_dict: |
1778 | d = section_dict[i] |
1779 | if d not in rev_section_dict: |
1780 | rev_section_dict[d] = list([i]) |
1781 | else: |
1782 | rev_section_dict[d].append(i) |
1783 | - |
1784 | - #print rev_section_dict |
1785 | - |
1786 | + |
1787 | + #print rev_section_dict |
1788 | + |
1789 | for i in sorted(rev_section_dict.keys(), reverse=True, key=len): |
1790 | #the gui code is here - done for every GROUP of entry fields |
1791 | d = rev_section_dict[i] |
1792 | - |
1793 | + |
1794 | g_box = Gtk.VBox() |
1795 | g_box.set_margin_bottom(20) |
1796 | g_box.set_margin_left(10) |
1797 | - self.main_box.pack_start(g_box,True,False,0) |
1798 | - |
1799 | + self.main_box.pack_start(g_box, True, False, 0) |
1800 | + |
1801 | g_upbox = Gtk.HBox() |
1802 | - g_box.pack_start(g_upbox,True,False,0) |
1803 | - |
1804 | + g_box.pack_start(g_upbox, True, False, 0) |
1805 | + |
1806 | g_upimage = Gtk.Image() |
1807 | g_upimage.set_margin_left(5) |
1808 | g_upimage.set_margin_top(5) |
1809 | g_upimage.set_margin_bottom(5) |
1810 | g_upimage.set_margin_right(5) |
1811 | - g_upimage.set_from_stock(Gtk.STOCK_GO_FORWARD,Gtk.IconSize.LARGE_TOOLBAR) |
1812 | - |
1813 | + g_upimage.set_from_stock(Gtk.STOCK_GO_FORWARD, Gtk.IconSize.LARGE_TOOLBAR) |
1814 | + |
1815 | #temporarily we'll use an ugly name |
1816 | n = len(i) |
1817 | if n is 1: |
1818 | @@ -141,32 +137,32 @@ |
1819 | name = self.libaccom.get_collection_name(i[0]) + " and " + self.libaccom.get_collection_name(i[1]) |
1820 | else: |
1821 | name = "" |
1822 | - for k in range(0,n): |
1823 | - if n-k > 2: |
1824 | + for k in range(0, n): |
1825 | + if n - k > 2: |
1826 | name = name + self.libaccom.get_collection_name(i[k]) + ", " |
1827 | - elif n-k is 2: |
1828 | + elif n - k is 2: |
1829 | name = name + self.libaccom.get_collection_name(i[k]) + " and " |
1830 | - elif n-k is 1: |
1831 | + elif n - k is 1: |
1832 | name = name + self.libaccom.get_collection_name(i[k]) |
1833 | - |
1834 | + |
1835 | g_uplabel = Gtk.Label("<big><b>" + name + "</b></big>") |
1836 | g_uplabel.set_use_markup(True) |
1837 | g_uplabel.set_margin_left(10) |
1838 | #g_uplabel.set_halign(Gtk.Align.START) |
1839 | - |
1840 | + |
1841 | g_sep = Gtk.HSeparator() |
1842 | - g_box.pack_start(g_sep,True,False,0) |
1843 | - |
1844 | + g_box.pack_start(g_sep, True, False, 0) |
1845 | + |
1846 | for f in d: |
1847 | #for each information field in the group... |
1848 | extrainfo = extrainfo_dict[f] |
1849 | label = extrainfo['label'] |
1850 | - label = label.replace("&","&") #pango would complain on that |
1851 | + label = label.replace("&", "&") # pango would complain on that |
1852 | description = extrainfo['description'] |
1853 | - description = description.replace("&","&") #pango would complain on that |
1854 | + description = description.replace("&", "&") # pango would complain on that |
1855 | value = extrainfo['value'] |
1856 | example = extrainfo.get('example') |
1857 | - |
1858 | + |
1859 | g_entrybox = Gtk.HBox() |
1860 | g_mainlabel = Gtk.Label(label) |
1861 | g_mainlabel.set_justify(Gtk.Justification.RIGHT) |
1862 | @@ -177,31 +173,31 @@ |
1863 | g_entry.set_text(value) |
1864 | g_desclabel = Gtk.Label("<small><small><b>" + description + "</b></small></small>") |
1865 | g_desclabel.set_use_markup(True) |
1866 | - g_desclabel.set_alignment(1,0) |
1867 | + g_desclabel.set_alignment(1, 0) |
1868 | |
1869 | if example: |
1870 | g_example = Gtk.Label("<small><small><b>Example: " + example + "</b></small></small>") |
1871 | g_example.set_use_markup(True) |
1872 | - g_example.set_alignment(1,0) |
1873 | + g_example.set_alignment(1, 0) |
1874 | g_example.set_margin_right(20) |
1875 | - |
1876 | + |
1877 | g_entrybox.set_margin_right(20) |
1878 | g_desclabel.set_margin_right(20) |
1879 | - |
1880 | - g_box.pack_start(g_entrybox,True,False,0) |
1881 | - g_box.pack_start(g_desclabel,True,False,0) |
1882 | + |
1883 | + g_box.pack_start(g_entrybox, True, False, 0) |
1884 | + g_box.pack_start(g_desclabel, True, False, 0) |
1885 | if example: |
1886 | - g_box.pack_start(g_example,True,False,0) |
1887 | - g_entrybox.pack_end(g_entry,False,False,0) |
1888 | - g_entrybox.pack_end(g_mainlabel,False,False,0) |
1889 | - |
1890 | - self.entries_map[f] = [g_entry,value] |
1891 | - |
1892 | - g_upbox.pack_start(g_upimage,False,False,0) |
1893 | - g_upbox.pack_start(g_uplabel,False,True,0) |
1894 | - |
1895 | + g_box.pack_start(g_example, True, False, 0) |
1896 | + g_entrybox.pack_end(g_entry, False, False, 0) |
1897 | + g_entrybox.pack_end(g_mainlabel, False, False, 0) |
1898 | + |
1899 | + self.entries_map[f] = [g_entry, value] |
1900 | + |
1901 | + g_upbox.pack_start(g_upimage, False, False, 0) |
1902 | + g_upbox.pack_start(g_uplabel, False, True, 0) |
1903 | + |
1904 | self.auth_box.show_all() |
1905 | - |
1906 | + |
1907 | else: |
1908 | #no point in asking at all |
1909 | label = Gtk.Label("<i>(no extra-information is required, most likely there is something wrong with your installtion)</i>") |
1910 | @@ -214,26 +210,25 @@ |
1911 | """Proxy function that simply calls the OK button when the user |
1912 | has pressed Enter on a textbox.""" |
1913 | self.btn_ok.clicked() |
1914 | - |
1915 | |
1916 | def on_btn_ok_clicked(self, widget, data=None): |
1917 | """The user has elected to save the changes. |
1918 | Called before the dialog returns Gtk.ResponseType.OK from run(). |
1919 | - """ |
1920 | - |
1921 | + """ |
1922 | + |
1923 | #saving the data should happen here. |
1924 | anything_changed = False |
1925 | for f in self.entries_map: |
1926 | - entry = self.entries_map[f][0] |
1927 | + entry = self.entries_map[f][0] |
1928 | origvalue = self.entries_map[f][1] |
1929 | - newvalue = entry.get_text() |
1930 | + newvalue = entry.get_text() |
1931 | if newvalue == origvalue: |
1932 | pass |
1933 | else: |
1934 | #print "value " + f + " changed" |
1935 | anything_changed = True |
1936 | - self.libaccom.write_extra_information_file(f,newvalue) |
1937 | - |
1938 | + self.libaccom.write_extra_information_file(f, newvalue) |
1939 | + |
1940 | if anything_changed: |
1941 | self.libaccom.run_scripts(True) |
1942 | |
1943 | |
1944 | === modified file 'accomplishments_viewer/PreferencesAccomplishmentsViewerDialog.py' |
1945 | --- accomplishments_viewer/PreferencesAccomplishmentsViewerDialog.py 2012-09-07 18:19:02 +0000 |
1946 | +++ accomplishments_viewer/PreferencesAccomplishmentsViewerDialog.py 2012-11-26 16:03:25 +0000 |
1947 | @@ -1,16 +1,16 @@ |
1948 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
1949 | ### BEGIN LICENSE |
1950 | # Copyright (C) 2012 Jono Bacon <jono@ubuntu.com> |
1951 | -# This program is free software: you can redistribute it and/or modify it |
1952 | -# under the terms of the GNU General Public License version 3, as published |
1953 | +# This program is free software: you can redistribute it and/or modify it |
1954 | +# under the terms of the GNU General Public License version 3, as published |
1955 | # by the Free Software Foundation. |
1956 | -# |
1957 | -# This program is distributed in the hope that it will be useful, but |
1958 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
1959 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
1960 | +# |
1961 | +# This program is distributed in the hope that it will be useful, but |
1962 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
1963 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
1964 | # PURPOSE. See the GNU General Public License for more details. |
1965 | -# |
1966 | -# You should have received a copy of the GNU General Public License along |
1967 | +# |
1968 | +# You should have received a copy of the GNU General Public License along |
1969 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
1970 | ### END LICENSE |
1971 | |
1972 | @@ -20,27 +20,24 @@ |
1973 | # data/glib-2.0/schemas/net.launchpad.accomplishments-viewer.gschema.xml |
1974 | # See http://developer.gnome.org/gio/stable/GSettings.html for more info. |
1975 | |
1976 | -from gi.repository import Gio # pylint: disable=E0611 |
1977 | - |
1978 | -import gettext, locale |
1979 | +import gettext |
1980 | +import locale |
1981 | from locale import gettext as _ |
1982 | from accomplishments.util.paths import locale_dir |
1983 | locale.bindtextdomain('accomplishments-viewer', locale_dir) |
1984 | -gettext.bindtextdomain('accomplishments-viewer',locale_dir) |
1985 | +gettext.bindtextdomain('accomplishments-viewer', locale_dir) |
1986 | locale.textdomain('accomplishments-viewer') |
1987 | |
1988 | -from accomplishments.daemon import dbusapi |
1989 | -import os, xdg.BaseDirectory, ConfigParser |
1990 | - |
1991 | import logging |
1992 | logger = logging.getLogger('accomplishments_viewer') |
1993 | |
1994 | from accomplishments_viewer_lib.PreferencesDialog import PreferencesDialog |
1995 | |
1996 | + |
1997 | class PreferencesAccomplishmentsViewerDialog(PreferencesDialog): |
1998 | __gtype_name__ = "PreferencesAccomplishmentsViewerDialog" |
1999 | |
2000 | - def finish_initializing(self, builder): # pylint: disable=E1002 |
2001 | + def finish_initializing(self, builder): # pylint: disable=E1002 |
2002 | """Set up the preferences dialog""" |
2003 | super(PreferencesAccomplishmentsViewerDialog, self).finish_initializing(builder) |
2004 | self.cb_daemonsessionstart = self.builder.get_object("cb_daemonsessionstart") |
2005 | @@ -49,9 +46,9 @@ |
2006 | self.pref_publish_label = self.builder.get_object("pref_publish_label") |
2007 | self.pref_publish_icon = self.builder.get_object("pref_publish_icon") |
2008 | self.publishedstatus = None |
2009 | - |
2010 | + |
2011 | #trophydir = self.libaccom.get_config_value("config", "trophypath") |
2012 | - |
2013 | + |
2014 | # Bind each preference widget to gsettings |
2015 | #settings = Gio.Settings("net.launchpad.accomplishments-viewer") |
2016 | #widget = self.builder.get_object('example_entry') |
2017 | @@ -59,21 +56,21 @@ |
2018 | |
2019 | # Code for other initialization actions should be added here. |
2020 | |
2021 | - def prepare(self,daemon_handle): |
2022 | + def prepare(self, daemon_handle): |
2023 | self.libaccom = daemon_handle |
2024 | self.populate_settings() |
2025 | - |
2026 | + |
2027 | self.publishedstatus = self.libaccom.get_published_status() |
2028 | - |
2029 | + |
2030 | if self.publishedstatus == 0: |
2031 | self.pref_publish.set_label(_("Publish...")) |
2032 | else: |
2033 | self.pref_publish.set_label(_("Stop Publishing")) |
2034 | - |
2035 | + |
2036 | def populate_settings(self): |
2037 | self.cb_daemonsessionstart.handler_block_by_func(self.cb_daemonsessionstart_toggled) |
2038 | self.cb_hideu1bubbles.handler_block_by_func(self.cb_hideu1bubbles_toggled) |
2039 | - |
2040 | + |
2041 | self.cb_daemonsessionstart.set_active(bool(self.libaccom.get_daemon_session_start())) |
2042 | print self.libaccom.get_daemon_session_start() |
2043 | print type(self.libaccom.get_daemon_session_start()) |
2044 | @@ -81,13 +78,13 @@ |
2045 | |
2046 | self.cb_daemonsessionstart.handler_unblock_by_func(self.cb_daemonsessionstart_toggled) |
2047 | self.cb_hideu1bubbles.handler_unblock_by_func(self.cb_hideu1bubbles_toggled) |
2048 | - |
2049 | + |
2050 | def cb_daemonsessionstart_toggled(self, widget): |
2051 | print widget.get_active() |
2052 | - self.libaccom.set_daemon_session_start( widget.get_active() ) |
2053 | + self.libaccom.set_daemon_session_start(widget.get_active()) |
2054 | |
2055 | def cb_hideu1bubbles_toggled(self, widget): |
2056 | - self.libaccom.set_block_ubuntuone_notification_bubbles( widget.get_active() ) |
2057 | + self.libaccom.set_block_ubuntuone_notification_bubbles(widget.get_active()) |
2058 | |
2059 | def on_pref_publish_clicked(self, widget): |
2060 | if self.publishedstatus == 0: |
2061 | |
2062 | === modified file 'accomplishments_viewer/__init__.py' |
2063 | --- accomplishments_viewer/__init__.py 2012-11-22 10:04:35 +0000 |
2064 | +++ accomplishments_viewer/__init__.py 2012-11-26 16:03:25 +0000 |
2065 | @@ -1,34 +1,36 @@ |
2066 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
2067 | ### BEGIN LICENSE |
2068 | # Copyright (C) 2012 Jono Bacon <jono@ubuntu.com> |
2069 | -# This program is free software: you can redistribute it and/or modify it |
2070 | -# under the terms of the GNU General Public License version 3, as published |
2071 | +# This program is free software: you can redistribute it and/or modify it |
2072 | +# under the terms of the GNU General Public License version 3, as published |
2073 | # by the Free Software Foundation. |
2074 | -# |
2075 | -# This program is distributed in the hope that it will be useful, but |
2076 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
2077 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2078 | +# |
2079 | +# This program is distributed in the hope that it will be useful, but |
2080 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
2081 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2082 | # PURPOSE. See the GNU General Public License for more details. |
2083 | -# |
2084 | -# You should have received a copy of the GNU General Public License along |
2085 | +# |
2086 | +# You should have received a copy of the GNU General Public License along |
2087 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
2088 | ### END LICENSE |
2089 | |
2090 | import optparse |
2091 | |
2092 | -import gettext, locale |
2093 | +import gettext |
2094 | +import locale |
2095 | from locale import gettext as _ |
2096 | from accomplishments.util.paths import locale_dir |
2097 | locale.bindtextdomain('accomplishments-viewer', locale_dir) |
2098 | -gettext.bindtextdomain('accomplishments-viewer',locale_dir) |
2099 | +gettext.bindtextdomain('accomplishments-viewer', locale_dir) |
2100 | locale.textdomain('accomplishments-viewer') |
2101 | |
2102 | -from gi.repository import Gtk, GObject # pylint: disable=E0611 |
2103 | +from gi.repository import Gtk, GObject # pylint: disable=E0611 |
2104 | |
2105 | from accomplishments_viewer import AccomplishmentsViewerWindow |
2106 | |
2107 | from accomplishments_viewer_lib import set_up_logging, get_version |
2108 | |
2109 | + |
2110 | def parse_options(): |
2111 | """Support for command line options""" |
2112 | parser = optparse.OptionParser(version="%%prog %s" % get_version()) |
2113 | @@ -39,20 +41,21 @@ |
2114 | "-a", "--accomplishment", action="store", dest="id", |
2115 | help=_("Display information about the provided accomplishment ID (e.g. 'ubuntu-community/registered-on-launchpad')").decode('utf-8')) |
2116 | (options, args) = parser.parse_args() |
2117 | - |
2118 | + |
2119 | set_up_logging(options) |
2120 | return options |
2121 | |
2122 | + |
2123 | def main(): |
2124 | 'constructor for your class instances' |
2125 | GObject.threads_init() |
2126 | options = parse_options() |
2127 | |
2128 | - # Run the application. |
2129 | + # Run the application. |
2130 | window = AccomplishmentsViewerWindow.AccomplishmentsViewerWindow() |
2131 | - |
2132 | + |
2133 | if options.id: |
2134 | window.optparse_accomplishment(options.id) |
2135 | - |
2136 | + |
2137 | window.show() |
2138 | Gtk.main() |
2139 | |
2140 | === modified file 'accomplishments_viewer_lib/AboutDialog.py' |
2141 | --- accomplishments_viewer_lib/AboutDialog.py 2012-09-07 18:19:02 +0000 |
2142 | +++ accomplishments_viewer_lib/AboutDialog.py 2012-11-26 16:03:25 +0000 |
2143 | @@ -1,32 +1,33 @@ |
2144 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
2145 | ### BEGIN LICENSE |
2146 | # Copyright (C) 2012 Jono Bacon <jono@ubuntu.com> |
2147 | -# This program is free software: you can redistribute it and/or modify it |
2148 | -# under the terms of the GNU General Public License version 3, as published |
2149 | +# This program is free software: you can redistribute it and/or modify it |
2150 | +# under the terms of the GNU General Public License version 3, as published |
2151 | # by the Free Software Foundation. |
2152 | -# |
2153 | -# This program is distributed in the hope that it will be useful, but |
2154 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
2155 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2156 | +# |
2157 | +# This program is distributed in the hope that it will be useful, but |
2158 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
2159 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2160 | # PURPOSE. See the GNU General Public License for more details. |
2161 | -# |
2162 | -# You should have received a copy of the GNU General Public License along |
2163 | +# |
2164 | +# You should have received a copy of the GNU General Public License along |
2165 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
2166 | ### END LICENSE |
2167 | |
2168 | ### DO NOT EDIT THIS FILE ### |
2169 | |
2170 | -from gi.repository import Gtk # pylint: disable=E0611 |
2171 | +from gi.repository import Gtk # pylint: disable=E0611 |
2172 | |
2173 | from . helpers import get_builder |
2174 | |
2175 | + |
2176 | class AboutDialog(Gtk.AboutDialog): |
2177 | __gtype_name__ = "AboutDialog" |
2178 | |
2179 | def __new__(cls): |
2180 | - """Special static method that's automatically called by Python when |
2181 | + """Special static method that's automatically called by Python when |
2182 | constructing a new instance of this class. |
2183 | - |
2184 | + |
2185 | Returns a fully instantiated AboutDialog object. |
2186 | """ |
2187 | builder = get_builder('AboutAccomplishmentsViewerDialog') |
2188 | @@ -41,10 +42,9 @@ |
2189 | and creating a AboutDialog object with it in order |
2190 | to finish initializing the start of the new AboutAccomplishmentsViewerDialog |
2191 | instance. |
2192 | - |
2193 | + |
2194 | Put your initialization code in here and leave __init__ undefined. |
2195 | """ |
2196 | # Get a reference to the builder and set up the signals. |
2197 | self.builder = builder |
2198 | self.ui = builder.get_ui(self) |
2199 | - |
2200 | |
2201 | === modified file 'accomplishments_viewer_lib/Builder.py' |
2202 | --- accomplishments_viewer_lib/Builder.py 2012-09-07 18:19:02 +0000 |
2203 | +++ accomplishments_viewer_lib/Builder.py 2012-11-26 16:03:25 +0000 |
2204 | @@ -1,16 +1,16 @@ |
2205 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
2206 | ### BEGIN LICENSE |
2207 | # Copyright (C) 2012 Jono Bacon <jono@ubuntu.com> |
2208 | -# This program is free software: you can redistribute it and/or modify it |
2209 | -# under the terms of the GNU General Public License version 3, as published |
2210 | +# This program is free software: you can redistribute it and/or modify it |
2211 | +# under the terms of the GNU General Public License version 3, as published |
2212 | # by the Free Software Foundation. |
2213 | -# |
2214 | -# This program is distributed in the hope that it will be useful, but |
2215 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
2216 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2217 | +# |
2218 | +# This program is distributed in the hope that it will be useful, but |
2219 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
2220 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2221 | # PURPOSE. See the GNU General Public License for more details. |
2222 | -# |
2223 | -# You should have received a copy of the GNU General Public License along |
2224 | +# |
2225 | +# You should have received a copy of the GNU General Public License along |
2226 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
2227 | ### END LICENSE |
2228 | |
2229 | @@ -18,7 +18,7 @@ |
2230 | |
2231 | '''Enhances builder connections, provides object to access glade objects''' |
2232 | |
2233 | -from gi.repository import GObject, Gtk # pylint: disable=E0611 |
2234 | +from gi.repository import GObject, Gtk # pylint: disable=E0611 |
2235 | |
2236 | import inspect |
2237 | import functools |
2238 | @@ -54,8 +54,7 @@ |
2239 | |
2240 | # pylint: disable=R0201 |
2241 | # this is a method so that a subclass of Builder can redefine it |
2242 | - def default_handler(self, |
2243 | - handler_name, filename, *args, **kwargs): |
2244 | + def default_handler(self, handler_name, filename, *args, **kwargs): |
2245 | '''helps the apprentice guru |
2246 | |
2247 | glade defined handlers that do not exist come here instead. |
2248 | @@ -108,7 +107,8 @@ |
2249 | ele_signals = tree.getiterator("signal") |
2250 | for ele_signal in ele_signals: |
2251 | self.glade_handler_dict.update( |
2252 | - {ele_signal.attrib["handler"]: None}) |
2253 | + {ele_signal.attrib["handler"]: None} |
2254 | + ) |
2255 | |
2256 | def connect_signals(self, callback_obj): |
2257 | '''connect the handlers defined in glade |
2258 | @@ -129,8 +129,7 @@ |
2259 | connection_dict[item[0]] = handler |
2260 | |
2261 | # replace the run time warning |
2262 | - logger.warn("expected handler '%s' in %s", |
2263 | - item[0], filename) |
2264 | + logger.warn("expected handler '%s' in %s", item[0], filename) |
2265 | |
2266 | # connect glade define handlers |
2267 | Gtk.Builder.connect_signals(self, connection_dict) |
2268 | @@ -139,7 +138,7 @@ |
2269 | for connection in self.connections: |
2270 | widget_name, signal_name, handler_name = connection |
2271 | logger.debug("connect builder by design '%s', '%s', '%s'", |
2272 | - widget_name, signal_name, handler_name) |
2273 | + widget_name, signal_name, handler_name) |
2274 | |
2275 | def get_ui(self, callback_obj=None, by_name=True): |
2276 | '''Creates the ui object with widgets as attributes |
2277 | @@ -175,7 +174,7 @@ |
2278 | cannot_message = """cannot bind ui.%s, name already exists |
2279 | consider using a pythonic name instead of design name '%s'""" |
2280 | consider_message = """consider using a pythonic name instead of design name '%s'""" |
2281 | - |
2282 | + |
2283 | for (widget_name, widget) in widget_dict.items(): |
2284 | pyname = make_pyname(widget_name) |
2285 | if pyname != widget_name: |
2286 | @@ -201,14 +200,14 @@ |
2287 | pyname = '' |
2288 | for character in name: |
2289 | if (character.isalpha() or character == '_' or |
2290 | - (pyname and character.isdigit())): |
2291 | + (pyname and character.isdigit())): |
2292 | pyname += character |
2293 | else: |
2294 | pyname += '_' |
2295 | return pyname |
2296 | |
2297 | |
2298 | -# Until bug https://bugzilla.gnome.org/show_bug.cgi?id=652127 is fixed, we |
2299 | +# Until bug https://bugzilla.gnome.org/show_bug.cgi?id=652127 is fixed, we |
2300 | # need to reimplement inspect.getmembers. GObject introspection doesn't |
2301 | # play nice with it. |
2302 | def getmembers(obj, check): |
2303 | @@ -285,13 +284,13 @@ |
2304 | handler_names.append("on_%s" % sig) |
2305 | |
2306 | do_connect(item, sig, handler_names, |
2307 | - callback_handler_dict, builder.connections) |
2308 | + callback_handler_dict, builder.connections) |
2309 | |
2310 | log_unconnected_functions(callback_handler_dict, builder.connections) |
2311 | |
2312 | |
2313 | def do_connect(item, signal_name, handler_names, |
2314 | - callback_handler_dict, connections): |
2315 | + callback_handler_dict, connections): |
2316 | '''connect this signal to an unused handler''' |
2317 | widget_name, widget = item |
2318 | |
2319 | @@ -304,7 +303,7 @@ |
2320 | connections.append(connection) |
2321 | |
2322 | logger.debug("connect builder by name '%s','%s', '%s'", |
2323 | - widget_name, signal_name, handler_name) |
2324 | + widget_name, signal_name, handler_name) |
2325 | |
2326 | |
2327 | def log_unconnected_functions(callback_handler_dict, connections): |
2328 | |
2329 | === modified file 'accomplishments_viewer_lib/PreferencesDialog.py' |
2330 | --- accomplishments_viewer_lib/PreferencesDialog.py 2012-09-07 18:19:02 +0000 |
2331 | +++ accomplishments_viewer_lib/PreferencesDialog.py 2012-11-26 16:03:25 +0000 |
2332 | @@ -1,16 +1,16 @@ |
2333 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
2334 | ### BEGIN LICENSE |
2335 | # Copyright (C) 2012 Jono Bacon <jono@ubuntu.com> |
2336 | -# This program is free software: you can redistribute it and/or modify it |
2337 | -# under the terms of the GNU General Public License version 3, as published |
2338 | +# This program is free software: you can redistribute it and/or modify it |
2339 | +# under the terms of the GNU General Public License version 3, as published |
2340 | # by the Free Software Foundation. |
2341 | -# |
2342 | -# This program is distributed in the hope that it will be useful, but |
2343 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
2344 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2345 | +# |
2346 | +# This program is distributed in the hope that it will be useful, but |
2347 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
2348 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2349 | # PURPOSE. See the GNU General Public License for more details. |
2350 | -# |
2351 | -# You should have received a copy of the GNU General Public License along |
2352 | +# |
2353 | +# You should have received a copy of the GNU General Public License along |
2354 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
2355 | ### END LICENSE |
2356 | |
2357 | @@ -19,19 +19,20 @@ |
2358 | """this dialog adjusts values in gsettings |
2359 | """ |
2360 | |
2361 | -from gi.repository import Gtk # pylint: disable=E0611 |
2362 | +from gi.repository import Gtk # pylint: disable=E0611 |
2363 | import logging |
2364 | logger = logging.getLogger('accomplishments_viewer_lib') |
2365 | |
2366 | from . helpers import get_builder, show_uri, get_help_uri |
2367 | |
2368 | + |
2369 | class PreferencesDialog(Gtk.Dialog): |
2370 | __gtype_name__ = "PreferencesDialog" |
2371 | |
2372 | def __new__(cls): |
2373 | - """Special static method that's automatically called by Python when |
2374 | + """Special static method that's automatically called by Python when |
2375 | constructing a new instance of this class. |
2376 | - |
2377 | + |
2378 | Returns a fully instantiated PreferencesDialog object. |
2379 | """ |
2380 | builder = get_builder('PreferencesAccomplishmentsViewerDialog') |
2381 | @@ -46,7 +47,7 @@ |
2382 | and creating a PreferencesDialog object with it in order to |
2383 | finish initializing the start of the new PerferencesAccomplishmentsViewerDialog |
2384 | instance. |
2385 | - |
2386 | + |
2387 | Put your initialization code in here and leave __init__ undefined. |
2388 | """ |
2389 | |
2390 | @@ -61,4 +62,3 @@ |
2391 | |
2392 | def on_btn_help_clicked(self, widget, data=None): |
2393 | show_uri(self, "ghelp:%s" % get_help_uri('preferences')) |
2394 | - |
2395 | |
2396 | === modified file 'accomplishments_viewer_lib/Window.py' |
2397 | --- accomplishments_viewer_lib/Window.py 2012-09-07 18:19:02 +0000 |
2398 | +++ accomplishments_viewer_lib/Window.py 2012-11-26 16:03:25 +0000 |
2399 | @@ -1,33 +1,34 @@ |
2400 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
2401 | ### BEGIN LICENSE |
2402 | # Copyright (C) 2012 Jono Bacon <jono@ubuntu.com> |
2403 | -# This program is free software: you can redistribute it and/or modify it |
2404 | -# under the terms of the GNU General Public License version 3, as published |
2405 | +# This program is free software: you can redistribute it and/or modify it |
2406 | +# under the terms of the GNU General Public License version 3, as published |
2407 | # by the Free Software Foundation. |
2408 | -# |
2409 | -# This program is distributed in the hope that it will be useful, but |
2410 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
2411 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2412 | +# |
2413 | +# This program is distributed in the hope that it will be useful, but |
2414 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
2415 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2416 | # PURPOSE. See the GNU General Public License for more details. |
2417 | -# |
2418 | -# You should have received a copy of the GNU General Public License along |
2419 | +# |
2420 | +# You should have received a copy of the GNU General Public License along |
2421 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
2422 | ### END LICENSE |
2423 | |
2424 | ### DO NOT EDIT THIS FILE ### |
2425 | |
2426 | -from gi.repository import Gio, Gtk # pylint: disable=E0611 |
2427 | +from gi.repository import Gio, Gtk # pylint: disable=E0611 |
2428 | import logging |
2429 | logger = logging.getLogger('accomplishments_viewer_lib') |
2430 | |
2431 | from . helpers import get_builder, show_uri, get_help_uri |
2432 | |
2433 | + |
2434 | # This class is meant to be subclassed by AccomplishmentsViewerWindow. It provides |
2435 | # common functions and some boilerplate. |
2436 | class Window(Gtk.Window): |
2437 | __gtype_name__ = "Window" |
2438 | |
2439 | - # To construct a new instance of this method, the following notable |
2440 | + # To construct a new instance of this method, the following notable |
2441 | # methods are called in this order: |
2442 | # __new__(cls) |
2443 | # __init__(self) |
2444 | @@ -36,11 +37,11 @@ |
2445 | # |
2446 | # For this reason, it's recommended you leave __init__ empty and put |
2447 | # your initialization code in finish_initializing |
2448 | - |
2449 | + |
2450 | def __new__(cls): |
2451 | - """Special static method that's automatically called by Python when |
2452 | + """Special static method that's automatically called by Python when |
2453 | constructing a new instance of this class. |
2454 | - |
2455 | + |
2456 | Returns a fully instantiated BaseAccomplishmentsViewerWindow object. |
2457 | """ |
2458 | builder = get_builder('AccomplishmentsViewerWindow') |
2459 | @@ -58,9 +59,9 @@ |
2460 | # Get a reference to the builder and set up the signals. |
2461 | self.builder = builder |
2462 | self.ui = builder.get_ui(self, True) |
2463 | - self.PreferencesDialog = None # class |
2464 | - self.preferences_dialog = None # instance |
2465 | - self.AboutDialog = None # class |
2466 | + self.PreferencesDialog = None # class |
2467 | + self.preferences_dialog = None # instance |
2468 | + self.AboutDialog = None # class |
2469 | |
2470 | self.settings = Gio.Settings("net.launchpad.accomplishments-viewer") |
2471 | self.settings.connect('changed', self.on_preferences_changed) |
2472 | @@ -84,7 +85,7 @@ |
2473 | def on_mnu_about_activate(self, widget, data=None): |
2474 | """Display the about box for accomplishments-viewer.""" |
2475 | if self.AboutDialog is not None: |
2476 | - about = self.AboutDialog() # pylint: disable=E1102 |
2477 | + about = self.AboutDialog() # pylint: disable=E1102 |
2478 | response = about.run() |
2479 | about.destroy() |
2480 | |
2481 | @@ -101,7 +102,7 @@ |
2482 | self.preferences_dialog.present() |
2483 | elif self.PreferencesDialog is not None: |
2484 | logger.debug('create new preferences_dialog') |
2485 | - self.preferences_dialog = self.PreferencesDialog() # pylint: disable=E1102 |
2486 | + self.preferences_dialog = self.PreferencesDialog() # pylint: disable=E1102 |
2487 | self.preferences_dialog.connect('destroy', self.on_preferences_dialog_destroyed) |
2488 | self.preferences_dialog.show() |
2489 | # destroy command moved into dialog to allow for a help button |
2490 | @@ -120,7 +121,7 @@ |
2491 | |
2492 | def on_preferences_dialog_destroyed(self, widget, data=None): |
2493 | '''only affects gui |
2494 | - |
2495 | + |
2496 | logically there is no difference between the user closing, |
2497 | minimising or ignoring the preferences dialog''' |
2498 | logger.debug('on_preferences_dialog_destroyed') |
2499 | |
2500 | === modified file 'accomplishments_viewer_lib/__init__.py' |
2501 | --- accomplishments_viewer_lib/__init__.py 2012-09-07 18:19:02 +0000 |
2502 | +++ accomplishments_viewer_lib/__init__.py 2012-11-26 16:03:25 +0000 |
2503 | @@ -1,16 +1,16 @@ |
2504 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
2505 | ### BEGIN LICENSE |
2506 | # Copyright (C) 2012 Jono Bacon <jono@ubuntu.com> |
2507 | -# This program is free software: you can redistribute it and/or modify it |
2508 | -# under the terms of the GNU General Public License version 3, as published |
2509 | +# This program is free software: you can redistribute it and/or modify it |
2510 | +# under the terms of the GNU General Public License version 3, as published |
2511 | # by the Free Software Foundation. |
2512 | -# |
2513 | -# This program is distributed in the hope that it will be useful, but |
2514 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
2515 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2516 | +# |
2517 | +# This program is distributed in the hope that it will be useful, but |
2518 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
2519 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2520 | # PURPOSE. See the GNU General Public License for more details. |
2521 | -# |
2522 | -# You should have received a copy of the GNU General Public License along |
2523 | +# |
2524 | +# You should have received a copy of the GNU General Public License along |
2525 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
2526 | ### END LICENSE |
2527 | |
2528 | @@ -22,4 +22,3 @@ |
2529 | from . helpers import set_up_logging |
2530 | from . Window import Window |
2531 | from . accomplishments_viewerconfig import get_version |
2532 | - |
2533 | |
2534 | === modified file 'accomplishments_viewer_lib/accomplishments_viewerconfig.py' |
2535 | --- accomplishments_viewer_lib/accomplishments_viewerconfig.py 2012-09-07 18:19:02 +0000 |
2536 | +++ accomplishments_viewer_lib/accomplishments_viewerconfig.py 2012-11-26 16:03:25 +0000 |
2537 | @@ -1,16 +1,16 @@ |
2538 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
2539 | ### BEGIN LICENSE |
2540 | # Copyright (C) 2012 Jono Bacon <jono@ubuntu.com> |
2541 | -# This program is free software: you can redistribute it and/or modify it |
2542 | -# under the terms of the GNU General Public License version 3, as published |
2543 | +# This program is free software: you can redistribute it and/or modify it |
2544 | +# under the terms of the GNU General Public License version 3, as published |
2545 | # by the Free Software Foundation. |
2546 | -# |
2547 | -# This program is distributed in the hope that it will be useful, but |
2548 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
2549 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2550 | +# |
2551 | +# This program is distributed in the hope that it will be useful, but |
2552 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
2553 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2554 | # PURPOSE. See the GNU General Public License for more details. |
2555 | -# |
2556 | -# You should have received a copy of the GNU General Public License along |
2557 | +# |
2558 | +# You should have received a copy of the GNU General Public License along |
2559 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
2560 | ### END LICENSE |
2561 | |
2562 | @@ -20,7 +20,7 @@ |
2563 | 'project_path_not_found', |
2564 | 'get_data_file', |
2565 | 'get_data_path', |
2566 | - ] |
2567 | +] |
2568 | |
2569 | # Where your project will look for your data (for instance, images and ui |
2570 | # files). By default, this is ../data, relative your trunk layout |
2571 | @@ -30,7 +30,6 @@ |
2572 | |
2573 | import os |
2574 | |
2575 | -from locale import gettext as _ |
2576 | |
2577 | class project_path_not_found(Exception): |
2578 | """Raised when we can't find the project directory.""" |
2579 | |
2580 | === modified file 'accomplishments_viewer_lib/helpers.py' |
2581 | --- accomplishments_viewer_lib/helpers.py 2012-09-07 18:19:02 +0000 |
2582 | +++ accomplishments_viewer_lib/helpers.py 2012-11-26 16:03:25 +0000 |
2583 | @@ -1,16 +1,16 @@ |
2584 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
2585 | ### BEGIN LICENSE |
2586 | # Copyright (C) 2012 Jono Bacon <jono@ubuntu.com> |
2587 | -# This program is free software: you can redistribute it and/or modify it |
2588 | -# under the terms of the GNU General Public License version 3, as published |
2589 | +# This program is free software: you can redistribute it and/or modify it |
2590 | +# under the terms of the GNU General Public License version 3, as published |
2591 | # by the Free Software Foundation. |
2592 | -# |
2593 | -# This program is distributed in the hope that it will be useful, but |
2594 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
2595 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2596 | +# |
2597 | +# This program is distributed in the hope that it will be useful, but |
2598 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
2599 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2600 | # PURPOSE. See the GNU General Public License for more details. |
2601 | -# |
2602 | -# You should have received a copy of the GNU General Public License along |
2603 | +# |
2604 | +# You should have received a copy of the GNU General Public License along |
2605 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
2606 | ### END LICENSE |
2607 | |
2608 | @@ -25,10 +25,11 @@ |
2609 | |
2610 | from locale import gettext as _ |
2611 | |
2612 | + |
2613 | def get_builder(builder_file_name): |
2614 | - """Return a fully-instantiated Gtk.Builder instance from specified ui |
2615 | + """Return a fully-instantiated Gtk.Builder instance from specified ui |
2616 | file |
2617 | - |
2618 | + |
2619 | :param builder_file_name: The name of the builder file, without extension. |
2620 | Assumed to be in the 'ui' directory under the data path. |
2621 | """ |
2622 | @@ -49,12 +50,14 @@ |
2623 | if not os.path.exists(media_filename): |
2624 | media_filename = None |
2625 | |
2626 | - return "file:///"+media_filename |
2627 | + return "file:///" + media_filename |
2628 | + |
2629 | |
2630 | class NullHandler(logging.Handler): |
2631 | def emit(self, record): |
2632 | pass |
2633 | |
2634 | + |
2635 | def set_up_logging(opts): |
2636 | # add a handler to prevent basicConfig |
2637 | root = logging.getLogger() |
2638 | @@ -80,6 +83,7 @@ |
2639 | if opts.verbose > 1: |
2640 | lib_logger.setLevel(logging.DEBUG) |
2641 | |
2642 | + |
2643 | def get_help_uri(page=None): |
2644 | # help_uri from source tree - default language |
2645 | here = os.path.dirname(__file__) |
2646 | @@ -95,11 +99,13 @@ |
2647 | |
2648 | return help_uri |
2649 | |
2650 | + |
2651 | def show_uri(parent, link): |
2652 | - from gi.repository import Gtk # pylint: disable=E0611 |
2653 | + from gi.repository import Gtk # pylint: disable=E0611 |
2654 | screen = parent.get_screen() |
2655 | Gtk.show_uri(screen, link, Gtk.get_current_event_time()) |
2656 | |
2657 | + |
2658 | def alias(alternative_function_name): |
2659 | '''see http://www.drdobbs.com/web-development/184406073#l9''' |
2660 | def decorator(function): |
2661 | |
2662 | === modified file 'bin/accomplishments-viewer' |
2663 | --- bin/accomplishments-viewer 2012-09-07 18:19:02 +0000 |
2664 | +++ bin/accomplishments-viewer 2012-11-26 16:03:25 +0000 |
2665 | @@ -2,16 +2,16 @@ |
2666 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
2667 | ### BEGIN LICENSE |
2668 | # Copyright (C) 2012 Jono Bacon <jono@ubuntu.com> |
2669 | -# This program is free software: you can redistribute it and/or modify it |
2670 | -# under the terms of the GNU General Public License version 3, as published |
2671 | +# This program is free software: you can redistribute it and/or modify it |
2672 | +# under the terms of the GNU General Public License version 3, as published |
2673 | # by the Free Software Foundation. |
2674 | -# |
2675 | -# This program is distributed in the hope that it will be useful, but |
2676 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
2677 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2678 | +# |
2679 | +# This program is distributed in the hope that it will be useful, but |
2680 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
2681 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2682 | # PURPOSE. See the GNU General Public License for more details. |
2683 | -# |
2684 | -# You should have received a copy of the GNU General Public License along |
2685 | +# |
2686 | +# You should have received a copy of the GNU General Public License along |
2687 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
2688 | ### END LICENSE |
2689 | |
2690 | @@ -30,18 +30,18 @@ |
2691 | python_path = [] |
2692 | if os.path.abspath(__file__).startswith('/opt'): |
2693 | locale.bindtextdomain('accomplishments-viewer', '/opt/extras.ubuntu.com/accomplishments-viewer/share/locale') |
2694 | - syspath = sys.path[:] # copy to avoid infinite loop in pending objects |
2695 | + syspath = sys.path[:] # copy to avoid infinite loop in pending objects |
2696 | for path in syspath: |
2697 | opt_path = path.replace('/usr', '/opt/extras.ubuntu.com/accomplishments-viewer') |
2698 | python_path.insert(0, opt_path) |
2699 | sys.path.insert(0, opt_path) |
2700 | os.putenv("XDG_DATA_DIRS", "%s:%s" % ("/opt/extras.ubuntu.com/accomplishments-viewer/share/", os.getenv("XDG_DATA_DIRS", "/usr/local/share/:/usr/share/"))) |
2701 | if (os.path.exists(os.path.join(PROJECT_ROOT_DIRECTORY, 'accomplishments_viewer')) |
2702 | - and PROJECT_ROOT_DIRECTORY not in sys.path): |
2703 | + and PROJECT_ROOT_DIRECTORY not in sys.path): |
2704 | python_path.insert(0, PROJECT_ROOT_DIRECTORY) |
2705 | sys.path.insert(0, PROJECT_ROOT_DIRECTORY) |
2706 | if python_path: |
2707 | - os.putenv('PYTHONPATH', "%s:%s" % (os.getenv('PYTHONPATH', ''), ':'.join(python_path))) # for subprocesses |
2708 | + os.putenv('PYTHONPATH', "%s:%s" % (os.getenv('PYTHONPATH', ''), ':'.join(python_path))) # for subprocesses |
2709 | |
2710 | import accomplishments_viewer |
2711 | accomplishments_viewer.main() |
2712 | |
2713 | === modified file 'tests/test_example.py' |
2714 | --- tests/test_example.py 2012-09-07 18:40:05 +0000 |
2715 | +++ tests/test_example.py 2012-11-26 16:03:25 +0000 |
2716 | @@ -2,16 +2,16 @@ |
2717 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
2718 | ### BEGIN LICENSE |
2719 | # Copyright (C) 2012 Jono Bacon <jono@ubuntu.com> |
2720 | -# This program is free software: you can redistribute it and/or modify it |
2721 | -# under the terms of the GNU General Public License version 3, as published |
2722 | +# This program is free software: you can redistribute it and/or modify it |
2723 | +# under the terms of the GNU General Public License version 3, as published |
2724 | # by the Free Software Foundation. |
2725 | -# |
2726 | -# This program is distributed in the hope that it will be useful, but |
2727 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
2728 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2729 | +# |
2730 | +# This program is distributed in the hope that it will be useful, but |
2731 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
2732 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2733 | # PURPOSE. See the GNU General Public License for more details. |
2734 | -# |
2735 | -# You should have received a copy of the GNU General Public License along |
2736 | +# |
2737 | +# You should have received a copy of the GNU General Public License along |
2738 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
2739 | ### END LICENSE |
2740 | |
2741 | @@ -22,10 +22,13 @@ |
2742 | |
2743 | from accomplishments_viewer import AboutAccomplishmentsViewerDialog |
2744 | |
2745 | + |
2746 | class TestExample(unittest.TestCase): |
2747 | def setUp(self): |
2748 | self.AboutAccomplishmentsViewerDialog_members = [ |
2749 | - 'AboutAccomplishmentsViewerDialog', 'AboutDialog', 'dbusapi', 'gettext', 'locale', 'locale_dir', 'logger', 'logging'] |
2750 | + 'AboutAccomplishmentsViewerDialog', 'AboutDialog', 'dbusapi', |
2751 | + 'gettext', 'locale', 'locale_dir', 'logger', 'logging' |
2752 | + ] |
2753 | |
2754 | def test_AboutAccomplishmentsViewerDialog_members(self): |
2755 | all_members = dir(AboutAccomplishmentsViewerDialog) |
2756 | @@ -33,5 +36,5 @@ |
2757 | public_members.sort() |
2758 | self.assertEqual(self.AboutAccomplishmentsViewerDialog_members, public_members) |
2759 | |
2760 | -if __name__ == '__main__': |
2761 | +if __name__ == '__main__': |
2762 | unittest.main() |
2763 | |
2764 | === modified file 'tests/test_lint.py' |
2765 | --- tests/test_lint.py 2012-09-07 18:19:02 +0000 |
2766 | +++ tests/test_lint.py 2012-11-26 16:03:25 +0000 |
2767 | @@ -2,16 +2,16 @@ |
2768 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
2769 | ### BEGIN LICENSE |
2770 | # Copyright (C) 2012 Jono Bacon <jono@ubuntu.com> |
2771 | -# This program is free software: you can redistribute it and/or modify it |
2772 | -# under the terms of the GNU General Public License version 3, as published |
2773 | +# This program is free software: you can redistribute it and/or modify it |
2774 | +# under the terms of the GNU General Public License version 3, as published |
2775 | # by the Free Software Foundation. |
2776 | -# |
2777 | -# This program is distributed in the hope that it will be useful, but |
2778 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
2779 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2780 | +# |
2781 | +# This program is distributed in the hope that it will be useful, but |
2782 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
2783 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2784 | # PURPOSE. See the GNU General Public License for more details. |
2785 | -# |
2786 | -# You should have received a copy of the GNU General Public License along |
2787 | +# |
2788 | +# You should have received a copy of the GNU General Public License along |
2789 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
2790 | ### END LICENSE |
2791 | |
2792 | @@ -21,17 +21,17 @@ |
2793 | class TestPylint(unittest.TestCase): |
2794 | def test_project_errors_only(self): |
2795 | '''run pylint in error only mode |
2796 | - |
2797 | + |
2798 | your code may well work even with pylint errors |
2799 | but have some unusual code''' |
2800 | return_code = subprocess.call(["pylint", '-E', 'accomplishments_viewer']) |
2801 | # not needed because nosetests displays pylint console output |
2802 | #self.assertEqual(return_code, 0) |
2803 | |
2804 | - # un-comment the following for loads of diagnostics |
2805 | + # un-comment the following for loads of diagnostics |
2806 | #~ def test_project_full_report(self): |
2807 | #~ '''Only for the brave |
2808 | -#~ |
2809 | +#~ |
2810 | #~ you will have to make judgement calls about your code standards |
2811 | #~ that differ from the norm''' |
2812 | #~ return_code = subprocess.call(["pylint", 'accomplishments_viewer']) |
Here's a diff with all whitespace changes removed:
http:// paste.ubuntu. com/1390196/