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
1=== modified file 'txaws/client/gui/gtk.py'
2--- txaws/client/gui/gtk.py 2012-01-23 01:26:39 +0000
3+++ txaws/client/gui/gtk.py 2012-03-24 15:42:18 +0000
4@@ -7,6 +7,13 @@
5 import gnomekeyring
6 import gobject
7 import gtk
8+import sys
9+
10+try:
11+ import appindicator
12+ have_appindicator = True
13+except:
14+ have_appindicator = False
15
16 # DO NOT IMPORT twisted.internet, or things that import
17 # twisted.internet.
18@@ -14,19 +21,20 @@
19
20 from txaws.credentials import AWSCredentials
21
22-
23 __all__ = ["main"]
24
25-
26-class AWSStatusIcon(gtk.StatusIcon):
27- """A status icon shown when instances are running."""
28-
29+class AWSStatusIndicator(object):
30 def __init__(self, reactor):
31- gtk.StatusIcon.__init__(self)
32- self.set_from_stock(gtk.STOCK_NETWORK)
33- self.set_visible(True)
34+ # Even though we have appindicator, we may still need the status
35+ # icon because we're on something that does not show them.
36+ self.status_icon = gtk.StatusIcon()
37+ self.status_icon.set_from_stock(gtk.STOCK_NETWORK)
38+ self.status_icon.set_visible(True)
39+ self.status_icon.connect("activate", self.on_activate)
40+ if have_appindicator:
41+ self.indicator = appindicator.Indicator("aws-status","stock_weather-cloudy",appindicator.CATEGORY_OTHER)
42+ self.indicator.set_status(appindicator.STATUS_PASSIVE)
43 self.reactor = reactor
44- self.connect("activate", self.on_activate)
45 self.probing = False
46 # Nested import because otherwise we get "reactor already installed".
47 self.password_dialog = None
48@@ -42,15 +50,21 @@
49 <ui>
50 <menubar name="Menubar">
51 <menu action="Menu">
52+ <menuitem action="Refresh"/>
53 <menuitem action="Stop instances"/>
54+ <menuitem action="Quit"/>
55 </menu>
56 </menubar>
57 </ui>
58 """
59 actions = [
60 ("Menu", None, "Menu"),
61+ ("Refresh", gtk.STOCK_REFRESH, "_Refresh...", None,
62+ "Refresh", self.on_activate),
63 ("Stop instances", gtk.STOCK_STOP, "_Stop instances...", None,
64 "Stop instances", self.on_stop_instances),
65+ ("Quit", gtk.STOCK_QUIT, "_Quit...", None,
66+ "Quit", self.on_quit),
67 ]
68 ag = gtk.ActionGroup("Actions")
69 ag.add_actions(actions)
70@@ -59,7 +73,12 @@
71 self.manager.add_ui_from_string(menu)
72 self.menu = self.manager.get_widget(
73 "/Menubar/Menu/Stop instances").props.parent
74- self.connect("popup-menu", self.on_popup_menu)
75+ self.status_icon.connect("popup-menu", self.on_popup_menu)
76+ if have_appindicator:
77+ self.indicator.set_menu(self.menu)
78+ # kickstart things
79+ self.on_activate(None)
80+ self.queue_check()
81
82 def set_region(self, creds):
83 from txaws.service import AWSServiceRegion
84@@ -127,6 +146,9 @@
85 deferred = self.client.describe_instances()
86 deferred.addCallbacks(self.showhide, self.describe_error)
87
88+ def on_quit(self, data):
89+ self.reactor.stop()
90+
91 def on_popup_menu(self, status, button, time):
92 self.menu.popup(None, None, None, button, time)
93
94@@ -161,8 +183,22 @@
95 for instance in reservation:
96 if instance.instance_state == "running":
97 active += 1
98- self.set_tooltip("AWS Status - %d instances" % active)
99- self.set_visible(active != 0)
100+ if active == 0:
101+ self.status_icon.set_visible(False)
102+ if have_appindicator:
103+ self.indicator.set_label("")
104+ self.indicator.set_status(appindicator.STATUS_PASSIVE)
105+ else:
106+ if active == 1:
107+ word = "instance"
108+ else:
109+ word = "instances"
110+ self.status_icon.set_tooltip(
111+ "AWS Status - %d %s" % (active,word))
112+ self.status_icon.set_visible(True)
113+ if have_appindicator:
114+ self.indicator.set_label("%d %s" % (active,word), "10 instances")
115+ self.indicator.set_status(appindicator.STATUS_ACTIVE)
116 self.queue_check()
117
118 def shutdown_instances(self, reservation):
119@@ -172,7 +208,7 @@
120
121 def queue_check(self):
122 self.probing = False
123- self.reactor.callLater(60, self.on_activate, None)
124+ self.reactor.callLater(29, self.on_activate, None)
125
126 def show_error(self, error):
127 # debugging output for now.
128@@ -210,7 +246,7 @@
129 gtk2reactor.install()
130 from twisted.internet import reactor
131 try:
132- AWSStatusIcon(reactor)
133+ AWSStatusIndicator(reactor)
134 gobject.set_application_name("aws-status")
135 reactor.run()
136 except ValueError:

Subscribers

People subscribed via source and target branches

to all changes: