From d7f66c09c1c3163bbcd312542e3ad7f7a46fb197 Mon Sep 17 00:00:00 2001 From: Francesco Marella Date: Fri, 4 Jun 2010 12:22:06 +0200 Subject: Implement the application panel indicator for redshift --- src/gtk-redshift/rsappindicator.py | 95 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/gtk-redshift/rsappindicator.py (limited to 'src/gtk-redshift') diff --git a/src/gtk-redshift/rsappindicator.py b/src/gtk-redshift/rsappindicator.py new file mode 100644 index 0000000..c681d89 --- /dev/null +++ b/src/gtk-redshift/rsappindicator.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python +# rsappindicator.py -- Application Panel Indicator source +# This file is part of Redshift. + +# Redshift is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# Redshift is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with Redshift. If not, see . + +# Copyright (c) 2010 Jon Lund Steffensen + + +import sys, os +import subprocess, signal +import gettext + +import pygtk +pygtk.require("2.0") + +import gtk, glib +import appindicator + +import defs + + +def run(): + # Internationalisation + gettext.bindtextdomain('redshift', defs.LOCALEDIR) + gettext.textdomain('redshift') + _ = gettext.gettext + + # Start redshift with arguments from the command line + args = sys.argv[1:] + args.insert(0, os.path.join(defs.BINDIR, 'redshift')) + process = subprocess.Popen(args) + + try: + # Create status icon + indicator = appindicator.Indicator ("redshift", + "redshift", + appindicator.CATEGORY_APPLICATION_STATUS) + indicator.set_status (appindicator.STATUS_ACTIVE) + + def toggle_cb(widget, data=None): + if indicator.get_icon() == 'redshift': + indicator.set_icon('redshift-idle') + else: + indicator.set_icon('redshift') + process.send_signal(signal.SIGUSR1) + + def destroy_cb(widget, data=None): + gtk.main_quit() + return False + + # Create popup menu + status_menu = gtk.Menu() + + toggle_item = gtk.ImageMenuItem(_('Toggle')) + toggle_item.connect('activate', toggle_cb) + status_menu.append(toggle_item) + + quit_item = gtk.ImageMenuItem(gtk.STOCK_QUIT) + quit_item.connect('activate', destroy_cb) + status_menu.append(quit_item) + + status_menu.show_all() + + # Set the menu + indicator.set_menu(status_menu) + + def child_cb(pid, cond, data=None): + sys.exit(-1) + + # Add watch on child process + glib.child_watch_add(process.pid, child_cb) + + # Run main loop + gtk.main() + + except KeyboardInterrupt: + # Ignore user interruption + pass + + finally: + # Always terminate redshift + process.terminate() + process.wait() -- cgit v1.2.3-70-g09d2 From a5b9ff65c421de27d81f9317a17467592fab3552 Mon Sep 17 00:00:00 2001 From: Francesco Marella Date: Fri, 4 Jun 2010 12:42:31 +0200 Subject: Add the autofoo needed to choose GTK+ status icon or app-indicator Passing 'enable-appindicator=yes' to the configure script the GTK+ status icon will be disabled. --- configure.ac | 24 ++++++++++++++++++++++++ src/gtk-redshift/Makefile.am | 24 ++++++++++++++++++++++-- src/gtk-redshift/gtk-redshift | 23 ----------------------- src/gtk-redshift/gtk-redshift.in | 23 +++++++++++++++++++++++ src/gtk-redshift/statusicon.py | 2 +- 5 files changed, 70 insertions(+), 26 deletions(-) delete mode 100644 src/gtk-redshift/gtk-redshift create mode 100644 src/gtk-redshift/gtk-redshift.in (limited to 'src/gtk-redshift') diff --git a/configure.ac b/configure.ac index 89cb47a..e667f64 100644 --- a/configure.ac +++ b/configure.ac @@ -121,6 +121,27 @@ AS_IF([test "x$enable_gnome_clock" != xno], [ ]) AM_CONDITIONAL([ENABLE_GNOME_CLOCK], [test "x$enable_gnome_clock" != xno]) +# Check for application indicator +AC_MSG_CHECKING([whether to enable application indicator]) +AC_ARG_ENABLE([appindicator], [AC_HELP_STRING([--enable-appindicator], + [enable application indicator])], + [enable_appindicator=$enableval],[enable_appindicator=no]) +AS_IF([test "x$enable_appindicator" != xno], [ + AS_IF([test $have_python = yes], [ + AC_MSG_RESULT([yes]) + enable_gtk=no + ], [ + AC_MSG_RESULT([missing dependencies]) + AS_IF([test "x$enable_appindicator" = xyes], [ + AC_MSG_ERROR([application indicator script requires Python 2.6]) + ]) + enable_appindicator=no + ]) +], [ + AC_MSG_RESULT([no]) +]) +AM_CONDITIONAL([ENABLE_APPINDICATOR], [test "x$enable_appindicator" != xno]) + # Check for GTK+ status icon AC_MSG_CHECKING([whether to enable GTK status icon]) AC_ARG_ENABLE([gtk], [AC_HELP_STRING([--enable-gtk], @@ -168,4 +189,7 @@ echo " compiler: ${CC} cflags: ${CFLAGS} ldflags: ${LDFLAGS} + + gtk status icon: ${enable_gtk} + application indicator: ${enable_appindicator} " diff --git a/src/gtk-redshift/Makefile.am b/src/gtk-redshift/Makefile.am index d0d8695..9c8479f 100644 --- a/src/gtk-redshift/Makefile.am +++ b/src/gtk-redshift/Makefile.am @@ -1,5 +1,6 @@ if ENABLE_GTK +module=statusicon gtk_redshift_PYTHON = \ __init__.py \ statusicon.py @@ -8,12 +9,31 @@ nodist_gtk_redshift_PYTHON = \ gtk_redshiftdir = $(pythondir)/gtk_redshift dist_bin_SCRIPTS = gtk-redshift -EXTRA_DIST = defs.py.in +EXTRA_DIST = gtk-redshift.in \ + defs.py.in endif -CLEANFILES = defs.py +if ENABLE_APPINDICATOR +module=rsappindicator +gtk_redshift_PYTHON = \ + __init__.py \ + rsappindicator.py +nodist_gtk_redshift_PYTHON = \ + defs.py +gtk_redshiftdir = $(pythondir)/gtk_redshift + +dist_bin_SCRIPTS = gtk-redshift +EXTRA_DIST = gtk-redshift.in \ + defs.py.in +endif + +CLEANFILES = defs.py \ + gtk-redshift # Local python definitions +gtk-redshift: gtk-redshift.in + sed -e "s|\@module\@|$(module)|g" $< > $@ + defs.py: defs.py.in sed -e "s|\@bindir\@|$(bindir)|g" \ -e "s|\@localedir\@|$(localedir)|g" $< > $@ diff --git a/src/gtk-redshift/gtk-redshift b/src/gtk-redshift/gtk-redshift deleted file mode 100644 index f62c6f1..0000000 --- a/src/gtk-redshift/gtk-redshift +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env python -# gtk-redshift -- GTK+ Redshift launcher script -# This file is part of Redshift. - -# Redshift is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# Redshift is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with Redshift. If not, see . - -# Copyright (c) 2010 Jon Lund Steffensen - - -if __name__ == '__main__': - from gtk_redshift.statusicon import run_statusicon - run_statusicon() diff --git a/src/gtk-redshift/gtk-redshift.in b/src/gtk-redshift/gtk-redshift.in new file mode 100644 index 0000000..18ee145 --- /dev/null +++ b/src/gtk-redshift/gtk-redshift.in @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# gtk-redshift -- GTK+ Redshift launcher script +# This file is part of Redshift. + +# Redshift is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# Redshift is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with Redshift. If not, see . + +# Copyright (c) 2010 Jon Lund Steffensen + + +if __name__ == '__main__': + from gtk_redshift.@module@ import run + run() diff --git a/src/gtk-redshift/statusicon.py b/src/gtk-redshift/statusicon.py index 9925c35..2295963 100644 --- a/src/gtk-redshift/statusicon.py +++ b/src/gtk-redshift/statusicon.py @@ -30,7 +30,7 @@ import gtk, glib import defs -def run_statusicon(): +def run(): # Internationalisation gettext.bindtextdomain('redshift', defs.LOCALEDIR) gettext.textdomain('redshift') -- cgit v1.2.3-70-g09d2 From d4fd3d4c4e36c72bd0745552b3c2c009ea1d9f47 Mon Sep 17 00:00:00 2001 From: Francesco Marella Date: Fri, 4 Jun 2010 12:43:21 +0200 Subject: Clean up --- src/gtk-redshift/__init__.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/gtk-redshift') diff --git a/src/gtk-redshift/__init__.py b/src/gtk-redshift/__init__.py index 30205ca..51ab2ef 100644 --- a/src/gtk-redshift/__init__.py +++ b/src/gtk-redshift/__init__.py @@ -16,5 +16,3 @@ # along with Redshift. If not, see . # Copyright (c) 2010 Jon Lund Steffensen - -__all__ = ['statusicon'] -- cgit v1.2.3-70-g09d2 From 69d1996f6d40b23558e7edc5b8000726438344e8 Mon Sep 17 00:00:00 2001 From: Francesco Marella Date: Sat, 5 Jun 2010 08:47:02 +0200 Subject: Wrap in try...except only gtk.main. --- src/gtk-redshift/rsappindicator.py | 60 +++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'src/gtk-redshift') diff --git a/src/gtk-redshift/rsappindicator.py b/src/gtk-redshift/rsappindicator.py index c681d89..0caebc1 100644 --- a/src/gtk-redshift/rsappindicator.py +++ b/src/gtk-redshift/rsappindicator.py @@ -42,46 +42,46 @@ def run(): args.insert(0, os.path.join(defs.BINDIR, 'redshift')) process = subprocess.Popen(args) - try: - # Create status icon - indicator = appindicator.Indicator ("redshift", - "redshift", - appindicator.CATEGORY_APPLICATION_STATUS) - indicator.set_status (appindicator.STATUS_ACTIVE) + # Create status icon + indicator = appindicator.Indicator ("redshift", + "redshift", + appindicator.CATEGORY_APPLICATION_STATUS) + indicator.set_status (appindicator.STATUS_ACTIVE) - def toggle_cb(widget, data=None): - if indicator.get_icon() == 'redshift': - indicator.set_icon('redshift-idle') - else: - indicator.set_icon('redshift') - process.send_signal(signal.SIGUSR1) + def toggle_cb(widget, data=None): + if indicator.get_icon() == 'redshift': + indicator.set_icon('redshift-idle') + else: + indicator.set_icon('redshift') + process.send_signal(signal.SIGUSR1) - def destroy_cb(widget, data=None): - gtk.main_quit() - return False + def destroy_cb(widget, data=None): + gtk.main_quit() + return False - # Create popup menu - status_menu = gtk.Menu() + # Create popup menu + status_menu = gtk.Menu() - toggle_item = gtk.ImageMenuItem(_('Toggle')) - toggle_item.connect('activate', toggle_cb) - status_menu.append(toggle_item) + toggle_item = gtk.ImageMenuItem(_('Toggle')) + toggle_item.connect('activate', toggle_cb) + status_menu.append(toggle_item) - quit_item = gtk.ImageMenuItem(gtk.STOCK_QUIT) - quit_item.connect('activate', destroy_cb) - status_menu.append(quit_item) + quit_item = gtk.ImageMenuItem(gtk.STOCK_QUIT) + quit_item.connect('activate', destroy_cb) + status_menu.append(quit_item) - status_menu.show_all() + status_menu.show_all() - # Set the menu - indicator.set_menu(status_menu) + # Set the menu + indicator.set_menu(status_menu) - def child_cb(pid, cond, data=None): - sys.exit(-1) + def child_cb(pid, cond, data=None): + sys.exit(-1) - # Add watch on child process - glib.child_watch_add(process.pid, child_cb) + # Add watch on child process + glib.child_watch_add(process.pid, child_cb) + try: # Run main loop gtk.main() -- cgit v1.2.3-70-g09d2 From 57f88da335e64509a2710c7c85cbb9b246640a3c Mon Sep 17 00:00:00 2001 From: Francesco Marella Date: Sat, 5 Jun 2010 09:17:17 +0200 Subject: Add a check for appindicator's module import --- src/gtk-redshift/rsappindicator.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/gtk-redshift') diff --git a/src/gtk-redshift/rsappindicator.py b/src/gtk-redshift/rsappindicator.py index 0caebc1..42514e4 100644 --- a/src/gtk-redshift/rsappindicator.py +++ b/src/gtk-redshift/rsappindicator.py @@ -26,7 +26,11 @@ import pygtk pygtk.require("2.0") import gtk, glib -import appindicator +try: + import appindicator +except ImportError as ie: + # No module named appindicator + sys.exit(str(ie)) import defs -- cgit v1.2.3-70-g09d2 From 84501af9338e2fb4a0252e8990981085b197ab46 Mon Sep 17 00:00:00 2001 From: Francesco Marella Date: Sun, 6 Jun 2010 14:39:50 +0200 Subject: rvert commit 103: Wrap in try...except only gtk.main. --- src/gtk-redshift/rsappindicator.py | 60 +++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'src/gtk-redshift') diff --git a/src/gtk-redshift/rsappindicator.py b/src/gtk-redshift/rsappindicator.py index 42514e4..59fa725 100644 --- a/src/gtk-redshift/rsappindicator.py +++ b/src/gtk-redshift/rsappindicator.py @@ -46,46 +46,46 @@ def run(): args.insert(0, os.path.join(defs.BINDIR, 'redshift')) process = subprocess.Popen(args) - # Create status icon - indicator = appindicator.Indicator ("redshift", - "redshift", - appindicator.CATEGORY_APPLICATION_STATUS) - indicator.set_status (appindicator.STATUS_ACTIVE) + try: + # Create status icon + indicator = appindicator.Indicator ("redshift", + "redshift", + appindicator.CATEGORY_APPLICATION_STATUS) + indicator.set_status (appindicator.STATUS_ACTIVE) - def toggle_cb(widget, data=None): - if indicator.get_icon() == 'redshift': - indicator.set_icon('redshift-idle') - else: - indicator.set_icon('redshift') - process.send_signal(signal.SIGUSR1) + def toggle_cb(widget, data=None): + if indicator.get_icon() == 'redshift': + indicator.set_icon('redshift-idle') + else: + indicator.set_icon('redshift') + process.send_signal(signal.SIGUSR1) - def destroy_cb(widget, data=None): - gtk.main_quit() - return False + def destroy_cb(widget, data=None): + gtk.main_quit() + return False - # Create popup menu - status_menu = gtk.Menu() + # Create popup menu + status_menu = gtk.Menu() - toggle_item = gtk.ImageMenuItem(_('Toggle')) - toggle_item.connect('activate', toggle_cb) - status_menu.append(toggle_item) + toggle_item = gtk.ImageMenuItem(_('Toggle')) + toggle_item.connect('activate', toggle_cb) + status_menu.append(toggle_item) - quit_item = gtk.ImageMenuItem(gtk.STOCK_QUIT) - quit_item.connect('activate', destroy_cb) - status_menu.append(quit_item) + quit_item = gtk.ImageMenuItem(gtk.STOCK_QUIT) + quit_item.connect('activate', destroy_cb) + status_menu.append(quit_item) - status_menu.show_all() + status_menu.show_all() - # Set the menu - indicator.set_menu(status_menu) + # Set the menu + indicator.set_menu(status_menu) - def child_cb(pid, cond, data=None): - sys.exit(-1) + def child_cb(pid, cond, data=None): + sys.exit(-1) - # Add watch on child process - glib.child_watch_add(process.pid, child_cb) + # Add watch on child process + glib.child_watch_add(process.pid, child_cb) - try: # Run main loop gtk.main() -- cgit v1.2.3-70-g09d2