diff options
author | Jon Lund Steffensen <jonlst@gmail.com> | 2012-02-03 20:23:48 +0100 |
---|---|---|
committer | Jon Lund Steffensen <jonlst@gmail.com> | 2012-02-03 20:23:48 +0100 |
commit | ed873130a140a154b373ac61027a25b79f13de4e (patch) | |
tree | e028fcac5c845b89cc2a610ea62002510ebb02ce /src | |
parent | Add some info on building redshift from a bzr branch. (diff) | |
parent | Add "Suspend for X minutes" option to gtk-redshift (diff) | |
download | redshift-ng-ed873130a140a154b373ac61027a25b79f13de4e.tar.gz redshift-ng-ed873130a140a154b373ac61027a25b79f13de4e.tar.bz2 redshift-ng-ed873130a140a154b373ac61027a25b79f13de4e.tar.xz |
Merge gtk-redshift option to suspend for a short time period (Jendrik Seipp).
Diffstat (limited to 'src')
-rw-r--r-- | src/gtk-redshift/statusicon.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/gtk-redshift/statusicon.py b/src/gtk-redshift/statusicon.py index 9b80a6b..da35896 100644 --- a/src/gtk-redshift/statusicon.py +++ b/src/gtk-redshift/statusicon.py @@ -40,6 +40,9 @@ import defs import utils +SUSPEND_TIMER = None + + def run(): # Internationalisation gettext.bindtextdomain('redshift', defs.LOCALEDIR) @@ -64,7 +67,24 @@ def run(): 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': @@ -77,6 +97,23 @@ def run(): 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()) @@ -93,6 +130,16 @@ def run(): 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()) |