aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJon Lund Steffensen <jonlst@gmail.com>2010-06-06 23:34:49 +0200
committerJon Lund Steffensen <jonlst@gmail.com>2010-06-06 23:34:49 +0200
commit79d6d29889102a7935268dadf0b5fd2965151141 (patch)
tree2c0c2b64b38b3fc715167f283ca57fa38285e667 /src
parentUpdate po files. (diff)
parentrvert commit 103: Wrap in try...except only gtk.main. (diff)
downloadredshift-ng-79d6d29889102a7935268dadf0b5fd2965151141.tar.gz
redshift-ng-79d6d29889102a7935268dadf0b5fd2965151141.tar.bz2
redshift-ng-79d6d29889102a7935268dadf0b5fd2965151141.tar.xz
Merge application indicator support from Franesco Marella.
Change GUI configuration parameter in configure.ac to --enable-gui. Distribute defs.py.in and gtk-redshift.in even if GUI is disabled. Update POTFILES.in and update translation files.
Diffstat (limited to 'src')
-rw-r--r--src/gtk-redshift/Makefile.am29
-rw-r--r--src/gtk-redshift/__init__.py2
-rw-r--r--src/gtk-redshift/gtk-redshift.in (renamed from src/gtk-redshift/gtk-redshift)4
-rw-r--r--src/gtk-redshift/rsappindicator.py99
-rw-r--r--src/gtk-redshift/statusicon.py2
5 files changed, 127 insertions, 9 deletions
diff --git a/src/gtk-redshift/Makefile.am b/src/gtk-redshift/Makefile.am
index d0d8695..ddeafd6 100644
--- a/src/gtk-redshift/Makefile.am
+++ b/src/gtk-redshift/Makefile.am
@@ -1,5 +1,6 @@
-if ENABLE_GTK
+if ENABLE_STATUSICON
+gui_module=statusicon
gtk_redshift_PYTHON = \
__init__.py \
statusicon.py
@@ -7,11 +8,31 @@ nodist_gtk_redshift_PYTHON = \
defs.py
gtk_redshiftdir = $(pythondir)/gtk_redshift
-dist_bin_SCRIPTS = gtk-redshift
-EXTRA_DIST = defs.py.in
+bin_SCRIPTS = gtk-redshift
endif
-CLEANFILES = defs.py
+if ENABLE_APPINDICATOR
+gui_module=rsappindicator
+gtk_redshift_PYTHON = \
+ __init__.py \
+ rsappindicator.py
+nodist_gtk_redshift_PYTHON = \
+ defs.py
+gtk_redshiftdir = $(pythondir)/gtk_redshift
+
+bin_SCRIPTS = gtk-redshift
+endif
+
+EXTRA_DIST = gtk-redshift.in \
+ defs.py.in
+
+CLEANFILES = defs.py \
+ gtk-redshift
+
+
+# Main GUI script
+gtk-redshift: gtk-redshift.in
+ sed -e "s|\@gui_module\@|$(gui_module)|g" $< > $@
# Local python definitions
defs.py: defs.py.in
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 <http://www.gnu.org/licenses/>.
# Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com>
-
-__all__ = ['statusicon']
diff --git a/src/gtk-redshift/gtk-redshift b/src/gtk-redshift/gtk-redshift.in
index f62c6f1..120e05c 100644
--- a/src/gtk-redshift/gtk-redshift
+++ b/src/gtk-redshift/gtk-redshift.in
@@ -19,5 +19,5 @@
if __name__ == '__main__':
- from gtk_redshift.statusicon import run_statusicon
- run_statusicon()
+ from gtk_redshift.@gui_module@ import run
+ run()
diff --git a/src/gtk-redshift/rsappindicator.py b/src/gtk-redshift/rsappindicator.py
new file mode 100644
index 0000000..59fa725
--- /dev/null
+++ b/src/gtk-redshift/rsappindicator.py
@@ -0,0 +1,99 @@
+#!/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 <http://www.gnu.org/licenses/>.
+
+# Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com>
+
+
+import sys, os
+import subprocess, signal
+import gettext
+
+import pygtk
+pygtk.require("2.0")
+
+import gtk, glib
+try:
+ import appindicator
+except ImportError as ie:
+ # No module named appindicator
+ sys.exit(str(ie))
+
+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()
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')