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-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-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-19 03:10:08 +02:00
|
|
|
from laditools import LadiApp
|
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 GObject
|
2012-03-19 03:10:08 +02:00
|
|
|
|
2012-03-18 02:26:04 +02:00
|
|
|
try:
|
|
|
|
from gi.repository import AppIndicator3
|
|
|
|
except:
|
|
|
|
AppIndicator3 = None
|
|
|
|
|
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-19 03:10:08 +02:00
|
|
|
class LadiStatusIcon (LadiMenu, LadiApp):
|
|
|
|
|
|
|
|
_appname = 'ladi-system-tray'
|
|
|
|
_appname_long = _("LADI System Tray")
|
|
|
|
_appid = 'org.linuxaudio.ladi.systemtray'
|
2012-03-11 15:09:35 +02:00
|
|
|
|
|
|
|
# Default configuration
|
|
|
|
_default_config = {
|
|
|
|
'autostart' : False,
|
|
|
|
}
|
|
|
|
|
2012-03-16 22:08:17 +02:00
|
|
|
def on_about(self, *args):
|
|
|
|
LadiMenu.on_about(self, version=get_version_string())
|
|
|
|
|
2012-03-20 09:32:14 +02:00
|
|
|
def quit(self, *args, **kwargs):
|
|
|
|
# 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 (self.appname, self.config_dict)
|
|
|
|
self.global_config.save ()
|
|
|
|
Gtk.main_quit()
|
|
|
|
|
2012-03-18 02:26:04 +02:00
|
|
|
def set_tooltip_text(self, text): pass
|
|
|
|
|
2012-03-19 03:10:08 +02:00
|
|
|
def __init__ (self, config_filename = None):
|
2008-02-05 22:46:44 +02:00
|
|
|
# Handle the configuration
|
2012-03-18 02:26:04 +02:00
|
|
|
self.icon_state = ""
|
|
|
|
self.last_status_text = ""
|
|
|
|
self.diagnose_text = None
|
2012-03-19 13:34:07 +02:00
|
|
|
self.status_icons = {'started' : 'ladi-started',
|
|
|
|
'stopped' : 'ladi-stopped',
|
|
|
|
'starting' : 'ladi-starting'}
|
2012-03-19 03:10:08 +02:00
|
|
|
self.global_config = LadiConfiguration(self.appname,
|
|
|
|
self._default_config,
|
|
|
|
config_filename)
|
|
|
|
self.config_dict = self.global_config.get_config_section (self.appname)
|
|
|
|
autostart = bool(eval(self.config_dict['autostart']))
|
2008-02-05 22:46:44 +02:00
|
|
|
# Build the UI
|
2012-03-20 09:32:14 +02:00
|
|
|
LadiMenu.__init__(self,
|
|
|
|
autostart,
|
|
|
|
quit = self.quit)
|
2012-03-20 14:34:07 +02:00
|
|
|
LadiApp.__init__(self)
|
|
|
|
self.connect_signals_quit()
|
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")
|
|
|
|
|
2012-03-18 02:26:04 +02:00
|
|
|
def set_tooltip_safe (self, text):
|
|
|
|
if text != self.last_status_text:
|
|
|
|
self.set_tooltip_text (text)
|
|
|
|
self.last_status_text = text
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
Gtk.main ()
|
|
|
|
|
|
|
|
class LadiStatusTray(Gtk.StatusIcon, LadiStatusIcon):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
LadiStatusIcon.__init__(self)
|
|
|
|
GObject.GObject.__init__ (self)
|
|
|
|
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-19 03:10:08 +02:00
|
|
|
self.set_title(self.appname_long)
|
2012-03-18 02:26:04 +02:00
|
|
|
|
2012-03-18 16:27:46 +02:00
|
|
|
def do_button_press_event(self, event):
|
|
|
|
if event.type != Gdk.EventType._2BUTTON_PRESS:
|
|
|
|
return False
|
|
|
|
self.on_menu_launch_handler(None, "gladish")
|
|
|
|
return True
|
|
|
|
|
2012-03-18 02:26:04 +02:00
|
|
|
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()
|
2023-07-20 01:11:25 +03:00
|
|
|
except Exception as e:
|
2012-03-18 02:26:04 +02:00
|
|
|
self.set_tooltip_safe ("JACK is sick")
|
|
|
|
self.set_diagnose_text(repr(e))
|
|
|
|
self.set_icon ("stopped")
|
|
|
|
self.clear_jack_proxies()
|
|
|
|
finally:
|
|
|
|
LadiManager.update(self)
|
|
|
|
return True
|
|
|
|
|
2009-02-01 11:46:39 +02:00
|
|
|
def set_icon (self, newstate):
|
|
|
|
if self.icon_state == newstate:
|
|
|
|
return
|
|
|
|
self.icon_state = newstate
|
2012-03-19 13:34:07 +02:00
|
|
|
self.set_from_icon_name(self.status_icons[newstate])
|
2009-02-01 11:46:39 +02:00
|
|
|
|
2012-03-18 02:26:04 +02:00
|
|
|
class LadiStatusIndicator(LadiStatusIcon):
|
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()
|
2021-02-14 23:59:34 +02:00
|
|
|
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-18 02:26:04 +02:00
|
|
|
def set_icon (self, newstate):
|
|
|
|
if self.icon_state == newstate:
|
|
|
|
return
|
|
|
|
self.icon_state = newstate
|
2012-03-19 13:34:07 +02:00
|
|
|
self.indicator.set_icon(self.status_icons[newstate])
|
2012-03-18 02:26:04 +02:00
|
|
|
|
2012-03-18 16:03:49 +02:00
|
|
|
def create_menu(self):
|
|
|
|
menu_items = []
|
|
|
|
|
|
|
|
ladish_available = self.ladish_is_available()
|
|
|
|
|
|
|
|
menu_items.append((Gtk.ImageMenuItem(_("LADI Player")), self.on_menu_launch_handler, "ladi-player"))
|
|
|
|
if ladish_available:
|
|
|
|
menu_items.append((Gtk.ImageMenuItem(_("Session editor")), self.on_menu_launch_handler, "gladish"))
|
|
|
|
|
|
|
|
menu_items.append((Gtk.SeparatorMenuItem.new(),))
|
|
|
|
menu_items.append((Gtk.ImageMenuItem(_("Settings")), self.on_menu_launch_handler, "ladi-control-center"))
|
|
|
|
menu_items.append((Gtk.ImageMenuItem(_("Log Viewer")), self.on_menu_launch_handler, "ladi-system-log"))
|
|
|
|
|
|
|
|
menu_items.append((Gtk.SeparatorMenuItem.new(),))
|
|
|
|
if hasattr(self, 'on_about'):
|
|
|
|
menu_items.append((Gtk.ImageMenuItem(_("About")), self.on_about, None))
|
2012-03-20 09:32:14 +02:00
|
|
|
menu_items.append((Gtk.ImageMenuItem(_("Quit")), self.on_menu_command, self.quit))
|
2012-03-18 16:03:49 +02:00
|
|
|
|
|
|
|
menu = Gtk.Menu()
|
|
|
|
for menu_tuple in menu_items:
|
|
|
|
item = menu_tuple[0]
|
|
|
|
if len(menu_tuple) > 1:
|
|
|
|
callback = menu_tuple[1]
|
|
|
|
exec_path = menu_tuple[2]
|
|
|
|
menu.append(item)
|
|
|
|
if type(item) is not Gtk.SeparatorMenuItem:
|
|
|
|
if callback in (self.studio_list_fill, self.configure_list_fill):
|
|
|
|
item.set_submenu(Gtk.Menu())
|
|
|
|
item.connect("activate", callback, exec_path)
|
|
|
|
menu.show_all()
|
|
|
|
return menu
|
|
|
|
|
|
|
|
|
2012-03-18 02:26:04 +02:00
|
|
|
def __init__(self):
|
|
|
|
LadiStatusIcon.__init__(self)
|
|
|
|
self.indicator = indicator = AppIndicator3.Indicator.new('ladi-indicator',
|
|
|
|
find_data_file('scalable/apps/laditools.svg'),
|
|
|
|
AppIndicator3.IndicatorCategory.APPLICATION_STATUS)
|
|
|
|
self.menu = menu = self.create_menu()
|
|
|
|
|
|
|
|
indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
|
|
|
|
indicator.set_menu(menu)
|
|
|
|
menu.show()
|
|
|
|
# Get the initial status
|
|
|
|
self.update ()
|
|
|
|
# Add the auto update callback
|
|
|
|
self.auto_updater = timeout_add (250, self.update, None)
|
2007-12-15 17:27:42 +02:00
|
|
|
|
2012-03-03 13:00:50 +02:00
|
|
|
if __name__ == "__main__":
|
2012-04-12 11:07:56 +03:00
|
|
|
parser = argparse.ArgumentParser(description=_('system tray icon that allows users to start, stop and '
|
2012-03-03 13:00:50 +02:00
|
|
|
'monitor JACK, as well as start some JACK related applications'),
|
|
|
|
epilog=_('This program is part of the LADITools suite.'))
|
2012-03-22 13:49:17 +02:00
|
|
|
parser.add_argument('--no-appindicator',
|
|
|
|
action='store_true',
|
|
|
|
help=_('Force fallback to system tray.'))
|
|
|
|
parser.add_argument('--version',
|
|
|
|
action='version',
|
|
|
|
version="%(prog)s " + get_version_string())
|
|
|
|
args = parser.parse_args()
|
2012-03-03 13:00:50 +02:00
|
|
|
|
2012-03-20 09:32:14 +02:00
|
|
|
Gtk.init(None)
|
|
|
|
|
2012-03-22 13:49:17 +02:00
|
|
|
if (not args.no_appindicator) and AppIndicator3:
|
2012-03-18 02:26:04 +02:00
|
|
|
LadiStatusIndicator().run()
|
|
|
|
else:
|
|
|
|
LadiStatusTray().run()
|
2012-03-22 13:49:17 +02:00
|
|
|
|
2012-03-03 13:00:50 +02:00
|
|
|
sys.exit(0)
|