Merge lp:~clint-fewbar/txaws/make-aws-status-indicator into lp:txaws

Proposed by Clint Byrum
Status: Merged
Approved by: Duncan McGreggor
Approved revision: 141
Merged at revision: 140
Proposed branch: lp:~clint-fewbar/txaws/make-aws-status-indicator
Merge into: lp:txaws
Diff against target: 136 lines (+50/-14)
1 file modified
txaws/client/gui/gtk.py (+50/-14)
To merge this branch: bzr merge lp:~clint-fewbar/txaws/make-aws-status-indicator
Reviewer Review Type Date Requested Status
Duncan McGreggor Approve
Review via email: mp+99175@code.launchpad.net

Description of the change

Makes aws-status create an app indicator. Keeps the GtkStatusIcon around for non-unity environments, but I don't have any of those to test on, so a smoke test of that would be appreciated. That said, the target of this tool is Ubuntu users so I'm not sure how critical that is.

To post a comment you must log in.
Revision history for this message
Clint Byrum (clint-fewbar) wrote :

This is already shipping in Ubuntu 12.04. Can somebody please review it? I'd like to make some more improvements but don't want to get too far off in the weeds!

Revision history for this message
Duncan McGreggor (oubiwann) wrote :

Sorry, man -- I took a look at this before, and meant to say: +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'txaws/client/gui/gtk.py'
--- txaws/client/gui/gtk.py 2012-01-23 01:26:39 +0000
+++ txaws/client/gui/gtk.py 2012-03-24 15:42:18 +0000
@@ -7,6 +7,13 @@
7import gnomekeyring7import gnomekeyring
8import gobject8import gobject
9import gtk9import gtk
10import sys
11
12try:
13 import appindicator
14 have_appindicator = True
15except:
16 have_appindicator = False
1017
11# DO NOT IMPORT twisted.internet, or things that import18# DO NOT IMPORT twisted.internet, or things that import
12# twisted.internet.19# twisted.internet.
@@ -14,19 +21,20 @@
1421
15from txaws.credentials import AWSCredentials22from txaws.credentials import AWSCredentials
1623
17
18__all__ = ["main"]24__all__ = ["main"]
1925
2026class AWSStatusIndicator(object):
21class AWSStatusIcon(gtk.StatusIcon):
22 """A status icon shown when instances are running."""
23
24 def __init__(self, reactor):27 def __init__(self, reactor):
25 gtk.StatusIcon.__init__(self)28 # Even though we have appindicator, we may still need the status
26 self.set_from_stock(gtk.STOCK_NETWORK)29 # icon because we're on something that does not show them.
27 self.set_visible(True)30 self.status_icon = gtk.StatusIcon()
31 self.status_icon.set_from_stock(gtk.STOCK_NETWORK)
32 self.status_icon.set_visible(True)
33 self.status_icon.connect("activate", self.on_activate)
34 if have_appindicator:
35 self.indicator = appindicator.Indicator("aws-status","stock_weather-cloudy",appindicator.CATEGORY_OTHER)
36 self.indicator.set_status(appindicator.STATUS_PASSIVE)
28 self.reactor = reactor37 self.reactor = reactor
29 self.connect("activate", self.on_activate)
30 self.probing = False38 self.probing = False
31 # Nested import because otherwise we get "reactor already installed".39 # Nested import because otherwise we get "reactor already installed".
32 self.password_dialog = None40 self.password_dialog = None
@@ -42,15 +50,21 @@
42 <ui>50 <ui>
43 <menubar name="Menubar">51 <menubar name="Menubar">
44 <menu action="Menu">52 <menu action="Menu">
53 <menuitem action="Refresh"/>
45 <menuitem action="Stop instances"/>54 <menuitem action="Stop instances"/>
55 <menuitem action="Quit"/>
46 </menu>56 </menu>
47 </menubar>57 </menubar>
48 </ui>58 </ui>
49 """59 """
50 actions = [60 actions = [
51 ("Menu", None, "Menu"),61 ("Menu", None, "Menu"),
62 ("Refresh", gtk.STOCK_REFRESH, "_Refresh...", None,
63 "Refresh", self.on_activate),
52 ("Stop instances", gtk.STOCK_STOP, "_Stop instances...", None,64 ("Stop instances", gtk.STOCK_STOP, "_Stop instances...", None,
53 "Stop instances", self.on_stop_instances),65 "Stop instances", self.on_stop_instances),
66 ("Quit", gtk.STOCK_QUIT, "_Quit...", None,
67 "Quit", self.on_quit),
54 ]68 ]
55 ag = gtk.ActionGroup("Actions")69 ag = gtk.ActionGroup("Actions")
56 ag.add_actions(actions)70 ag.add_actions(actions)
@@ -59,7 +73,12 @@
59 self.manager.add_ui_from_string(menu)73 self.manager.add_ui_from_string(menu)
60 self.menu = self.manager.get_widget(74 self.menu = self.manager.get_widget(
61 "/Menubar/Menu/Stop instances").props.parent75 "/Menubar/Menu/Stop instances").props.parent
62 self.connect("popup-menu", self.on_popup_menu)76 self.status_icon.connect("popup-menu", self.on_popup_menu)
77 if have_appindicator:
78 self.indicator.set_menu(self.menu)
79 # kickstart things
80 self.on_activate(None)
81 self.queue_check()
6382
64 def set_region(self, creds):83 def set_region(self, creds):
65 from txaws.service import AWSServiceRegion84 from txaws.service import AWSServiceRegion
@@ -127,6 +146,9 @@
127 deferred = self.client.describe_instances()146 deferred = self.client.describe_instances()
128 deferred.addCallbacks(self.showhide, self.describe_error)147 deferred.addCallbacks(self.showhide, self.describe_error)
129148
149 def on_quit(self, data):
150 self.reactor.stop()
151
130 def on_popup_menu(self, status, button, time):152 def on_popup_menu(self, status, button, time):
131 self.menu.popup(None, None, None, button, time)153 self.menu.popup(None, None, None, button, time)
132154
@@ -161,8 +183,22 @@
161 for instance in reservation:183 for instance in reservation:
162 if instance.instance_state == "running":184 if instance.instance_state == "running":
163 active += 1185 active += 1
164 self.set_tooltip("AWS Status - %d instances" % active)186 if active == 0:
165 self.set_visible(active != 0)187 self.status_icon.set_visible(False)
188 if have_appindicator:
189 self.indicator.set_label("")
190 self.indicator.set_status(appindicator.STATUS_PASSIVE)
191 else:
192 if active == 1:
193 word = "instance"
194 else:
195 word = "instances"
196 self.status_icon.set_tooltip(
197 "AWS Status - %d %s" % (active,word))
198 self.status_icon.set_visible(True)
199 if have_appindicator:
200 self.indicator.set_label("%d %s" % (active,word), "10 instances")
201 self.indicator.set_status(appindicator.STATUS_ACTIVE)
166 self.queue_check()202 self.queue_check()
167203
168 def shutdown_instances(self, reservation):204 def shutdown_instances(self, reservation):
@@ -172,7 +208,7 @@
172208
173 def queue_check(self):209 def queue_check(self):
174 self.probing = False210 self.probing = False
175 self.reactor.callLater(60, self.on_activate, None)211 self.reactor.callLater(29, self.on_activate, None)
176212
177 def show_error(self, error):213 def show_error(self, error):
178 # debugging output for now.214 # debugging output for now.
@@ -210,7 +246,7 @@
210 gtk2reactor.install()246 gtk2reactor.install()
211 from twisted.internet import reactor247 from twisted.internet import reactor
212 try:248 try:
213 AWSStatusIcon(reactor)249 AWSStatusIndicator(reactor)
214 gobject.set_application_name("aws-status")250 gobject.set_application_name("aws-status")
215 reactor.run()251 reactor.run()
216 except ValueError:252 except ValueError:

Subscribers

People subscribed via source and target branches

to all changes: