laditools/laditray

99 lines
3.9 KiB
Python
Executable File

#!/usr/bin/env python
# LADITools - Linux Audio Desktop Integration Tools
# laditray - System tray integration for LADI
# Copyright (C) 2007-2008, Marc-Olivier Barre and Nedko Arnaudov.
#
# This program 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.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
import pygtk
pygtk.require('2.0')
import gtk
from gobject import timeout_add
import laditools
# Default configuration
autostart_default = 0
class laditray (gtk.StatusIcon, laditools.manager):
def __init__ (self):
# Handle the configuration
self.jacktray_config = laditools.config ()
self.param_dict = self.jacktray_config.get_as_dict ('jacktray')
if 'autostart' not in self.param_dict:
self.param_dict['autostart'] = str(autostart_default), {}
autostart, devnull = self.param_dict['autostart']
# Build the UI
laditools.manager.__init__(self, int(autostart))
gtk.StatusIcon.__init__ (self)
# Create the needed pixbufs to manage the status icon's look
self.stopped_pixbuf = gtk.gdk.pixbuf_new_from_file(laditools.find_data_file("stopped.svg"))
self.starting_pixbuf = gtk.gdk.pixbuf_new_from_file(laditools.find_data_file("starting.svg"))
self.started_pixbuf = gtk.gdk.pixbuf_new_from_file(laditools.find_data_file("started.svg"))
self.set_from_pixbuf (self.stopped_pixbuf)
# Get the initial status
self.update ()
# Add the auto update callback
self.auto_updater = timeout_add (250, self.update)
# Make the menu popup when the icon is right clicked
self.connect ("popup-menu", self.menu_activate)
def menu_activate (self, statusicon, button, activate_time):
menu = self.create_menu()
menu.popup (None, None, gtk.status_icon_position_menu, button, activate_time, self)
menu.reposition ()
def set_starting_status (self):
self.set_tooltip ("JACK is starting")
self.set_from_pixbuf (self.starting_pixbuf)
def update (self):
try:
if self.jack_is_started():
# Get Realtime status
if self.jack_is_realtime():
status_text = "RT | "
# Get DSP Load
status_text += str (round (float (self.jack_get_load()),1)) + "% | "
# Get Xruns
status_text += str (self.jack_get_xruns())
# Set a started status
self.set_tooltip (status_text)
self.set_from_pixbuf (self.started_pixbuf)
else:
self.set_tooltip ("JACK is stopped")
self.set_from_pixbuf (self.stopped_pixbuf)
self.clear_diagnose_text()
except Exception, e:
self.set_tooltip ("JACK is sick")
self.set_diagnose_text(repr(e))
self.set_from_pixbuf (self.stopped_pixbuf)
self.clear_jack_proxies()
# Take a look at the processes we've started so we don't get any zombies
for i in self.proc_list:
i.poll ()
return True
def run(self):
gtk.main ()
self.jacktray_config.set_as_dict ('jacktray', self.param_dict)
return 0
try:
laditray().run()
except Exception, e:
error = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "Unexpected error\n\n" + repr(e))
error.run()
exit(1)