2011-12-08 12:18:14 +02:00
#!/usr/bin/python
2008-08-13 13:03:04 +03:00
# LADITools - Linux Audio Desktop Integration Tools
2012-03-16 21:16:40 +02:00
# ladi-system-tray - System tray integration for LADI
2012-02-23 21:01:16 +02:00
# Copyright (C) 2011-2012 Alessio Treglia <quadrispro@ubuntu.com>
2010-01-07 21:18:24 +02:00
# Copyright (C) 2007-2010, Marc-Olivier Barre <marco@marcochapeau.org>
# Copyright (C) 2007-2009, Nedko Arnaudov <nedko@arnaudov.name>
2007-12-15 17:27:42 +02:00
#
2007-12-21 19:40:55 +02:00
# This program is free software: you can redistribute it and/or modify
2007-12-15 17:27:42 +02:00
# it under the terms of the GNU General Public License as published by
2007-12-21 19:40:55 +02:00
# the Free Software Foundation, either version 3 of the License, or
2007-12-15 17:27:42 +02:00
# (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
2007-12-21 19:40:55 +02:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2007-12-15 17:27:42 +02:00
2011-12-08 18:08:25 +02:00
import os
import sys
2012-03-03 15:41:17 +02:00
import signal
2012-03-02 02:53:57 +02:00
import gettext
2012-03-03 13:00:50 +02:00
import argparse
2011-12-08 02:50:44 +02:00
2012-03-03 16:02:06 +02:00
sig_handler = signal.getsignal(signal.SIGTERM)
2012-03-03 15:41:17 +02:00
signal.signal(signal.SIGINT, sig_handler)
2012-03-02 02:53:57 +02:00
from laditools import _gettext_domain
gettext.install(_gettext_domain)
2012-03-03 13:00:50 +02:00
from laditools import get_version_string
2012-03-02 02:53:57 +02:00
from laditools import LadiConfiguration
2012-03-15 15:11:03 +02:00
from laditools import LadiManager
2012-03-02 02:53:57 +02:00
from gi.repository import Gtk
2012-03-16 21:52:35 +02:00
from gi.repository import Gdk
2012-03-02 02:53:57 +02:00
from gi.repository import GdkPixbuf
from gi.repository import GObject
2012-03-14 21:38:28 +02:00
from laditools.gtk import LadiMenu
2012-03-08 23:38:07 +02:00
from laditools.gtk import find_data_file
2012-03-02 02:53:57 +02:00
timeout_add = GObject.timeout_add
2007-12-15 17:27:42 +02:00
2012-03-14 21:38:28 +02:00
class laditray (Gtk.StatusIcon, LadiMenu):
2012-03-11 15:09:35 +02:00
# Default configuration
_default_config = {
'autostart' : False,
}
2012-03-16 21:52:35 +02:00
def do_button_press_event(self, event):
if event.type != Gdk.EventType._2BUTTON_PRESS:
return False
self.on_menu_launcher(None, "gladish")
return True
2008-08-13 13:03:04 +03:00
def __init__ (self):
2008-02-05 22:46:44 +02:00
# Handle the configuration
2012-03-11 15:09:35 +02:00
self.global_config = LadiConfiguration(laditray = self._default_config)
2009-12-28 21:52:35 +02:00
self.laditray_param_dict = self.global_config.get_config_section ('laditray')
2012-03-11 15:09:35 +02:00
autostart = bool(eval(self.laditray_param_dict['autostart']))
2008-02-05 22:46:44 +02:00
# Build the UI
2012-03-14 21:38:28 +02:00
LadiMenu.__init__(self, self.global_config.get_config_section ('ladimenu'), autostart)
2011-12-16 20:59:22 +02:00
GObject.GObject.__init__ (self)
2009-02-01 11:46:39 +02:00
self.icon_state = ""
self.last_status_text = ""
2007-12-25 02:13:58 +02:00
# Create the needed pixbufs to manage the status icon's look
2012-03-02 02:53:57 +02:00
self.stopped_pixbuf = GdkPixbuf.Pixbuf.new_from_file(find_data_file("stopped.svg"))
self.starting_pixbuf = GdkPixbuf.Pixbuf.new_from_file(find_data_file("starting.svg"))
self.started_pixbuf = GdkPixbuf.Pixbuf.new_from_file(find_data_file("started.svg"))
2009-02-01 11:46:39 +02:00
self.set_icon ("stopped")
2007-12-25 02:13:58 +02:00
# Get the initial status
2008-08-13 13:03:04 +03:00
self.update ()
2007-12-25 02:13:58 +02:00
# Add the auto update callback
2012-03-08 23:43:31 +02:00
self.auto_updater = timeout_add (250, self.update, None)
2007-12-25 02:13:58 +02:00
# Make the menu popup when the icon is right clicked
2008-08-13 13:03:04 +03:00
self.connect ("popup-menu", self.menu_activate)
2012-03-16 21:16:40 +02:00
self.set_title(_("LADI System Tray"))
2007-12-19 20:12:29 +02:00
2011-12-16 20:59:22 +02:00
def menu_activate(self, status_icon, button, activate_time, user_data=None):
2008-09-12 15:35:52 +03:00
menu = self.create_menu()
2011-12-16 20:59:22 +02:00
menu.popup (parent_menu_shell=None,
parent_menu_item=None,
func=self.position_menu,
data=self,
button=button,
activate_time=activate_time)
2008-09-12 15:35:52 +03:00
menu.reposition ()
2007-12-19 20:12:29 +02:00
2008-08-13 13:03:04 +03:00
def set_starting_status (self):
2009-02-01 11:46:39 +02:00
self.set_tooltip_safe ("JACK is starting")
self.set_icon ("starting")
def set_icon (self, newstate):
if self.icon_state == newstate:
return
self.icon_state = newstate
if newstate == "stopped": self.set_from_pixbuf (self.stopped_pixbuf)
if newstate == "started": self.set_from_pixbuf (self.started_pixbuf)
if newstate == "starting": self.set_from_pixbuf (self.starting_pixbuf)
def set_tooltip_safe (self, text):
if text != self.last_status_text:
2011-12-16 20:59:22 +02:00
self.set_tooltip_text (text)
2009-02-01 11:46:39 +02:00
self.last_status_text = text
2008-01-08 20:27:23 +02:00
2012-03-08 23:43:31 +02:00
def update (self, user_data = None):
2007-12-25 02:13:58 +02:00
try:
2008-12-12 20:35:09 +02:00
if self.jack_is_started():
2007-12-25 02:13:58 +02:00
# Get Realtime status
2008-09-12 15:35:52 +03:00
if self.jack_is_realtime():
2007-12-25 02:13:58 +02:00
status_text = "RT | "
2010-04-11 13:48:55 +03:00
else:
status_text = ""
2007-12-25 02:13:58 +02:00
# Get DSP Load
2008-09-12 15:35:52 +03:00
status_text += str (round (float (self.jack_get_load()),1)) + "% | "
2007-12-25 02:13:58 +02:00
# Get Xruns
2008-09-12 15:35:52 +03:00
status_text += str (self.jack_get_xruns())
2007-12-25 02:13:58 +02:00
# Set a started status
2009-02-01 11:46:39 +02:00
self.set_tooltip_safe (status_text)
self.set_icon ("started")
2008-12-12 20:35:09 +02:00
else:
2009-02-01 11:46:39 +02:00
self.set_tooltip_safe ("JACK is stopped")
self.set_icon ("stopped")
2008-09-12 15:35:52 +03:00
self.clear_diagnose_text()
except Exception, e:
2009-02-01 11:46:39 +02:00
self.set_tooltip_safe ("JACK is sick")
2008-09-12 15:35:52 +03:00
self.set_diagnose_text(repr(e))
2009-02-01 11:46:39 +02:00
self.set_icon ("stopped")
2008-09-16 10:54:22 +03:00
self.clear_jack_proxies()
2012-03-15 15:11:03 +02:00
finally:
LadiManager.update(self)
2007-12-25 02:13:58 +02:00
return True
2007-12-18 18:11:07 +02:00
2012-03-09 09:48:17 +02:00
def on_about(self, *args):
logo_pixbuf = GdkPixbuf.Pixbuf.new_from_file(find_data_file("laditools_logo.svg"))
2012-03-09 11:52:13 +02:00
copyright_str = u"""Copyright \xa9 2011-2012 Alessio Treglia <quadrispro@ubuntu.com>
Copyright \xa9 2007-2010 Marc-Olivier Barre <marco@marcochapeau.org>
Copyright \xa9 2007-2010 Nedko Arnaudov <nedko@arnaudov.name>"""
2012-03-09 09:48:17 +02:00
ad = Gtk.AboutDialog.new()
ad.set_program_name("LADITools")
2012-03-09 09:51:04 +02:00
ad.set_comments(_("LADITools is a set of tools aiming to achieve the goals of the LADI project to improve desktop integration and user workflow of Linux audio system based on JACK and ladish."))
2012-03-09 09:48:17 +02:00
ad.set_logo(logo_pixbuf)
ad.set_authors(["Marc-Olivier Barre", "Nedko Arnaudov", "Alessio Treglia"])
2012-03-09 11:52:13 +02:00
ad.set_copyright(copyright_str)
2012-03-09 09:48:17 +02:00
ad.set_version(get_version_string())
ad.set_license_type( Gtk.License.GPL_3_0)
ad.set_translator_credits(_("translator-credits"))
ad.set_website("https://launchpad.net/laditools/")
ad.run()
ad.destroy()
2007-12-25 02:13:58 +02:00
def run(self):
2011-12-16 20:59:22 +02:00
Gtk.main ()
2011-12-07 23:22:26 +02:00
# Some default config might need to be injected in the config file,
# we handle all that before we quit.
2009-12-28 21:52:35 +02:00
self.global_config.set_config_section ('ladimenu', self.menu_array)
2011-12-07 23:22:26 +02:00
self.global_config.set_config_section ('laditray', self.laditray_param_dict)
self.global_config.save ()
2007-12-25 02:13:58 +02:00
return 0
2007-12-15 17:27:42 +02:00
2012-03-03 13:00:50 +02:00
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=_('system tray icon that allows users to start, stop and'
'monitor JACK, as well as start some JACK related applications'),
epilog=_('This program is part of the LADITools suite.'))
parser.add_argument('--version', action='version', version="%(prog)s " + get_version_string())
parser.parse_args()
laditray().run()
sys.exit(0)