Merge lp:~francesco-marella/redshift/optimize-indicators into lp:~jonls/redshift/trunk

Proposed by Francesco Marella
Status: Merged
Merged at revision: 125
Proposed branch: lp:~francesco-marella/redshift/optimize-indicators
Merge into: lp:~jonls/redshift/trunk
Diff against target: 351 lines (+67/-203)
5 files modified
configure.ac (+17/-42)
src/gtk-redshift/Makefile.am (+7/-28)
src/gtk-redshift/gtk-redshift (+1/-1)
src/gtk-redshift/rsappindicator.py (+0/-114)
src/gtk-redshift/statusicon.py (+42/-18)
To merge this branch: bzr merge lp:~francesco-marella/redshift/optimize-indicators
Reviewer Review Type Date Requested Status
Jon Lund Steffensen Approve
Review via email: mp+30546@code.launchpad.net

Description of the change

Simplify and optimize indicators code and autoconf scripts.

User, at configure time, chooses to enable or disable the gui. Determine
at runtime whether to use the appindicator or status icon as fallback.

Comments are welcome.

To post a comment you must log in.
Revision history for this message
Jon Lund Steffensen (jonls) wrote :

Thanks, looks good. I'm going to merge this as it is.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2010-06-30 18:10:12 +0000
3+++ configure.ac 2010-07-21 15:24:51 +0000
4@@ -131,50 +131,25 @@
5 ])
6 AM_CONDITIONAL([ENABLE_GNOME_CLOCK], [test "x$enable_gnome_clock" = xyes])
7
8-
9-# Check for GUI
10-# There doesn't seem to be an easy way of detecting the presence
11-# of a python module. For that reason, statusicon is the default GUI.
12-AC_MSG_CHECKING([which GUI to enable])
13+# Check for AppIndicator or GTK+ status icon
14+AC_MSG_CHECKING([whether to enable AppIndicator or GTK status icon])
15 AC_ARG_ENABLE([gui], [AC_HELP_STRING([--enable-gui],
16- [enable GUI (appindicator, statusicon or none)])],
17+ [enable AppIndicator or GTK status icon])],
18 [enable_gui=$enableval],[enable_gui=maybe])
19-
20-# Statusicon GUI
21-AS_IF([test "x$enable_gui" = xstatusicon -o "x$enable_gui" = xmaybe], [
22- AS_IF([test "x$have_python" != xyes], [
23- AS_IF([test "x$enable_gui" = xstatusicon], [
24- AC_MSG_ERROR([status icon script requires Python 2.6])
25- ])
26- enable_gui=maybe
27- ], [
28- enable_gui=statusicon
29- ])
30-])
31-
32-# Appindicator GUI
33-AS_IF([test "x$enable_gui" = xappindicator -o "x$enable_gui" = xmaybe], [
34- AS_IF([test "x$have_python" != xyes], [
35- AS_IF([test "x$enable_gui" = xappindicator], [
36- AC_MSG_ERROR([application indicator script requires Python 2.6])
37- ])
38- enable_gui=maybe
39- ], [
40- enable_gui=appindicator
41- ])
42-])
43-
44-# Fall back to no GUI
45-AS_IF([test "x$enable_gui" != xappindicator -a "x$enable_gui" != xstatusicon], [
46- enable_gui=none
47-])
48-
49-AC_MSG_RESULT([$enable_gui])
50-
51-AM_CONDITIONAL([ENABLE_GUI], [test "x$enable_gui" != xnone])
52-AM_CONDITIONAL([ENABLE_STATUSICON], [test "x$enable_gui" = xstatusicon])
53-AM_CONDITIONAL([ENABLE_APPINDICATOR], [test "x$enable_gui" = xappindicator])
54-
55+AS_IF([test "x$enable_gui" != xno], [
56+ AS_IF([test $have_python = yes], [
57+ AC_MSG_RESULT([yes])
58+ ], [
59+ AC_MSG_RESULT([missing dependencies])
60+ AS_IF([test "x$enable_gui" = xyes], [
61+ AC_MSG_ERROR([appindicator and status icon script requires Python 2.6])
62+ ])
63+ enable_gui=no
64+ ])
65+], [
66+ AC_MSG_RESULT([no])
67+])
68+AM_CONDITIONAL([ENABLE_GUI], [test "x$enable_gui" != xno])
69
70 # Checks for header files.
71 AC_CHECK_HEADERS([locale.h stdint.h stdlib.h string.h unistd.h sys/signal.h])
72
73=== modified file 'src/gtk-redshift/Makefile.am'
74--- src/gtk-redshift/Makefile.am 2010-06-30 18:10:12 +0000
75+++ src/gtk-redshift/Makefile.am 2010-07-21 15:24:51 +0000
76@@ -1,6 +1,5 @@
77
78-if ENABLE_STATUSICON
79-gui_module=statusicon
80+if ENABLE_GUI
81 gtk_redshift_PYTHON = \
82 __init__.py \
83 utils.py \
84@@ -9,32 +8,12 @@
85 defs.py
86 gtk_redshiftdir = $(pythondir)/gtk_redshift
87
88-bin_SCRIPTS = gtk-redshift
89-endif
90-
91-if ENABLE_APPINDICATOR
92-gui_module=rsappindicator
93-gtk_redshift_PYTHON = \
94- __init__.py \
95- utils.py \
96- rsappindicator.py
97-nodist_gtk_redshift_PYTHON = \
98- defs.py
99-gtk_redshiftdir = $(pythondir)/gtk_redshift
100-
101-bin_SCRIPTS = gtk-redshift
102-endif
103-
104-EXTRA_DIST = gtk-redshift.in \
105- defs.py.in
106-
107-CLEANFILES = defs.py \
108- gtk-redshift
109-
110-
111-# Main GUI script
112-gtk-redshift: gtk-redshift.in
113- sed -e "s|\@gui_module\@|$(gui_module)|g" $< > $@
114+dist_bin_SCRIPTS = gtk-redshift
115+endif
116+
117+EXTRA_DIST = defs.py.in
118+
119+CLEANFILES = defs.py
120
121 # Local python definitions
122 defs.py: defs.py.in
123
124=== renamed file 'src/gtk-redshift/gtk-redshift.in' => 'src/gtk-redshift/gtk-redshift'
125--- src/gtk-redshift/gtk-redshift.in 2010-06-06 21:34:49 +0000
126+++ src/gtk-redshift/gtk-redshift 2010-07-21 15:24:51 +0000
127@@ -19,5 +19,5 @@
128
129
130 if __name__ == '__main__':
131- from gtk_redshift.@gui_module@ import run
132+ from gtk_redshift.statusicon import run
133 run()
134
135=== removed file 'src/gtk-redshift/rsappindicator.py'
136--- src/gtk-redshift/rsappindicator.py 2010-06-22 10:46:45 +0000
137+++ src/gtk-redshift/rsappindicator.py 1970-01-01 00:00:00 +0000
138@@ -1,114 +0,0 @@
139-#!/usr/bin/env python
140-# rsappindicator.py -- Application Panel Indicator source
141-# This file is part of Redshift.
142-
143-# Redshift is free software: you can redistribute it and/or modify
144-# it under the terms of the GNU General Public License as published by
145-# the Free Software Foundation, either version 3 of the License, or
146-# (at your option) any later version.
147-
148-# Redshift is distributed in the hope that it will be useful,
149-# but WITHOUT ANY WARRANTY; without even the implied warranty of
150-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
151-# GNU General Public License for more details.
152-
153-# You should have received a copy of the GNU General Public License
154-# along with Redshift. If not, see <http://www.gnu.org/licenses/>.
155-
156-# Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com>
157-
158-
159-import sys, os
160-import subprocess, signal
161-import gettext
162-
163-import pygtk
164-pygtk.require("2.0")
165-
166-import gtk, glib
167-try:
168- import appindicator
169-except ImportError as ie:
170- # No module named appindicator
171- sys.exit(str(ie))
172-
173-import defs
174-import utils
175-
176-
177-def run():
178- # Internationalisation
179- gettext.bindtextdomain('redshift', defs.LOCALEDIR)
180- gettext.textdomain('redshift')
181- _ = gettext.gettext
182-
183- # Start redshift with arguments from the command line
184- args = sys.argv[1:]
185- args.insert(0, os.path.join(defs.BINDIR, 'redshift'))
186- process = subprocess.Popen(args)
187-
188- try:
189- # Create status icon
190- indicator = appindicator.Indicator ("redshift",
191- "redshift",
192- appindicator.CATEGORY_APPLICATION_STATUS)
193- indicator.set_status (appindicator.STATUS_ACTIVE)
194-
195- def toggle_cb(widget, data=None):
196- if indicator.get_icon() == 'redshift':
197- indicator.set_icon('redshift-idle')
198- else:
199- indicator.set_icon('redshift')
200- process.send_signal(signal.SIGUSR1)
201-
202- def autostart_cb(widget, data=None):
203- utils.set_autostart(widget.get_active())
204-
205- def destroy_cb(widget, data=None):
206- gtk.main_quit()
207- return False
208-
209- # Create popup menu
210- status_menu = gtk.Menu()
211-
212- toggle_item = gtk.ImageMenuItem(_('Toggle'))
213- toggle_item.connect('activate', toggle_cb)
214- status_menu.append(toggle_item)
215-
216- autostart_item = gtk.CheckMenuItem(_('Autostart'))
217- try:
218- autostart_item.set_active(utils.get_autostart())
219- except IOError as strerror:
220- print strerror
221- autostart_item.set_property('sensitive', False)
222- else:
223- autostart_item.connect('activate', autostart_cb)
224- finally:
225- status_menu.append(autostart_item)
226-
227- quit_item = gtk.ImageMenuItem(gtk.STOCK_QUIT)
228- quit_item.connect('activate', destroy_cb)
229- status_menu.append(quit_item)
230-
231- status_menu.show_all()
232-
233- # Set the menu
234- indicator.set_menu(status_menu)
235-
236- def child_cb(pid, cond, data=None):
237- sys.exit(-1)
238-
239- # Add watch on child process
240- glib.child_watch_add(process.pid, child_cb)
241-
242- # Run main loop
243- gtk.main()
244-
245- except KeyboardInterrupt:
246- # Ignore user interruption
247- pass
248-
249- finally:
250- # Always terminate redshift
251- process.terminate()
252- process.wait()
253
254=== modified file 'src/gtk-redshift/statusicon.py'
255--- src/gtk-redshift/statusicon.py 2010-06-30 17:55:36 +0000
256+++ src/gtk-redshift/statusicon.py 2010-07-21 15:24:51 +0000
257@@ -1,5 +1,5 @@
258 #!/usr/bin/env python
259-# statusicon.py -- GTK+ status icon source
260+# statusicon.py -- Application panel indicator / GTK+ status icon source
261 # This file is part of Redshift.
262
263 # Redshift is free software: you can redistribute it and/or modify
264@@ -26,6 +26,10 @@
265 pygtk.require("2.0")
266
267 import gtk, glib
268+try:
269+ import appindicator
270+except ImportError:
271+ appindicator = None
272
273 import defs
274 import utils
275@@ -43,23 +47,37 @@
276 process = subprocess.Popen(args)
277
278 try:
279- # Create status icon
280- status_icon = gtk.StatusIcon()
281- status_icon.set_from_icon_name('redshift')
282- status_icon.set_tooltip('Redshift')
283+ if appindicator:
284+ # Create indicator
285+ indicator = appindicator.Indicator ("redshift",
286+ "redshift",
287+ appindicator.CATEGORY_APPLICATION_STATUS)
288+ indicator.set_status (appindicator.STATUS_ACTIVE)
289+ else:
290+ # Create status icon
291+ status_icon = gtk.StatusIcon()
292+ status_icon.set_from_icon_name('redshift')
293+ status_icon.set_tooltip('Redshift')
294
295 def toggle_cb(widget, data=None):
296 process.send_signal(signal.SIGUSR1)
297- if status_icon.get_icon_name() == 'redshift':
298- status_icon.set_from_icon_name('redshift-idle')
299- else:
300- status_icon.set_from_icon_name('redshift')
301+ if appindicator:
302+ if indicator.get_icon() == 'redshift':
303+ indicator.set_icon('redshift-idle')
304+ else:
305+ indicator.set_icon('redshift')
306+ else:
307+ if status_icon.get_icon_name() == 'redshift':
308+ status_icon.set_from_icon_name('redshift-idle')
309+ else:
310+ status_icon.set_from_icon_name('redshift')
311
312 def autostart_cb(widget, data=None):
313 utils.set_autostart(widget.get_active())
314
315 def destroy_cb(widget, data=None):
316- status_icon.set_visible(False)
317+ if not appindicator:
318+ status_icon.set_visible(False)
319 gtk.main_quit()
320 return False
321
322@@ -85,15 +103,21 @@
323 quit_item.connect('activate', destroy_cb)
324 status_menu.append(quit_item)
325
326- def popup_menu_cb(widget, button, time, data=None):
327+ if appindicator:
328 status_menu.show_all()
329- status_menu.popup(None, None, gtk.status_icon_position_menu,
330- button, time, status_icon)
331-
332- # Connect signals for status icon and show
333- status_icon.connect('activate', toggle_cb)
334- status_icon.connect('popup-menu', popup_menu_cb)
335- status_icon.set_visible(True)
336+
337+ # Set the menu
338+ indicator.set_menu(status_menu)
339+ else:
340+ def popup_menu_cb(widget, button, time, data=None):
341+ status_menu.show_all()
342+ status_menu.popup(None, None, gtk.status_icon_position_menu,
343+ button, time, status_icon)
344+
345+ # Connect signals for status icon and show
346+ status_icon.connect('activate', toggle_cb)
347+ status_icon.connect('popup-menu', popup_menu_cb)
348+ status_icon.set_visible(True)
349
350 def child_cb(pid, cond, data=None):
351 sys.exit(-1)

Subscribers

People subscribed via source and target branches