From 8768ba76f8b6aa760822e1c83ba82477ae601314 Mon Sep 17 00:00:00 2001 From: TingPing Date: Sun, 29 Dec 2013 19:41:10 -0500 Subject: Port redshift-gtk to Python3 Python 2 is no longer supported --- configure.ac | 2 +- src/redshift-gtk/Makefile.am | 7 +++++-- src/redshift-gtk/redshift-gtk | 23 ----------------------- src/redshift-gtk/redshift-gtk.in | 27 +++++++++++++++++++++++++++ src/redshift-gtk/statusicon.py | 10 +++++----- 5 files changed, 38 insertions(+), 31 deletions(-) delete mode 100644 src/redshift-gtk/redshift-gtk create mode 100644 src/redshift-gtk/redshift-gtk.in diff --git a/configure.ac b/configure.ac index e82ee03..550ed0f 100644 --- a/configure.ac +++ b/configure.ac @@ -27,7 +27,7 @@ PKG_CHECK_MODULES([GEOCLUE], [geoclue], [have_geoclue=yes], [have_geoclue=no]) AC_CHECK_HEADER([windows.h], [have_windows_h=yes], [have_windows_h=no]) # Check for Python -AM_PATH_PYTHON([2.6], [have_python=yes], [have_python=no]) +AM_PATH_PYTHON([3.3], [have_python=yes], [have_python=no]) # Check RANDR method AC_MSG_CHECKING([whether to enable RANDR method]) diff --git a/src/redshift-gtk/Makefile.am b/src/redshift-gtk/Makefile.am index 9eb0cdb..96d7718 100644 --- a/src/redshift-gtk/Makefile.am +++ b/src/redshift-gtk/Makefile.am @@ -11,11 +11,14 @@ redshift_gtkdir = $(pythondir)/redshift_gtk dist_bin_SCRIPTS = redshift-gtk endif -EXTRA_DIST = defs.py.in -CLEANFILES = defs.py +EXTRA_DIST = defs.py.in redshift-gtk.in +CLEANFILES = defs.py redshift-gtk # Local python definitions defs.py: defs.py.in $(AM_V_GEN)sed -e "s|\@bindir\@|$(bindir)|g" \ -e "s|\@localedir\@|$(localedir)|g" $< > $@ + +redshift-gtk: redshift-gtk.in + $(AM_V_GEN)sed -e "s|\@pythondir\@|$(pythondir)|g" $< > $@ diff --git a/src/redshift-gtk/redshift-gtk b/src/redshift-gtk/redshift-gtk deleted file mode 100644 index 3ec3010..0000000 --- a/src/redshift-gtk/redshift-gtk +++ /dev/null @@ -1,23 +0,0 @@ -#!/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/redshift-gtk.in b/src/redshift-gtk/redshift-gtk.in new file mode 100644 index 0000000..ba6e1ac --- /dev/null +++ b/src/redshift-gtk/redshift-gtk.in @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +# 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 + +import sys + +# Some non-standard install paths may need to be added +sys.path.append('@pythondir@') + +if __name__ == '__main__': + from redshift_gtk.statusicon import run + run() diff --git a/src/redshift-gtk/statusicon.py b/src/redshift-gtk/statusicon.py index 15a822b..626b9e3 100644 --- a/src/redshift-gtk/statusicon.py +++ b/src/redshift-gtk/statusicon.py @@ -34,8 +34,8 @@ try: except ImportError: appindicator = None -import defs -import utils +from . import defs +from . import utils _ = gettext.gettext @@ -99,7 +99,7 @@ class RedshiftStatusIcon(object): try: autostart_item.set_active(utils.get_autostart()) except IOError as strerror: - print strerror + print(strerror) autostart_item.set_property('sensitive', False) else: autostart_item.connect('toggled', self.autostart_cb) @@ -185,7 +185,7 @@ class RedshiftStatusIcon(object): # Start child process with C locale so we can parse the output env = os.environ.copy() env['LANG'] = env['LANGUAGE'] = env['LC_ALL'] = env['LC_MESSAGES'] = 'C' - self.process = GLib.spawn_async(args, envp=['{}={}'.format(k,v) for k, v in env.iteritems()], + self.process = GLib.spawn_async(args, envp=['{}={}'.format(k,v) for k, v in env.items()], flags=GLib.SPAWN_DO_NOT_REAP_CHILD, standard_output=True, standard_error=True) @@ -299,7 +299,7 @@ class RedshiftStatusIcon(object): def child_data_cb(self, f, cond, data): stdout, ib = data - ib.buf += os.read(f, 256) + ib.buf += os.read(f, 256).decode('utf-8') # Split input at line break sep = True -- cgit v1.2.3-70-g09d2 From d7975feaea007f7e190a1c4cf2ad0d63fea4752f Mon Sep 17 00:00:00 2001 From: TingPing Date: Sun, 29 Dec 2013 20:14:14 -0500 Subject: Update icon cache on install --- Makefile.am | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Makefile.am b/Makefile.am index 000076f..f3109ed 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,6 +2,8 @@ SUBDIRS = src po ACLOCAL_AMFLAGS = -I m4 +UPDATE_ICON_CACHE = gtk-update-icon-cache -f -t $(datadir)/icons/hicolor || : + EXTRA_ROOTDOC_FILES = \ HACKING \ DESIGN \ @@ -45,6 +47,14 @@ desktopdir = @datadir@/applications desktop_DATA = $(_DESKTOP_FILES) endif +if ENABLE_GUI +install-data-hook: + $(UPDATE_ICON_CACHE); + +uninstall-hook: + $(UPDATE_ICON_CACHE); +endif + # man page dist_man1_MANS = redshift.1 -- cgit v1.2.3-70-g09d2 From 635e192fb7e672f661c377051efd55c99deffeb8 Mon Sep 17 00:00:00 2001 From: TingPing Date: Mon, 30 Dec 2013 00:28:04 -0500 Subject: Update .gitignore --- .gitignore | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9c72138..fddec06 100644 --- a/.gitignore +++ b/.gitignore @@ -16,11 +16,13 @@ *.exe *.out *.app - +src/redshift* # autotools /autom4te.cache Makefile.in +Makefile +stamp-h1 /config.* /ABOUT-NLS /aclocal.m4 @@ -29,8 +31,18 @@ Makefile.in /install-sh /missing /py-compile +/compile +*.deps/ +/m4/ + +# generated files +src/redshift-gtk/defs.py +src/redshift-gtk/redshift-gtk +contrib/redshift.spec # gettext +/po/POTFILES +/po/stamp-po /po/*.gmo /po/Makefile.in.in /po/Rules-quot -- cgit v1.2.3-70-g09d2 From 5340f2eb408c00180c91695f391e9fe354df754d Mon Sep 17 00:00:00 2001 From: TingPing Date: Mon, 30 Dec 2013 01:27:55 -0500 Subject: Fix PyGI deprecated warnings --- src/redshift-gtk/statusicon.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/redshift-gtk/statusicon.py b/src/redshift-gtk/statusicon.py index 626b9e3..6174aec 100644 --- a/src/redshift-gtk/statusicon.py +++ b/src/redshift-gtk/statusicon.py @@ -78,24 +78,24 @@ class RedshiftStatusIcon(object): self.status_menu = Gtk.Menu() # Add toggle action - toggle_item = Gtk.MenuItem(_('Toggle')) + toggle_item = Gtk.MenuItem.new_with_label(_('Toggle')) toggle_item.connect('activate', self.toggle_cb) self.status_menu.append(toggle_item) # Add suspend menu - suspend_menu_item = Gtk.MenuItem(_('Suspend for')) + suspend_menu_item = Gtk.MenuItem.new_with_label(_('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 = Gtk.MenuItem.new_with_label(label) suspend_item.connect('activate', self.suspend_cb, minutes) suspend_menu.append(suspend_item) suspend_menu_item.set_submenu(suspend_menu) self.status_menu.append(suspend_menu_item) # Add autostart option - autostart_item = Gtk.CheckMenuItem(_('Autostart')) + autostart_item = Gtk.CheckMenuItem.new_with_label(_('Autostart')) try: autostart_item.set_active(utils.get_autostart()) except IOError as strerror: @@ -107,19 +107,19 @@ class RedshiftStatusIcon(object): self.status_menu.append(autostart_item) # Add info action - info_item = Gtk.MenuItem(_('Info')) + info_item = Gtk.MenuItem.new_with_label(_('Info')) info_item.connect('activate', self.show_info_cb) self.status_menu.append(info_item) # Add quit action - quit_item = Gtk.ImageMenuItem(_('Quit')) + quit_item = Gtk.ImageMenuItem.new_with_label(_('Quit')) quit_item.connect('activate', self.destroy_cb) self.status_menu.append(quit_item) # Create info dialog - self.info_dialog = Gtk.Dialog(_('Info'), - None, 0, - (_('Close'), Gtk.ResponseType.CLOSE)) + self.info_dialog = Gtk.Dialog() + self.info_dialog.set_title(_('Info')) + self.info_dialog.add_button(_('Close'), Gtk.ButtonsType.CLOSE) self.info_dialog.set_resizable(False) self.info_dialog.set_property('border-width', 6) @@ -175,10 +175,10 @@ class RedshiftStatusIcon(object): fcntl.fcntl(self.process[2], fcntl.F_GETFL) | os.O_NONBLOCK) # Add watch on child process - GLib.child_watch_add(self.process[0], self.child_cb) - GLib.io_add_watch(self.process[2], GLib.IO_IN, + GLib.child_watch_add(GLib.PRIORITY_DEFAULT, self.process[0], self.child_cb) + GLib.io_add_watch(self.process[2], GLib.PRIORITY_DEFAULT, GLib.IO_IN, self.child_data_cb, (True, self.input_buffer)) - GLib.io_add_watch(self.process[3], GLib.IO_IN, + GLib.io_add_watch(self.process[3], GLib.PRIORITY_DEFAULT, GLib.IO_IN, self.child_data_cb, (False, self.error_buffer)) def start_child_process(self, args): -- cgit v1.2.3-70-g09d2