Optimize indicators code.
User, at configure time, chooses to enable or disable the gui. Determine at runtime whether to use the appindicator or status icon as fallback.
This commit is contained in:
+13
-38
@@ -131,50 +131,25 @@ AS_IF([test "x$enable_gnome_clock" != xno], [
|
||||
])
|
||||
AM_CONDITIONAL([ENABLE_GNOME_CLOCK], [test "x$enable_gnome_clock" = xyes])
|
||||
|
||||
|
||||
# Check for GUI
|
||||
# There doesn't seem to be an easy way of detecting the presence
|
||||
# of a python module. For that reason, statusicon is the default GUI.
|
||||
AC_MSG_CHECKING([which GUI to enable])
|
||||
# Check for AppIndicator or GTK+ status icon
|
||||
AC_MSG_CHECKING([whether to enable AppIndicator or GTK status icon])
|
||||
AC_ARG_ENABLE([gui], [AC_HELP_STRING([--enable-gui],
|
||||
[enable GUI (appindicator, statusicon or none)])],
|
||||
[enable AppIndicator or GTK status icon])],
|
||||
[enable_gui=$enableval],[enable_gui=maybe])
|
||||
|
||||
# Statusicon GUI
|
||||
AS_IF([test "x$enable_gui" = xstatusicon -o "x$enable_gui" = xmaybe], [
|
||||
AS_IF([test "x$have_python" != xyes], [
|
||||
AS_IF([test "x$enable_gui" = xstatusicon], [
|
||||
AC_MSG_ERROR([status icon script requires Python 2.6])
|
||||
])
|
||||
enable_gui=maybe
|
||||
AS_IF([test "x$enable_gui" != xno], [
|
||||
AS_IF([test $have_python = yes], [
|
||||
AC_MSG_RESULT([yes])
|
||||
], [
|
||||
enable_gui=statusicon
|
||||
])
|
||||
])
|
||||
|
||||
# Appindicator GUI
|
||||
AS_IF([test "x$enable_gui" = xappindicator -o "x$enable_gui" = xmaybe], [
|
||||
AS_IF([test "x$have_python" != xyes], [
|
||||
AS_IF([test "x$enable_gui" = xappindicator], [
|
||||
AC_MSG_ERROR([application indicator script requires Python 2.6])
|
||||
AC_MSG_RESULT([missing dependencies])
|
||||
AS_IF([test "x$enable_gui" = xyes], [
|
||||
AC_MSG_ERROR([appindicator and status icon script requires Python 2.6])
|
||||
])
|
||||
enable_gui=maybe
|
||||
], [
|
||||
enable_gui=appindicator
|
||||
enable_gui=no
|
||||
])
|
||||
], [
|
||||
AC_MSG_RESULT([no])
|
||||
])
|
||||
|
||||
# Fall back to no GUI
|
||||
AS_IF([test "x$enable_gui" != xappindicator -a "x$enable_gui" != xstatusicon], [
|
||||
enable_gui=none
|
||||
])
|
||||
|
||||
AC_MSG_RESULT([$enable_gui])
|
||||
|
||||
AM_CONDITIONAL([ENABLE_GUI], [test "x$enable_gui" != xnone])
|
||||
AM_CONDITIONAL([ENABLE_STATUSICON], [test "x$enable_gui" = xstatusicon])
|
||||
AM_CONDITIONAL([ENABLE_APPINDICATOR], [test "x$enable_gui" = xappindicator])
|
||||
|
||||
AM_CONDITIONAL([ENABLE_GUI], [test "x$enable_gui" != xno])
|
||||
|
||||
# Checks for header files.
|
||||
AC_CHECK_HEADERS([locale.h stdint.h stdlib.h string.h unistd.h sys/signal.h])
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
|
||||
if ENABLE_STATUSICON
|
||||
gui_module=statusicon
|
||||
if ENABLE_GUI
|
||||
gtk_redshift_PYTHON = \
|
||||
__init__.py \
|
||||
utils.py \
|
||||
@@ -9,32 +8,12 @@ nodist_gtk_redshift_PYTHON = \
|
||||
defs.py
|
||||
gtk_redshiftdir = $(pythondir)/gtk_redshift
|
||||
|
||||
bin_SCRIPTS = gtk-redshift
|
||||
dist_bin_SCRIPTS = gtk-redshift
|
||||
endif
|
||||
|
||||
if ENABLE_APPINDICATOR
|
||||
gui_module=rsappindicator
|
||||
gtk_redshift_PYTHON = \
|
||||
__init__.py \
|
||||
utils.py \
|
||||
rsappindicator.py
|
||||
nodist_gtk_redshift_PYTHON = \
|
||||
defs.py
|
||||
gtk_redshiftdir = $(pythondir)/gtk_redshift
|
||||
EXTRA_DIST = defs.py.in
|
||||
|
||||
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" $< > $@
|
||||
CLEANFILES = defs.py
|
||||
|
||||
# Local python definitions
|
||||
defs.py: defs.py.in
|
||||
|
||||
@@ -19,5 +19,5 @@
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from gtk_redshift.@gui_module@ import run
|
||||
from gtk_redshift.statusicon import run
|
||||
run()
|
||||
@@ -1,114 +0,0 @@
|
||||
#!/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
|
||||
import utils
|
||||
|
||||
|
||||
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 autostart_cb(widget, data=None):
|
||||
utils.set_autostart(widget.get_active())
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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()
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# statusicon.py -- GTK+ status icon source
|
||||
# statusicon.py -- Application panel indicator / GTK+ status icon source
|
||||
# This file is part of Redshift.
|
||||
|
||||
# Redshift is free software: you can redistribute it and/or modify
|
||||
@@ -26,6 +26,10 @@ import pygtk
|
||||
pygtk.require("2.0")
|
||||
|
||||
import gtk, glib
|
||||
try:
|
||||
import appindicator
|
||||
except ImportError:
|
||||
appindicator = None
|
||||
|
||||
import defs
|
||||
import utils
|
||||
@@ -43,23 +47,37 @@ def run():
|
||||
process = subprocess.Popen(args)
|
||||
|
||||
try:
|
||||
# Create status icon
|
||||
status_icon = gtk.StatusIcon()
|
||||
status_icon.set_from_icon_name('redshift')
|
||||
status_icon.set_tooltip('Redshift')
|
||||
if appindicator:
|
||||
# Create indicator
|
||||
indicator = appindicator.Indicator ("redshift",
|
||||
"redshift",
|
||||
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_icon.set_tooltip('Redshift')
|
||||
|
||||
def toggle_cb(widget, data=None):
|
||||
process.send_signal(signal.SIGUSR1)
|
||||
if status_icon.get_icon_name() == 'redshift':
|
||||
status_icon.set_from_icon_name('redshift-idle')
|
||||
else:
|
||||
status_icon.set_from_icon_name('redshift')
|
||||
if appindicator:
|
||||
if indicator.get_icon() == 'redshift':
|
||||
indicator.set_icon('redshift-idle')
|
||||
else:
|
||||
indicator.set_icon('redshift')
|
||||
else:
|
||||
if status_icon.get_icon_name() == 'redshift':
|
||||
status_icon.set_from_icon_name('redshift-idle')
|
||||
else:
|
||||
status_icon.set_from_icon_name('redshift')
|
||||
|
||||
def autostart_cb(widget, data=None):
|
||||
utils.set_autostart(widget.get_active())
|
||||
|
||||
def destroy_cb(widget, data=None):
|
||||
status_icon.set_visible(False)
|
||||
if not appindicator:
|
||||
status_icon.set_visible(False)
|
||||
gtk.main_quit()
|
||||
return False
|
||||
|
||||
@@ -85,15 +103,21 @@ def run():
|
||||
quit_item.connect('activate', destroy_cb)
|
||||
status_menu.append(quit_item)
|
||||
|
||||
def popup_menu_cb(widget, button, time, data=None):
|
||||
if appindicator:
|
||||
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)
|
||||
# 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)
|
||||
|
||||
Reference in New Issue
Block a user