Merge lp:~izidor/gtg/bug1074140 into lp:~gtg/gtg/old-trunk
- bug1074140
- Merge into old-trunk
Proposed by
Izidor Matušov
Status: | Merged |
---|---|
Merged at revision: | 1239 |
Proposed branch: | lp:~izidor/gtg/bug1074140 |
Merge into: | lp:~gtg/gtg/old-trunk |
Diff against target: |
346 lines (+123/-99) 1 file modified
GTG/plugins/notification_area/notification_area.py (+123/-99) |
To merge this branch: | bzr merge lp:~izidor/gtg/bug1074140 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Bertrand Rousseau (community) | Approve | ||
Review via email: mp+132654@code.launchpad.net |
Commit message
Description of the change
A patch to run notification area plugin even for systems without appindicator, e.g. Archlinux's XFCE4.
To post a comment you must log in.
Revision history for this message
Bertrand Rousseau (bertrand-rousseau) wrote : | # |
review:
Needs Information
Revision history for this message
Bertrand Rousseau (bertrand-rousseau) wrote : | # |
following discussion on IRC, it appears to have been tested on unity/xfce, so I approve
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === removed directory 'GTG/plugins/notification_area/data' | |||
2 | === removed directory 'GTG/plugins/notification_area/data/icons' | |||
3 | === removed directory 'GTG/plugins/notification_area/data/icons/hicolor' | |||
4 | === removed directory 'GTG/plugins/notification_area/data/icons/hicolor/22x22' | |||
5 | === removed directory 'GTG/plugins/notification_area/data/icons/hicolor/22x22/apps' | |||
6 | === modified file 'GTG/plugins/notification_area/notification_area.py' | |||
7 | --- GTG/plugins/notification_area/notification_area.py 2012-07-18 12:09:41 +0000 | |||
8 | +++ GTG/plugins/notification_area/notification_area.py 2012-11-02 07:54:58 +0000 | |||
9 | @@ -24,11 +24,109 @@ | |||
10 | 24 | pass | 24 | pass |
11 | 25 | 25 | ||
12 | 26 | from GTG import _ | 26 | from GTG import _ |
13 | 27 | from GTG import PLUGIN_DIR | ||
14 | 28 | from GTG.tools.borg import Borg | 27 | from GTG.tools.borg import Borg |
15 | 29 | from GTG.tools.dates import Date | 28 | from GTG.tools.dates import Date |
16 | 30 | 29 | ||
17 | 31 | 30 | ||
18 | 31 | class TheIndicator(Borg): | ||
19 | 32 | """ | ||
20 | 33 | Application indicator can be instantiated only once. The | ||
21 | 34 | plugin api, when toggling the activation state of a plugin, | ||
22 | 35 | instantiates different objects from the plugin class. Therefore, | ||
23 | 36 | we need to keep a reference to the indicator object. This class | ||
24 | 37 | does that. | ||
25 | 38 | """ | ||
26 | 39 | |||
27 | 40 | def __init__(self): | ||
28 | 41 | super(TheIndicator, self).__init__() | ||
29 | 42 | if not hasattr(self, "_indicator"): | ||
30 | 43 | try: | ||
31 | 44 | self._indicator = appindicator.Indicator( \ | ||
32 | 45 | "gtg", | ||
33 | 46 | "indicator-messages", | ||
34 | 47 | appindicator.CATEGORY_APPLICATION_STATUS) | ||
35 | 48 | except: | ||
36 | 49 | self._indicator = None | ||
37 | 50 | |||
38 | 51 | def get_indicator(self): | ||
39 | 52 | return self._indicator | ||
40 | 53 | |||
41 | 54 | |||
42 | 55 | class IconIndicator: | ||
43 | 56 | """ | ||
44 | 57 | A common interface to an app indicator and a status icon | ||
45 | 58 | """ | ||
46 | 59 | |||
47 | 60 | NORMAL_ICON = "gtg" | ||
48 | 61 | ATTENTION_ICON = "gtg_need_attention" | ||
49 | 62 | |||
50 | 63 | def __init__(self): | ||
51 | 64 | self._indicator = TheIndicator().get_indicator() | ||
52 | 65 | self._icon = None | ||
53 | 66 | self._menu = None | ||
54 | 67 | self._attention = False | ||
55 | 68 | |||
56 | 69 | def activate(self, leftbtn_callback, menu): | ||
57 | 70 | """ Setup the icon / the indicator """ | ||
58 | 71 | |||
59 | 72 | self._menu = menu | ||
60 | 73 | |||
61 | 74 | if self._indicator: | ||
62 | 75 | self._indicator.set_icon("gtg-panel") | ||
63 | 76 | self._indicator.set_attention_icon(self.ATTENTION_ICON) | ||
64 | 77 | self._indicator.set_menu(menu) | ||
65 | 78 | self._indicator.set_status(appindicator.STATUS_ACTIVE) | ||
66 | 79 | else: | ||
67 | 80 | self._icon = gtk.StatusIcon() | ||
68 | 81 | self._icon.set_from_icon_name(self.NORMAL_ICON) | ||
69 | 82 | self._icon.set_tooltip("Getting Things GNOME!") | ||
70 | 83 | self._icon.set_visible(True) | ||
71 | 84 | self._icon.connect('activate', leftbtn_callback) | ||
72 | 85 | self._icon.connect('popup-menu', self._on_icon_popup) | ||
73 | 86 | |||
74 | 87 | def deactivate(self): | ||
75 | 88 | """ Hide the icon """ | ||
76 | 89 | if self._indicator: | ||
77 | 90 | self._indicator.set_status(appindicator.STATUS_PASSIVE) | ||
78 | 91 | else: | ||
79 | 92 | self._icon.set_visible(False) | ||
80 | 93 | |||
81 | 94 | def update_menu(self): | ||
82 | 95 | """ Force indicator to update menu """ | ||
83 | 96 | if self._indicator: | ||
84 | 97 | self._indicator.set_menu(self._menu) | ||
85 | 98 | |||
86 | 99 | def set_attention(self, attention): | ||
87 | 100 | """ Show a special icon when the indicator needs attention """ | ||
88 | 101 | # Change icon only when the attention change | ||
89 | 102 | if self._attention == attention: | ||
90 | 103 | return | ||
91 | 104 | |||
92 | 105 | if self._indicator: | ||
93 | 106 | if attention: | ||
94 | 107 | status = appindicator.STATUS_ATTENTION | ||
95 | 108 | else: | ||
96 | 109 | status = appindicator.STATUS_ACTIVE | ||
97 | 110 | |||
98 | 111 | self._indicator.set_status(status) | ||
99 | 112 | else: | ||
100 | 113 | if attention: | ||
101 | 114 | icon = self.ATTENTION_ICON | ||
102 | 115 | else: | ||
103 | 116 | icon = self.NORMAL_ICON | ||
104 | 117 | |||
105 | 118 | self._icon.set_from_icon_name(icon) | ||
106 | 119 | |||
107 | 120 | self._attention = attention | ||
108 | 121 | |||
109 | 122 | def _on_icon_popup(self, icon, button, timestamp): | ||
110 | 123 | """ Show the menu on right click on the icon """ | ||
111 | 124 | if not self._indicator: | ||
112 | 125 | self._menu.popup(None, None, gtk.status_icon_position_menu, | ||
113 | 126 | button, timestamp, icon) | ||
114 | 127 | |||
115 | 128 | |||
116 | 129 | |||
117 | 32 | def _due_within(task, danger_zone): | 130 | def _due_within(task, danger_zone): |
118 | 33 | """ | 131 | """ |
119 | 34 | Determine if a task is the danger zone. | 132 | Determine if a task is the danger zone. |
120 | @@ -55,16 +153,10 @@ | |||
121 | 55 | than time span (in days) defined by danger_zone. | 153 | than time span (in days) defined by danger_zone. |
122 | 56 | """ | 154 | """ |
123 | 57 | 155 | ||
124 | 58 | STATUS = {'normal': appindicator.STATUS_ACTIVE, | ||
125 | 59 | 'high': appindicator.STATUS_ATTENTION} | ||
126 | 60 | |||
127 | 61 | ICON = {'normal': 'gtg-panel', | ||
128 | 62 | 'high': 'gtg_need_attention'} | ||
129 | 63 | |||
130 | 64 | def __init__(self, danger_zone, indicator, tree, req): | 156 | def __init__(self, danger_zone, indicator, tree, req): |
131 | 65 | self.__tree = tree | 157 | self.__tree = tree |
132 | 66 | self.__req = req | 158 | self.__req = req |
134 | 67 | self.__indicator = indicator | 159 | self._indicator = indicator |
135 | 68 | self.danger_zone = danger_zone | 160 | self.danger_zone = danger_zone |
136 | 69 | 161 | ||
137 | 70 | # Setup list of tasks in danger zone | 162 | # Setup list of tasks in danger zone |
138 | @@ -76,27 +168,13 @@ | |||
139 | 76 | self.tasks_danger.append(tid) | 168 | self.tasks_danger.append(tid) |
140 | 77 | 169 | ||
141 | 78 | # Set initial status | 170 | # Set initial status |
159 | 79 | self.__update_indicator(self.level()) | 171 | self._update_indicator() |
160 | 80 | 172 | ||
161 | 81 | def level(self): | 173 | def _update_indicator(self): |
162 | 82 | """ Two states only: attention is either needed or not """ | 174 | """ Set the proper icon for the indicator """ |
163 | 83 | return 'high' if len(self.tasks_danger)>0 else 'normal' | 175 | self._indicator.set_attention(len(self.tasks_danger) > 0) |
147 | 84 | |||
148 | 85 | def __update_indicator(self, new, old=None): | ||
149 | 86 | """ Reset indicator status or update upon change in status """ | ||
150 | 87 | if old is None or not old == new: | ||
151 | 88 | try: | ||
152 | 89 | # This works if __indicator implements the appindicator api | ||
153 | 90 | self.__indicator.set_status(self.STATUS[new]) | ||
154 | 91 | except AttributeError: | ||
155 | 92 | # If we passed a status icon instead try this | ||
156 | 93 | self.__indicator.set_from_icon_name(self.ICON[new]) | ||
157 | 94 | except: | ||
158 | 95 | raise | ||
164 | 96 | 176 | ||
165 | 97 | def update_on_task_modified(self, tid): | 177 | def update_on_task_modified(self, tid): |
166 | 98 | # Store current attention level | ||
167 | 99 | old_lev = self.level() | ||
168 | 100 | task = self.__req.get_task(tid) | 178 | task = self.__req.get_task(tid) |
169 | 101 | if tid in self.tasks_danger: | 179 | if tid in self.tasks_danger: |
170 | 102 | if not _due_within(task, self.danger_zone): | 180 | if not _due_within(task, self.danger_zone): |
171 | @@ -104,19 +182,14 @@ | |||
172 | 104 | else: | 182 | else: |
173 | 105 | if _due_within(task, self.danger_zone): | 183 | if _due_within(task, self.danger_zone): |
174 | 106 | self.tasks_danger.append(tid) | 184 | self.tasks_danger.append(tid) |
178 | 107 | 185 | ||
179 | 108 | # Update icon only if attention level has changed | 186 | self._update_indicator() |
177 | 109 | self.__update_indicator(self.level(), old_lev) | ||
180 | 110 | 187 | ||
181 | 111 | def update_on_task_deleted(self, tid): | 188 | def update_on_task_deleted(self, tid): |
182 | 112 | # Store current attention level | ||
183 | 113 | old_lev = self.level() | ||
184 | 114 | |||
185 | 115 | if tid in self.tasks_danger: | 189 | if tid in self.tasks_danger: |
186 | 116 | self.tasks_danger.remove(tid) | 190 | self.tasks_danger.remove(tid) |
187 | 117 | 191 | ||
190 | 118 | # Update icon only if attention level has changed | 192 | self._update_indicator() |
189 | 119 | self.__update_indicator(self.level(), old_lev) | ||
191 | 120 | 193 | ||
192 | 121 | 194 | ||
193 | 122 | class NotificationArea: | 195 | class NotificationArea: |
194 | @@ -131,31 +204,9 @@ | |||
195 | 131 | MAX_TITLE_LEN = 30 | 204 | MAX_TITLE_LEN = 30 |
196 | 132 | MAX_ITEMS = 10 | 205 | MAX_ITEMS = 10 |
197 | 133 | 206 | ||
198 | 134 | class TheIndicator(Borg): | ||
199 | 135 | """ | ||
200 | 136 | Application indicator can be instantiated only once. The | ||
201 | 137 | plugin api, when toggling the activation state of a plugin, | ||
202 | 138 | instantiates different objects from the plugin class. Therefore, | ||
203 | 139 | we need to keep a reference to the indicator object. This class | ||
204 | 140 | does that. | ||
205 | 141 | """ | ||
206 | 142 | |||
207 | 143 | def __init__(self): | ||
208 | 144 | super(NotificationArea.TheIndicator, self).__init__() | ||
209 | 145 | if not hasattr(self, "_indicator"): | ||
210 | 146 | try: | ||
211 | 147 | self._indicator = appindicator.Indicator( \ | ||
212 | 148 | "gtg", | ||
213 | 149 | "indicator-messages", | ||
214 | 150 | appindicator.CATEGORY_APPLICATION_STATUS) | ||
215 | 151 | except: | ||
216 | 152 | self._indicator = None | ||
217 | 153 | |||
218 | 154 | def get_indicator(self): | ||
219 | 155 | return self._indicator | ||
220 | 156 | 207 | ||
221 | 157 | def __init__(self): | 208 | def __init__(self): |
223 | 158 | self.__indicator = NotificationArea.TheIndicator().get_indicator() | 209 | self._indicator = IconIndicator() |
224 | 159 | self.__browser_handler = None | 210 | self.__browser_handler = None |
225 | 160 | self.__liblarch_callbacks = [] | 211 | self.__liblarch_callbacks = [] |
226 | 161 | 212 | ||
227 | @@ -203,10 +254,7 @@ | |||
228 | 203 | 254 | ||
229 | 204 | def deactivate(self, plugin_api): | 255 | def deactivate(self, plugin_api): |
230 | 205 | """ Set everything back to normal """ | 256 | """ Set everything back to normal """ |
235 | 206 | if self.__indicator: | 257 | self._indicator.deactivate() |
232 | 207 | self.__indicator.set_status(appindicator.STATUS_PASSIVE) | ||
233 | 208 | else: | ||
234 | 209 | self.status_icon.set_visible(False) | ||
236 | 210 | 258 | ||
237 | 211 | # Allow to close browser after deactivation | 259 | # Allow to close browser after deactivation |
238 | 212 | self.__set_browser_close_callback(None) | 260 | self.__set_browser_close_callback(None) |
239 | @@ -224,13 +272,13 @@ | |||
240 | 224 | def __init_gtk(self): | 272 | def __init_gtk(self): |
241 | 225 | browser = self.__view_manager.get_browser() | 273 | browser = self.__view_manager.get_browser() |
242 | 226 | 274 | ||
244 | 227 | self.__menu = gtk.Menu() | 275 | menu = gtk.Menu() |
245 | 228 | 276 | ||
246 | 229 | #add "new task" | 277 | #add "new task" |
247 | 230 | menuItem = gtk.ImageMenuItem(gtk.STOCK_ADD) | 278 | menuItem = gtk.ImageMenuItem(gtk.STOCK_ADD) |
248 | 231 | menuItem.get_children()[0].set_label(_('Add _New Task')) | 279 | menuItem.get_children()[0].set_label(_('Add _New Task')) |
249 | 232 | menuItem.connect('activate', self.__open_task) | 280 | menuItem.connect('activate', self.__open_task) |
251 | 233 | self.__menu.append(menuItem) | 281 | menu.append(menuItem) |
252 | 234 | 282 | ||
253 | 235 | #view in main window checkbox | 283 | #view in main window checkbox |
254 | 236 | view_browser_checkbox = gtk.CheckMenuItem(_("_View Main Window")) | 284 | view_browser_checkbox = gtk.CheckMenuItem(_("_View Main Window")) |
255 | @@ -239,48 +287,29 @@ | |||
256 | 239 | self.__toggle_browser) | 287 | self.__toggle_browser) |
257 | 240 | browser.connect('visibility-toggled', self.__on_browser_toggled, | 288 | browser.connect('visibility-toggled', self.__on_browser_toggled, |
258 | 241 | view_browser_checkbox) | 289 | view_browser_checkbox) |
260 | 242 | self.__menu.append(view_browser_checkbox) | 290 | menu.append(view_browser_checkbox) |
261 | 243 | self.checkbox = view_browser_checkbox | 291 | self.checkbox = view_browser_checkbox |
262 | 244 | 292 | ||
263 | 245 | #separator (it's intended to be after show_all) | 293 | #separator (it's intended to be after show_all) |
264 | 246 | # separator should be shown only when having tasks | 294 | # separator should be shown only when having tasks |
265 | 247 | self.__task_separator = gtk.SeparatorMenuItem() | 295 | self.__task_separator = gtk.SeparatorMenuItem() |
268 | 248 | self.__menu.append(self.__task_separator) | 296 | menu.append(self.__task_separator) |
269 | 249 | self.__menu_top_length = len(self.__menu) | 297 | menu_top_length = len(menu) |
270 | 250 | 298 | ||
272 | 251 | self.__menu.append(gtk.SeparatorMenuItem()) | 299 | menu.append(gtk.SeparatorMenuItem()) |
273 | 252 | 300 | ||
274 | 253 | #quit item | 301 | #quit item |
275 | 254 | menuItem = gtk.ImageMenuItem(gtk.STOCK_QUIT) | 302 | menuItem = gtk.ImageMenuItem(gtk.STOCK_QUIT) |
276 | 255 | menuItem.connect('activate', self.__view_manager.close_browser) | 303 | menuItem.connect('activate', self.__view_manager.close_browser) |
278 | 256 | self.__menu.append(menuItem) | 304 | menu.append(menuItem) |
279 | 257 | 305 | ||
281 | 258 | self.__menu.show_all() | 306 | menu.show_all() |
282 | 259 | self.__task_separator.hide() | 307 | self.__task_separator.hide() |
283 | 260 | 308 | ||
284 | 261 | self.__tasks_menu = SortedLimitedMenu(self.MAX_ITEMS, | 309 | self.__tasks_menu = SortedLimitedMenu(self.MAX_ITEMS, |
307 | 262 | self.__menu, self.__menu_top_length) | 310 | menu, menu_top_length) |
308 | 263 | 311 | ||
309 | 264 | # Update the icon theme | 312 | self._indicator.activate(self.__toggle_browser, menu) |
288 | 265 | icon_theme = os.path.join('notification_area', 'data', 'icons') | ||
289 | 266 | abs_theme_path = os.path.join(PLUGIN_DIR[0], icon_theme) | ||
290 | 267 | theme = gtk.icon_theme_get_default() | ||
291 | 268 | theme.append_search_path(abs_theme_path) | ||
292 | 269 | |||
293 | 270 | if self.__indicator: | ||
294 | 271 | self.__indicator.set_icon_theme_path(abs_theme_path) | ||
295 | 272 | self.__indicator.set_icon("gtg-panel") | ||
296 | 273 | self.__indicator.set_attention_icon("gtg_need_attention") | ||
297 | 274 | self.__indicator.set_menu(self.__menu) | ||
298 | 275 | self.__indicator.set_status(appindicator.STATUS_ACTIVE) | ||
299 | 276 | else: | ||
300 | 277 | self.status_icon = gtk.StatusIcon() | ||
301 | 278 | self.status_icon.set_from_icon_name("gtg-panel") | ||
302 | 279 | self.status_icon.set_tooltip("Getting Things Gnome!") | ||
303 | 280 | self.status_icon.set_visible(True) | ||
304 | 281 | self.status_icon.connect('activate', self.__toggle_browser) | ||
305 | 282 | self.status_icon.connect('popup-menu', | ||
306 | 283 | self.__on_icon_popup, self.__menu) | ||
310 | 284 | 313 | ||
311 | 285 | def __init_attention(self): | 314 | def __init_attention(self): |
312 | 286 | # Use two different viewtree for attention and menu | 315 | # Use two different viewtree for attention and menu |
313 | @@ -290,7 +319,7 @@ | |||
314 | 290 | if self.preferences['danger_zone'] > 0: | 319 | if self.preferences['danger_zone'] > 0: |
315 | 291 | self.__attention = _Attention( \ | 320 | self.__attention = _Attention( \ |
316 | 292 | self.preferences['danger_zone'], | 321 | self.preferences['danger_zone'], |
318 | 293 | self.__indicator if self.__indicator else self.status_icon, | 322 | self._indicator, |
319 | 294 | self.__tree_att, | 323 | self.__tree_att, |
320 | 295 | self.__requester) | 324 | self.__requester) |
321 | 296 | else: | 325 | else: |
322 | @@ -340,8 +369,7 @@ | |||
323 | 340 | menu_item.connect('activate', self.__open_task, tid) | 369 | menu_item.connect('activate', self.__open_task, tid) |
324 | 341 | self.__tasks_menu.add(tid, (task.get_due_date(), title), menu_item) | 370 | self.__tasks_menu.add(tid, (task.get_due_date(), title), menu_item) |
325 | 342 | 371 | ||
328 | 343 | if self.__indicator: | 372 | self._indicator.update_menu() |
327 | 344 | self.__indicator.set_menu(self.__menu) | ||
329 | 345 | 373 | ||
330 | 346 | def __on_task_deleted_att(self, tid, path): | 374 | def __on_task_deleted_att(self, tid, path): |
331 | 347 | # Update icon on deletion | 375 | # Update icon on deletion |
332 | @@ -362,10 +390,6 @@ | |||
333 | 362 | short_title = short_title.strip() + "..." | 390 | short_title = short_title.strip() + "..." |
334 | 363 | return short_title | 391 | return short_title |
335 | 364 | 392 | ||
336 | 365 | def __on_icon_popup(self, icon, button, timestamp, menu=None): | ||
337 | 366 | if not self.__indicator: | ||
338 | 367 | menu.popup(None, None, gtk.status_icon_position_menu, \ | ||
339 | 368 | button, timestamp, icon) | ||
340 | 369 | 393 | ||
341 | 370 | ### Preferences methods ####################################################### | 394 | ### Preferences methods ####################################################### |
342 | 371 | def preferences_load(self): | 395 | def preferences_load(self): |
343 | 372 | 396 | ||
344 | === renamed file 'GTG/plugins/notification_area/data/icons/hicolor/22x22/apps/gtg_need_attention.png' => 'data/icons/hicolor/22x22/apps/gtg_need_attention.png' | |||
345 | === renamed directory 'GTG/plugins/notification_area/data/icons/ubuntu-mono-dark' => 'data/icons/ubuntu-mono-dark' | |||
346 | === renamed directory 'GTG/plugins/notification_area/data/icons/ubuntu-mono-light' => 'data/icons/ubuntu-mono-light' |
I ran your code under Ubuntu 12.10/GNOME Shell, and could see the notification icon when activating the notification area plugin. So everything ok from that PoV.
Did you test it against Unity?