From 739f806f195a9b6a699cd4c821f321970a916645 Mon Sep 17 00:00:00 2001 From: Jon Lund Steffensen Date: Thu, 11 Feb 2010 22:06:12 +0100 Subject: Turn gtk-redshift into a python module. A launcher script is installed in bindir. --- src/gtk-redshift/__init__.py | 20 +++++++++ src/gtk-redshift/gtk-redshift | 23 ++++++++++ src/gtk-redshift/gtk-redshift.py | 95 ---------------------------------------- src/gtk-redshift/statusicon.py | 95 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+), 95 deletions(-) create mode 100644 src/gtk-redshift/__init__.py create mode 100644 src/gtk-redshift/gtk-redshift delete mode 100755 src/gtk-redshift/gtk-redshift.py create mode 100644 src/gtk-redshift/statusicon.py (limited to 'src') diff --git a/src/gtk-redshift/__init__.py b/src/gtk-redshift/__init__.py new file mode 100644 index 0000000..30205ca --- /dev/null +++ b/src/gtk-redshift/__init__.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +# __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 + +__all__ = ['statusicon'] diff --git a/src/gtk-redshift/gtk-redshift b/src/gtk-redshift/gtk-redshift new file mode 100644 index 0000000..f62c6f1 --- /dev/null +++ b/src/gtk-redshift/gtk-redshift @@ -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.statusicon import run_statusicon + run_statusicon() diff --git a/src/gtk-redshift/gtk-redshift.py b/src/gtk-redshift/gtk-redshift.py deleted file mode 100755 index a737154..0000000 --- a/src/gtk-redshift/gtk-redshift.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env python -# gtk-redshift -- GTK+ 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 - - -import sys -import subprocess, signal -import gettext - -import pygtk -pygtk.require("2.0") - -import gtk, glib - -import defs - - -if __name__ == '__main__': - # 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, 'redshift') - process = subprocess.Popen(args) - - try: - # Create status icon - status_icon = gtk.StatusIcon() - status_icon.set_from_icon_name('redshift') - status_icon.set_tooltip('Redshift') - - def toggle_cb(widget, data=None): - process.send_signal(signal.SIGUSR1) - - def destroy_cb(widget, data=None): - status_icon.set_visible(False) - 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) - - 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/statusicon.py b/src/gtk-redshift/statusicon.py new file mode 100644 index 0000000..ae05b5c --- /dev/null +++ b/src/gtk-redshift/statusicon.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python +# statusicon.py -- GTK+ 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 + + +import sys, os +import subprocess, signal +import gettext + +import pygtk +pygtk.require("2.0") + +import gtk, glib + +import defs + + +def run_statusicon(): + # 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, 'redshift') + process = subprocess.Popen(args) + + try: + # Create status icon + status_icon = gtk.StatusIcon() + status_icon.set_from_icon_name('redshift') + status_icon.set_tooltip('Redshift') + + def toggle_cb(widget, data=None): + process.send_signal(signal.SIGUSR1) + + def destroy_cb(widget, data=None): + status_icon.set_visible(False) + 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) + + 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() -- cgit v1.2.3-70-g09d2