/usr/bin/ladi-system-tray is in laditools 1.0.1-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | #!/usr/bin/python
# LADITools - Linux Audio Desktop Integration Tools
# ladi-system-tray - System tray integration for LADI
# 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/>.
import os
import sys
import gettext
import argparse
from laditools import _gettext_domain
gettext.install(_gettext_domain)
from laditools import get_version_string
from laditools import LadiConfiguration
from laditools import LadiManager
from laditools import LadiApp
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject
try:
from gi.repository import AppIndicator3
except:
AppIndicator3 = None
from laditools.gtk import LadiMenu
from laditools.gtk import find_data_file
timeout_add = GObject.timeout_add
class LadiStatusIcon (LadiMenu, LadiApp):
_appname = 'ladi-system-tray'
_appname_long = _("LADI System Tray")
_appid = 'org.linuxaudio.ladi.systemtray'
# Default configuration
_default_config = {
'autostart' : False,
}
def on_about(self, *args):
LadiMenu.on_about(self, version=get_version_string())
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()
def set_tooltip_text(self, text): pass
def __init__ (self, config_filename = None):
# Handle the configuration
self.icon_state = ""
self.last_status_text = ""
self.diagnose_text = None
self.status_icons = {'started' : 'ladi-started',
'stopped' : 'ladi-stopped',
'starting' : 'ladi-starting'}
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']))
# Build the UI
LadiMenu.__init__(self,
autostart,
quit = self.quit)
LadiApp.__init__(self)
self.connect_signals_quit()
def menu_activate(self, status_icon, button, activate_time, user_data=None):
menu = self.create_menu()
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_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)
self.set_title(self.appname_long)
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
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()
finally:
LadiManager.update(self)
return True
def set_icon (self, newstate):
if self.icon_state == newstate:
return
self.icon_state = newstate
self.set_from_icon_name(self.status_icons[newstate])
class LadiStatusIndicator(LadiStatusIcon):
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()
finally:
LadiManager.update(self)
return True
def set_icon (self, newstate):
if self.icon_state == newstate:
return
self.icon_state = newstate
self.indicator.set_icon(self.status_icons[newstate])
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))
menu_items.append((Gtk.ImageMenuItem(_("Quit")), self.on_menu_command, self.quit))
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
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)
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('--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()
Gtk.init(None)
if (not args.no_appindicator) and AppIndicator3:
LadiStatusIndicator().run()
else:
LadiStatusTray().run()
sys.exit(0)
|