From 30c805f5e7fe79c465077cecd05d0afafe79dc68 Mon Sep 17 00:00:00 2001 From: Jon Lund Steffensen Date: Tue, 5 Mar 2013 23:17:54 +0100 Subject: Rename gtk-redshift -> redshift-gtk. This is primarily for improved discovery. Some users report that they didn't know about redshift-gtk, but had it been available on tab completion they would have noticed. Also, I think it is in general good practice that closely related programs have the same prefix. --- DESIGN | 4 +- HACKING | 2 +- Makefile.am | 2 +- README | 2 +- configure.ac | 2 +- data/applications/gtk-redshift.desktop | 11 -- data/applications/redshift-gtk.desktop | 11 ++ po/POTFILES.in | 2 +- src/Makefile.am | 2 +- src/gtk-redshift/Makefile.am | 21 ---- src/gtk-redshift/__init__.py | 17 --- src/gtk-redshift/defs.py.in | 21 ---- src/gtk-redshift/gtk-redshift | 23 ---- src/gtk-redshift/statusicon.py | 190 --------------------------------- src/gtk-redshift/utils.py | 64 ----------- src/redshift-gtk/Makefile.am | 21 ++++ src/redshift-gtk/__init__.py | 17 +++ src/redshift-gtk/defs.py.in | 21 ++++ src/redshift-gtk/redshift-gtk | 23 ++++ src/redshift-gtk/statusicon.py | 190 +++++++++++++++++++++++++++++++++ src/redshift-gtk/utils.py | 64 +++++++++++ 21 files changed, 355 insertions(+), 355 deletions(-) delete mode 100755 data/applications/gtk-redshift.desktop create mode 100755 data/applications/redshift-gtk.desktop delete mode 100644 src/gtk-redshift/Makefile.am delete mode 100644 src/gtk-redshift/__init__.py delete mode 100644 src/gtk-redshift/defs.py.in delete mode 100644 src/gtk-redshift/gtk-redshift delete mode 100644 src/gtk-redshift/statusicon.py delete mode 100644 src/gtk-redshift/utils.py create mode 100644 src/redshift-gtk/Makefile.am create mode 100644 src/redshift-gtk/__init__.py create mode 100644 src/redshift-gtk/defs.py.in create mode 100644 src/redshift-gtk/redshift-gtk create mode 100644 src/redshift-gtk/statusicon.py create mode 100644 src/redshift-gtk/utils.py diff --git a/DESIGN b/DESIGN index 31c9ee4..0fdf6a0 100644 --- a/DESIGN +++ b/DESIGN @@ -26,10 +26,10 @@ Once running, redshift currently doesn't check location providers again. -gtk-redshift +redshift-gtk ------------ -gtk-redshift is a small program written in Python that shows a status +redshift-gtk is a small program written in Python that shows a status icon (what is an appindicator versus a GTK status icon?) (does it change the icon according to internal program state of redshift? doesn't seem so) and run an instance of the "redshift" program, and diff --git a/HACKING b/HACKING index 86b58bc..0138ca9 100644 --- a/HACKING +++ b/HACKING @@ -20,7 +20,7 @@ prefix directory run: You can now run the python scripts. Example: $ PYTHONHOME=$HOME/redshift/root/lib/python2.7/site-packages \ - $HOME/redshift/root/bin/gtk-redshift + $HOME/redshift/root/bin/redshift-gtk Notes diff --git a/Makefile.am b/Makefile.am index b0e5c37..b657680 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,7 +16,7 @@ _UBUNTU_MONO_LIGHT_FILES = \ data/icons/ubuntu-mono-light/scalable/apps/redshift-status-off.svg _DESKTOP_FILES = \ - data/applications/gtk-redshift.desktop + data/applications/redshift-gtk.desktop # Icons if ENABLE_GUI diff --git a/README b/README index 2fb3450..84439b7 100644 --- a/README +++ b/README @@ -7,7 +7,7 @@ your surroundings. This may help your eyes hurt less if you are working in front of the screen at night. Run `redshift -h' for help on command line options. You can run the program -as `gtk-redshift' instead of 'redshift' for a graphical status icon. +as `redshift-gtk' instead of 'redshift' for a graphical status icon. Website: http://jonls.dk/redshift/ Project page: http://launchpad.net/redshift diff --git a/configure.ac b/configure.ac index 1af5bfe..88dfd62 100644 --- a/configure.ac +++ b/configure.ac @@ -204,7 +204,7 @@ AC_CONFIG_FILES([ Makefile po/Makefile.in src/Makefile - src/gtk-redshift/Makefile + src/redshift-gtk/Makefile ]) AC_OUTPUT diff --git a/data/applications/gtk-redshift.desktop b/data/applications/gtk-redshift.desktop deleted file mode 100755 index 850255c..0000000 --- a/data/applications/gtk-redshift.desktop +++ /dev/null @@ -1,11 +0,0 @@ -[Desktop Entry] -Version=1.0 -Name=Redshift -GenericName=Color temperature adjustment -Comment=Color temperature adjustment tool -Exec=gtk-redshift -Icon=redshift -Terminal=false -Type=Application -Categories=Utility; -StartupNotify=true diff --git a/data/applications/redshift-gtk.desktop b/data/applications/redshift-gtk.desktop new file mode 100755 index 0000000..dc8d8b2 --- /dev/null +++ b/data/applications/redshift-gtk.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Version=1.0 +Name=Redshift +GenericName=Color temperature adjustment +Comment=Color temperature adjustment tool +Exec=redshift-gtk +Icon=redshift +Terminal=false +Type=Application +Categories=Utility; +StartupNotify=true diff --git a/po/POTFILES.in b/po/POTFILES.in index ff61d9a..01a6e9c 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -11,4 +11,4 @@ src/gamma-w32gdi.c src/location-gnome-clock.c src/location-manual.c -src/gtk-redshift/statusicon.py +src/redshift-gtk/statusicon.py diff --git a/src/Makefile.am b/src/Makefile.am index 6c4a613..ccf5108 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ -SUBDIRS = gtk-redshift +SUBDIRS = redshift-gtk # I18n localedir = $(datadir)/locale diff --git a/src/gtk-redshift/Makefile.am b/src/gtk-redshift/Makefile.am deleted file mode 100644 index bb69459..0000000 --- a/src/gtk-redshift/Makefile.am +++ /dev/null @@ -1,21 +0,0 @@ - -if ENABLE_GUI -gtk_redshift_PYTHON = \ - __init__.py \ - utils.py \ - statusicon.py -nodist_gtk_redshift_PYTHON = \ - defs.py -gtk_redshiftdir = $(pythondir)/gtk_redshift - -dist_bin_SCRIPTS = gtk-redshift -endif - -EXTRA_DIST = defs.py.in -CLEANFILES = defs.py - - -# Local python definitions -defs.py: defs.py.in - sed -e "s|\@bindir\@|$(bindir)|g" \ - -e "s|\@localedir\@|$(localedir)|g" $< > $@ diff --git a/src/gtk-redshift/__init__.py b/src/gtk-redshift/__init__.py deleted file mode 100644 index 0e4f254..0000000 --- a/src/gtk-redshift/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# __init__.py -- gtk-redshift package __init__ file -# 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 diff --git a/src/gtk-redshift/defs.py.in b/src/gtk-redshift/defs.py.in deleted file mode 100644 index 026fefd..0000000 --- a/src/gtk-redshift/defs.py.in +++ /dev/null @@ -1,21 +0,0 @@ -# defs.py -- GTK+ redshift local definitions -# 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 - - -LOCALEDIR = '@localedir@' -BINDIR = '@bindir@' diff --git a/src/gtk-redshift/gtk-redshift b/src/gtk-redshift/gtk-redshift deleted file mode 100644 index 56d940e..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 - run() diff --git a/src/gtk-redshift/statusicon.py b/src/gtk-redshift/statusicon.py deleted file mode 100644 index da35896..0000000 --- a/src/gtk-redshift/statusicon.py +++ /dev/null @@ -1,190 +0,0 @@ -# statusicon.py -- GUI status icon 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 - - -'''GUI status icon for Redshift. - -The run method will try to start an appindicator for Redshift. If the -appindicator module isn't present it will fall back to a GTK status icon. -''' - -import sys, os -import subprocess, signal -import gettext - -import pygtk -pygtk.require("2.0") - -import gtk, glib -try: - import appindicator -except ImportError: - appindicator = None - -import defs -import utils - - -SUSPEND_TIMER = None - - -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: - if appindicator: - # Create indicator - indicator = appindicator.Indicator('redshift', - 'redshift-status-on', - appindicator.CATEGORY_APPLICATION_STATUS) - indicator.set_status(appindicator.STATUS_ACTIVE) - else: - # Create status icon - status_icon = gtk.StatusIcon() - status_icon.set_from_icon_name('redshift-status-on') - status_icon.set_tooltip('Redshift') - - def is_enabled(): - if appindicator: - return indicator.get_icon() == 'redshift-status-on' - else: - return status_icon.get_icon_name() == 'redshift-status-on' - - def remove_suspend_timer(): - global SUSPEND_TIMER - if SUSPEND_TIMER is not None: - glib.source_remove(SUSPEND_TIMER) - SUSPEND_TIMER = None - - def toggle_cb(widget, data=None): - # If the user toggles redshift, we forget about the suspend timer. - # Only then widget is not None. - if widget: - remove_suspend_timer() - - process.send_signal(signal.SIGUSR1) - if appindicator: - if indicator.get_icon() == 'redshift-status-on': - indicator.set_icon('redshift-status-off') - else: - indicator.set_icon('redshift-status-on') - else: - if status_icon.get_icon_name() == 'redshift-status-on': - status_icon.set_from_icon_name('redshift-status-off') - else: - status_icon.set_from_icon_name('redshift-status-on') - - def enable_cb(): - if is_enabled(): - return - # Enable redshift - toggle_cb(None) - - def suspend_cb(widget, minutes): - if is_enabled(): - # Disable redshift - toggle_cb(None) - # If "suspend" is clicked while redshift is disabled, we reenable - # it after the last selected timespan is over. - remove_suspend_timer() - # If redshift was already disabled we reenable it nonetheless. - global SUSPEND_TIMER - SUSPEND_TIMER = glib.timeout_add_seconds(minutes * 60, enable_cb) - - def autostart_cb(widget, data=None): - utils.set_autostart(widget.get_active()) - - def destroy_cb(widget, data=None): - if not appindicator: - status_icon.set_visible(False) - gtk.main_quit() - return False - - # Create popup menu - status_menu = gtk.Menu() - - toggle_item = gtk.MenuItem(_('Toggle')) - toggle_item.connect('activate', toggle_cb) - status_menu.append(toggle_item) - - suspend_menu_item = gtk.MenuItem(_('Suspend for')) - suspend_menu = gtk.Menu() - for minutes, label in [(30, _('30 minutes')), (60, _('1 hour')), - (120, _('2 hours'))]: - suspend_item = gtk.MenuItem(label) - suspend_item.connect('activate', suspend_cb, minutes) - suspend_menu.append(suspend_item) - suspend_menu_item.set_submenu(suspend_menu) - status_menu.append(suspend_menu_item) - - autostart_item = gtk.CheckMenuItem(_('Autostart')) - try: - autostart_item.set_active(utils.get_autostart()) - except IOError as strerror: - print strerror - autostart_item.set_property('sensitive', False) - else: - autostart_item.connect('activate', autostart_cb) - finally: - status_menu.append(autostart_item) - - quit_item = gtk.ImageMenuItem(gtk.STOCK_QUIT) - quit_item.connect('activate', destroy_cb) - status_menu.append(quit_item) - - if appindicator: - status_menu.show_all() - - # Set the menu - indicator.set_menu(status_menu) - else: - def popup_menu_cb(widget, button, time, data=None): - status_menu.show_all() - status_menu.popup(None, None, gtk.status_icon_position_menu, - button, time, status_icon) - - # Connect signals for status icon and show - status_icon.connect('activate', toggle_cb) - status_icon.connect('popup-menu', popup_menu_cb) - status_icon.set_visible(True) - - 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/utils.py b/src/gtk-redshift/utils.py deleted file mode 100644 index 2fd3b71..0000000 --- a/src/gtk-redshift/utils.py +++ /dev/null @@ -1,64 +0,0 @@ -# utils.py -- utility functions 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 Francesco Marella -# Copyright (c) 2011 Jon Lund Steffensen - -import os -from xdg import BaseDirectory as base -from xdg import DesktopEntry as desktop - -REDSHIFT_DESKTOP = 'gtk-redshift.desktop' - -# Keys to set when enabling/disabling autostart. -# Only first one is checked on "get". -AUTOSTART_KEYS = (('Hidden', ('true', 'false')), - ('X-GNOME-Autostart-enabled', ('false', 'true'))) - - -def open_autostart_file(): - autostart_dir = base.save_config_path("autostart") - autostart_file = os.path.join(autostart_dir, REDSHIFT_DESKTOP) - - if not os.path.exists(autostart_file): - desktop_files = list(base.load_data_paths("applications", - REDSHIFT_DESKTOP)) - - if not desktop_files: - raise IOError("Installed redshift desktop file not found!") - - desktop_file_path = desktop_files[0] - - # Read installed file - dfile = desktop.DesktopEntry(desktop_file_path) - for key, values in AUTOSTART_KEYS: - dfile.set(key, values[False]) - dfile.write(filename=autostart_file) - else: - dfile = desktop.DesktopEntry(autostart_file) - - return dfile, autostart_file - -def get_autostart(): - dfile, path = open_autostart_file() - check_key, check_values = AUTOSTART_KEYS[0] - return dfile.get(check_key) == check_values[True] - -def set_autostart(active): - dfile, path = open_autostart_file() - for key, values in AUTOSTART_KEYS: - dfile.set(key, values[active]) - dfile.write(filename=path) diff --git a/src/redshift-gtk/Makefile.am b/src/redshift-gtk/Makefile.am new file mode 100644 index 0000000..10242ea --- /dev/null +++ b/src/redshift-gtk/Makefile.am @@ -0,0 +1,21 @@ + +if ENABLE_GUI +redshift_gtk_PYTHON = \ + __init__.py \ + utils.py \ + statusicon.py +nodist_redshift_gtk_PYTHON = \ + defs.py +redshift_gtkdir = $(pythondir)/redshift_gtk + +dist_bin_SCRIPTS = redshift-gtk +endif + +EXTRA_DIST = defs.py.in +CLEANFILES = defs.py + + +# Local python definitions +defs.py: defs.py.in + sed -e "s|\@bindir\@|$(bindir)|g" \ + -e "s|\@localedir\@|$(localedir)|g" $< > $@ diff --git a/src/redshift-gtk/__init__.py b/src/redshift-gtk/__init__.py new file mode 100644 index 0000000..e8a14af --- /dev/null +++ b/src/redshift-gtk/__init__.py @@ -0,0 +1,17 @@ +# __init__.py -- redshift-gtk package __init__ file +# 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 diff --git a/src/redshift-gtk/defs.py.in b/src/redshift-gtk/defs.py.in new file mode 100644 index 0000000..026fefd --- /dev/null +++ b/src/redshift-gtk/defs.py.in @@ -0,0 +1,21 @@ +# defs.py -- GTK+ redshift local definitions +# 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 + + +LOCALEDIR = '@localedir@' +BINDIR = '@bindir@' diff --git a/src/redshift-gtk/redshift-gtk b/src/redshift-gtk/redshift-gtk new file mode 100644 index 0000000..3ec3010 --- /dev/null +++ b/src/redshift-gtk/redshift-gtk @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# redshift-gtk -- 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 redshift_gtk.statusicon import run + run() diff --git a/src/redshift-gtk/statusicon.py b/src/redshift-gtk/statusicon.py new file mode 100644 index 0000000..da35896 --- /dev/null +++ b/src/redshift-gtk/statusicon.py @@ -0,0 +1,190 @@ +# statusicon.py -- GUI status icon 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 + + +'''GUI status icon for Redshift. + +The run method will try to start an appindicator for Redshift. If the +appindicator module isn't present it will fall back to a GTK status icon. +''' + +import sys, os +import subprocess, signal +import gettext + +import pygtk +pygtk.require("2.0") + +import gtk, glib +try: + import appindicator +except ImportError: + appindicator = None + +import defs +import utils + + +SUSPEND_TIMER = None + + +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: + if appindicator: + # Create indicator + indicator = appindicator.Indicator('redshift', + 'redshift-status-on', + appindicator.CATEGORY_APPLICATION_STATUS) + indicator.set_status(appindicator.STATUS_ACTIVE) + else: + # Create status icon + status_icon = gtk.StatusIcon() + status_icon.set_from_icon_name('redshift-status-on') + status_icon.set_tooltip('Redshift') + + def is_enabled(): + if appindicator: + return indicator.get_icon() == 'redshift-status-on' + else: + return status_icon.get_icon_name() == 'redshift-status-on' + + def remove_suspend_timer(): + global SUSPEND_TIMER + if SUSPEND_TIMER is not None: + glib.source_remove(SUSPEND_TIMER) + SUSPEND_TIMER = None + + def toggle_cb(widget, data=None): + # If the user toggles redshift, we forget about the suspend timer. + # Only then widget is not None. + if widget: + remove_suspend_timer() + + process.send_signal(signal.SIGUSR1) + if appindicator: + if indicator.get_icon() == 'redshift-status-on': + indicator.set_icon('redshift-status-off') + else: + indicator.set_icon('redshift-status-on') + else: + if status_icon.get_icon_name() == 'redshift-status-on': + status_icon.set_from_icon_name('redshift-status-off') + else: + status_icon.set_from_icon_name('redshift-status-on') + + def enable_cb(): + if is_enabled(): + return + # Enable redshift + toggle_cb(None) + + def suspend_cb(widget, minutes): + if is_enabled(): + # Disable redshift + toggle_cb(None) + # If "suspend" is clicked while redshift is disabled, we reenable + # it after the last selected timespan is over. + remove_suspend_timer() + # If redshift was already disabled we reenable it nonetheless. + global SUSPEND_TIMER + SUSPEND_TIMER = glib.timeout_add_seconds(minutes * 60, enable_cb) + + def autostart_cb(widget, data=None): + utils.set_autostart(widget.get_active()) + + def destroy_cb(widget, data=None): + if not appindicator: + status_icon.set_visible(False) + gtk.main_quit() + return False + + # Create popup menu + status_menu = gtk.Menu() + + toggle_item = gtk.MenuItem(_('Toggle')) + toggle_item.connect('activate', toggle_cb) + status_menu.append(toggle_item) + + suspend_menu_item = gtk.MenuItem(_('Suspend for')) + suspend_menu = gtk.Menu() + for minutes, label in [(30, _('30 minutes')), (60, _('1 hour')), + (120, _('2 hours'))]: + suspend_item = gtk.MenuItem(label) + suspend_item.connect('activate', suspend_cb, minutes) + suspend_menu.append(suspend_item) + suspend_menu_item.set_submenu(suspend_menu) + status_menu.append(suspend_menu_item) + + autostart_item = gtk.CheckMenuItem(_('Autostart')) + try: + autostart_item.set_active(utils.get_autostart()) + except IOError as strerror: + print strerror + autostart_item.set_property('sensitive', False) + else: + autostart_item.connect('activate', autostart_cb) + finally: + status_menu.append(autostart_item) + + quit_item = gtk.ImageMenuItem(gtk.STOCK_QUIT) + quit_item.connect('activate', destroy_cb) + status_menu.append(quit_item) + + if appindicator: + status_menu.show_all() + + # Set the menu + indicator.set_menu(status_menu) + else: + def popup_menu_cb(widget, button, time, data=None): + status_menu.show_all() + status_menu.popup(None, None, gtk.status_icon_position_menu, + button, time, status_icon) + + # Connect signals for status icon and show + status_icon.connect('activate', toggle_cb) + status_icon.connect('popup-menu', popup_menu_cb) + status_icon.set_visible(True) + + 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/redshift-gtk/utils.py b/src/redshift-gtk/utils.py new file mode 100644 index 0000000..723d4d8 --- /dev/null +++ b/src/redshift-gtk/utils.py @@ -0,0 +1,64 @@ +# utils.py -- utility functions 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 Francesco Marella +# Copyright (c) 2011 Jon Lund Steffensen + +import os +from xdg import BaseDirectory as base +from xdg import DesktopEntry as desktop + +REDSHIFT_DESKTOP = 'redshift-gtk.desktop' + +# Keys to set when enabling/disabling autostart. +# Only first one is checked on "get". +AUTOSTART_KEYS = (('Hidden', ('true', 'false')), + ('X-GNOME-Autostart-enabled', ('false', 'true'))) + + +def open_autostart_file(): + autostart_dir = base.save_config_path("autostart") + autostart_file = os.path.join(autostart_dir, REDSHIFT_DESKTOP) + + if not os.path.exists(autostart_file): + desktop_files = list(base.load_data_paths("applications", + REDSHIFT_DESKTOP)) + + if not desktop_files: + raise IOError("Installed redshift desktop file not found!") + + desktop_file_path = desktop_files[0] + + # Read installed file + dfile = desktop.DesktopEntry(desktop_file_path) + for key, values in AUTOSTART_KEYS: + dfile.set(key, values[False]) + dfile.write(filename=autostart_file) + else: + dfile = desktop.DesktopEntry(autostart_file) + + return dfile, autostart_file + +def get_autostart(): + dfile, path = open_autostart_file() + check_key, check_values = AUTOSTART_KEYS[0] + return dfile.get(check_key) == check_values[True] + +def set_autostart(active): + dfile, path = open_autostart_file() + for key, values in AUTOSTART_KEYS: + dfile.set(key, values[active]) + dfile.write(filename=path) -- cgit v1.2.3-70-g09d2