laditools/ladi-system-tray

174 lines
6.9 KiB
Plaintext
Raw Normal View History

2011-12-08 12:18:14 +02:00
#!/usr/bin/python
# 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>
# Copyright (C) 2007-2010, Marc-Olivier Barre <marco@marcochapeau.org>
# Copyright (C) 2007-2009, Nedko Arnaudov <nedko@arnaudov.name>
#
# 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/>.
2011-12-08 18:08:25 +02:00
import os
import sys
2012-03-03 15:41:17 +02:00
import signal
import gettext
2012-03-03 13:00:50 +02:00
import argparse
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)
from laditools import _gettext_domain
gettext.install(_gettext_domain)
2012-03-03 13:00:50 +02:00
from laditools import get_version_string
from laditools import LadiConfiguration
2012-03-15 15:11:03 +02:00
from laditools import LadiManager
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GdkPixbuf
from gi.repository import GObject
from laditools.gtk import LadiMenu
from laditools.gtk import find_data_file
timeout_add = GObject.timeout_add
class laditray (Gtk.StatusIcon, LadiMenu):
# Default configuration
_default_config = {
'autostart' : False,
}
def do_button_press_event(self, event):
if event.type != Gdk.EventType._2BUTTON_PRESS:
return False
self.on_menu_launcher(None, "gladish")
return True
def __init__ (self):
# Handle the configuration
self.global_config = LadiConfiguration(laditray = self._default_config)
self.laditray_param_dict = self.global_config.get_config_section ('laditray')
autostart = bool(eval(self.laditray_param_dict['autostart']))
# Build the UI
LadiMenu.__init__(self, self.global_config.get_config_section ('ladimenu'), autostart)
2011-12-16 20:59:22 +02:00
GObject.GObject.__init__ (self)
self.icon_state = ""
self.last_status_text = ""
# Create the needed pixbufs to manage the status icon's look
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"))
self.set_icon ("stopped")
# Get the initial status
self.update ()
# Add the auto update callback
self.auto_updater = timeout_add (250, self.update, None)
# Make the menu popup when the icon is right clicked
self.connect ("popup-menu", self.menu_activate)
2012-03-16 21:16:40 +02:00
self.set_title(_("LADI System Tray"))
2011-12-16 20:59:22 +02:00
def menu_activate(self, status_icon, button, activate_time, user_data=None):
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)
menu.reposition ()
def set_starting_status (self):
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)
self.last_status_text = text
def update (self, user_data = None):
try:
if self.jack_is_started():
# Get Realtime status
if self.jack_is_realtime():
status_text = "RT | "
else:
status_text = ""
# 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_safe (status_text)
self.set_icon ("started")
else:
self.set_tooltip_safe ("JACK is stopped")
self.set_icon ("stopped")
self.clear_diagnose_text()
except Exception, e:
self.set_tooltip_safe ("JACK is sick")
self.set_diagnose_text(repr(e))
self.set_icon ("stopped")
self.clear_jack_proxies()
2012-03-15 15:11:03 +02:00
finally:
LadiManager.update(self)
return True
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"))
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"])
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()
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.
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 ()
return 0
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)