laditools/jacktray

100 lines
3.8 KiB
Python
Executable File

#!/usr/bin/env python
# pyjackctl - The python jackdbus controller suite
# jackctl_trayicon - System tray integration for jackdbus
# 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 jacktray(gtk.StatusIcon, pyjackctl.jack_menu):
def __init__(self):
# Handle the configuration
self.jacktray_config = pyjackctl.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), {}
self.autostart, devnull = self.param_dict['autostart']
self.autostart = int(self.autostart)
# Build the UI
pyjackctl.jack_menu.__init__(self)
gtk.StatusIcon.__init__(self)
self.jack = pyjackctl.jack_controller()
if self.autostart:
self.jack.start()
# Create the needed pixbufs to manage the status icon's look
self.stopped_pixbuf = gtk.gdk.pixbuf_new_from_file("/usr/share/pyjackctl/data/stopped.svg")
self.starting_pixbuf = gtk.gdk.pixbuf_new_from_file("/usr/share/pyjackctl/data/starting.svg")
self.started_pixbuf = gtk.gdk.pixbuf_new_from_file("/usr/share/pyjackctl/data/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):
self.menu.popup(None, None, gtk.status_icon_position_menu, button, activate_time, self)
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 not self.jack:
self.jack = pyjackctl.jack_controller()
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)
except:
self.set_tooltip("JACK is sick")
self.set_from_pixbuf(self.stopped_pixbuf)
self.jack = None
# 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
def get_controller(self):
return self.jack
jacktray().run()