2011-12-08 12:18:14 +02:00
|
|
|
#!/usr/bin/python
|
2007-12-15 20:09:45 +02:00
|
|
|
|
2008-08-13 13:03:04 +03:00
|
|
|
# LADITools - Linux Audio Desktop Integration Tools
|
2010-01-04 11:32:35 +02:00
|
|
|
# wmladi - Window maker dockapp for jackdbus
|
2012-03-03 14:37:56 +02:00
|
|
|
# Copyright (C) 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-21 19:40:55 +02:00
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
2007-12-15 20:09:45 +02:00
|
|
|
import sys
|
|
|
|
import os
|
2012-03-04 11:00:17 +02:00
|
|
|
import signal
|
2007-12-15 20:09:45 +02:00
|
|
|
from wmdocklib import wmoo, pywmhelpers
|
2007-12-16 00:41:50 +02:00
|
|
|
import time
|
2012-03-03 14:35:53 +02:00
|
|
|
import argparse
|
|
|
|
import gettext
|
2012-03-10 14:25:53 +02:00
|
|
|
from gi.repository import Gdk
|
2007-12-16 00:41:50 +02:00
|
|
|
|
2012-03-04 11:00:17 +02:00
|
|
|
sig_handler = signal.getsignal(signal.SIGTERM)
|
|
|
|
signal.signal(signal.SIGINT, sig_handler)
|
|
|
|
|
2012-03-03 14:35:53 +02:00
|
|
|
from laditools import _gettext_domain
|
|
|
|
gettext.install(_gettext_domain)
|
2011-12-08 02:50:44 +02:00
|
|
|
|
2012-03-03 14:35:53 +02:00
|
|
|
from laditools import get_version_string
|
|
|
|
from laditools import LadiConfiguration
|
2012-03-19 03:49:43 +02:00
|
|
|
from laditools import LadiApp
|
2012-03-03 14:35:53 +02:00
|
|
|
|
|
|
|
from gi.repository import Gtk
|
|
|
|
from gi.repository import GObject
|
|
|
|
|
2012-03-17 20:20:49 +02:00
|
|
|
from laditools.gtk import LadiMenu
|
2007-12-15 20:09:45 +02:00
|
|
|
|
2008-02-09 22:00:59 +02:00
|
|
|
# Default configuration
|
|
|
|
autostart_default = 0
|
2008-02-25 02:01:38 +02:00
|
|
|
debug = False
|
2008-01-06 00:05:19 +02:00
|
|
|
|
2012-03-19 03:49:43 +02:00
|
|
|
class wmladi (wmoo.Application, LadiMenu, LadiApp):
|
|
|
|
|
|
|
|
_appname = 'wmladi'
|
|
|
|
_appname_long = _("LADI WindowMaker dockapp")
|
|
|
|
_appid = 'org.linuxaudio.ladi.wmlami'
|
|
|
|
|
|
|
|
# Default configuration
|
|
|
|
_default_config = {
|
|
|
|
'autostart' : False,
|
|
|
|
}
|
|
|
|
|
2012-03-23 19:01:36 +02:00
|
|
|
def on_about(self, *args):
|
|
|
|
LadiMenu.on_about(self, version=get_version_string())
|
|
|
|
|
2012-03-20 14:39:19 +02:00
|
|
|
def quit(self, *args):
|
|
|
|
Gtk.main_quit()
|
|
|
|
|
2008-08-17 14:38:52 +03:00
|
|
|
def __init__ (self):
|
2008-02-09 22:00:59 +02:00
|
|
|
# Handle the configuration
|
2012-03-19 03:49:43 +02:00
|
|
|
self.global_config = LadiConfiguration (self.appname,
|
|
|
|
self._default_config)
|
|
|
|
self.config_dict = self.global_config.get_config_section (self.appname)
|
|
|
|
autostart = bool(eval(self.config_dict['autostart']))
|
2008-08-17 14:38:52 +03:00
|
|
|
wmoo.Application.__init__ (
|
2007-12-15 20:09:45 +02:00
|
|
|
self,
|
2007-12-15 23:07:57 +02:00
|
|
|
#background = os.path.dirname(sys.argv[0]) + os.sep + "wmjackctl.xpm",
|
2007-12-15 20:09:45 +02:00
|
|
|
margin = 2,
|
|
|
|
debug = False)
|
|
|
|
|
2012-03-19 03:49:43 +02:00
|
|
|
LadiMenu.__init__(self, autostart)
|
2012-03-20 14:39:19 +02:00
|
|
|
LadiApp.__init__(self)
|
|
|
|
self.connect_signals_quit()
|
2007-12-16 00:41:50 +02:00
|
|
|
|
2008-08-17 14:38:52 +03:00
|
|
|
self.addCallback (self.on_button_release, 'buttonrelease', area=(0,0,64,64))
|
2007-12-16 00:41:50 +02:00
|
|
|
|
2007-12-23 17:43:47 +02:00
|
|
|
self.lines = []
|
2008-08-17 14:38:52 +03:00
|
|
|
for i in range (6):
|
|
|
|
self.lines.append ("")
|
|
|
|
self.clear ()
|
2007-12-23 17:43:47 +02:00
|
|
|
self.started = False
|
|
|
|
|
2008-08-17 14:38:52 +03:00
|
|
|
def set_starting_status (self):
|
|
|
|
self.set_line (0, "JACK")
|
|
|
|
self.set_line (1, "Starting")
|
|
|
|
self.clear_line (2)
|
|
|
|
self.clear_line (3)
|
|
|
|
self.clear_line (4)
|
|
|
|
self.clear_line (5)
|
|
|
|
|
|
|
|
def on_button_release (self, event):
|
2007-12-16 00:41:50 +02:00
|
|
|
if event['button'] == 3:
|
2008-08-17 14:38:52 +03:00
|
|
|
self.menu_activate ()
|
2007-12-19 00:56:58 +02:00
|
|
|
|
2008-08-17 14:38:52 +03:00
|
|
|
def set_line (self, line, text):
|
2007-12-23 17:43:47 +02:00
|
|
|
self.lines[line] = text
|
2008-08-17 14:38:52 +03:00
|
|
|
while len (self.lines[line]) < 9:
|
2007-12-23 17:43:47 +02:00
|
|
|
self.lines[line] += ' '
|
|
|
|
|
2008-08-17 14:38:52 +03:00
|
|
|
def clear_line (self, line):
|
|
|
|
self.set_line (line, "")
|
2007-12-23 17:43:47 +02:00
|
|
|
|
2008-08-17 14:38:52 +03:00
|
|
|
def clear (self):
|
|
|
|
for i in range (6):
|
|
|
|
self.clear_line (i)
|
2007-12-23 17:43:47 +02:00
|
|
|
|
2008-08-17 14:38:52 +03:00
|
|
|
def update (self):
|
2007-12-15 23:07:57 +02:00
|
|
|
try:
|
2008-09-16 10:54:14 +03:00
|
|
|
if self.jack_is_started():
|
2007-12-23 17:43:47 +02:00
|
|
|
self.started = True
|
2008-09-16 10:54:14 +03:00
|
|
|
|
2008-09-16 10:54:16 +03:00
|
|
|
line0 = "JACK"
|
2008-09-16 10:54:14 +03:00
|
|
|
if self.jack_is_realtime():
|
2008-09-16 10:54:16 +03:00
|
|
|
line0 += " RT"
|
2007-12-15 23:07:57 +02:00
|
|
|
else:
|
2008-09-16 10:54:16 +03:00
|
|
|
line0 += " "
|
2007-12-23 17:43:47 +02:00
|
|
|
|
2008-09-16 10:54:16 +03:00
|
|
|
if self.a2j_is_available():
|
2008-09-16 10:54:22 +03:00
|
|
|
try:
|
|
|
|
if self.a2j_is_started():
|
|
|
|
line0 += ' A'
|
|
|
|
else:
|
|
|
|
line0 += ' a'
|
|
|
|
except:
|
|
|
|
pass
|
2007-12-23 17:43:47 +02:00
|
|
|
|
2008-09-16 10:54:16 +03:00
|
|
|
self.set_line(0, line0)
|
|
|
|
self.set_line(1, "started")
|
2008-09-16 10:54:14 +03:00
|
|
|
self.set_line(2, "%.3f %%" % self.jack_get_load())
|
2007-12-23 17:43:47 +02:00
|
|
|
|
2008-09-16 10:54:14 +03:00
|
|
|
xruns = self.jack_get_xruns()
|
2007-12-15 23:07:57 +02:00
|
|
|
if xruns == 0:
|
2008-09-16 10:54:14 +03:00
|
|
|
self.set_line(3, "no xruns")
|
2007-12-23 17:43:47 +02:00
|
|
|
elif xruns == 1:
|
2008-09-16 10:54:14 +03:00
|
|
|
self.set_line(3, "1 xrun")
|
2007-12-15 23:07:57 +02:00
|
|
|
elif xruns > 999:
|
2008-09-16 10:54:14 +03:00
|
|
|
self.set_line(3, "lot xruns")
|
2007-12-15 23:07:57 +02:00
|
|
|
else:
|
2008-09-16 10:54:14 +03:00
|
|
|
self.set_line(3, "%s xruns" % xruns)
|
2007-12-23 17:43:47 +02:00
|
|
|
|
2008-09-16 10:54:14 +03:00
|
|
|
rate = self.jack_get_sample_rate()
|
2008-06-13 02:24:07 +03:00
|
|
|
if rate % 1000.0 == 0:
|
2008-09-16 10:54:14 +03:00
|
|
|
self.set_line(4, "%.0f Khz" % (rate / 1000.0))
|
2007-12-15 23:07:57 +02:00
|
|
|
else:
|
2008-09-16 10:54:14 +03:00
|
|
|
self.set_line(4, "%.1f Khz" % (rate / 1000.0))
|
2007-12-23 17:43:47 +02:00
|
|
|
|
2008-09-16 10:54:14 +03:00
|
|
|
self.set_line(5, "%.1f ms" % self.jack_get_latency())
|
2007-12-15 21:03:12 +02:00
|
|
|
else:
|
2008-09-16 10:54:14 +03:00
|
|
|
self.set_line(0, "JACK")
|
|
|
|
self.set_line(1, "stopped")
|
2007-12-23 17:43:47 +02:00
|
|
|
if self.started:
|
2008-09-16 10:54:14 +03:00
|
|
|
self.clear_line(2)
|
|
|
|
self.clear_line(3)
|
|
|
|
self.clear_line(4)
|
|
|
|
self.clear_line(5)
|
2007-12-23 17:43:47 +02:00
|
|
|
self.started = False
|
2008-09-16 10:54:14 +03:00
|
|
|
self.clear_diagnose_text()
|
2023-07-20 03:29:01 +03:00
|
|
|
except Exception as e:
|
2008-09-16 10:54:14 +03:00
|
|
|
self.set_diagnose_text(repr(e))
|
2008-01-06 00:05:19 +02:00
|
|
|
if debug:
|
2023-07-20 03:29:01 +03:00
|
|
|
print(repr(e))
|
2008-09-16 10:54:14 +03:00
|
|
|
self.set_line(0, "JACK")
|
2008-09-16 10:54:23 +03:00
|
|
|
self.set_line(1, "is sick")
|
2008-09-16 10:54:25 +03:00
|
|
|
self.clear_line(2)
|
|
|
|
self.clear_line(3)
|
|
|
|
self.clear_line(4)
|
|
|
|
self.clear_line(5)
|
|
|
|
self.clear_jack_proxies()
|
2007-12-23 17:43:47 +02:00
|
|
|
|
2008-08-17 14:38:52 +03:00
|
|
|
self.put_lines (self.lines)
|
|
|
|
wmoo.Application.update (self)
|
2012-03-17 20:28:00 +02:00
|
|
|
LadiMenu.update(self)
|
2007-12-15 20:09:45 +02:00
|
|
|
|
2008-08-17 14:38:52 +03:00
|
|
|
def put_lines (self, lines):
|
2007-12-15 21:03:12 +02:00
|
|
|
x = 3
|
|
|
|
y = 2
|
2007-12-15 20:09:45 +02:00
|
|
|
for line in lines:
|
2008-08-17 14:38:52 +03:00
|
|
|
self.putString (x, y, line)
|
2007-12-15 20:09:45 +02:00
|
|
|
y += 9
|
|
|
|
|
2012-03-08 23:43:31 +02:00
|
|
|
def do_dockapp (self, user_data = None):
|
2007-12-16 00:41:50 +02:00
|
|
|
"""this is called from event loop. events are examined and if a
|
|
|
|
callback has been registered, it is called, passing it the event as
|
|
|
|
argument.
|
|
|
|
"""
|
2008-08-17 14:38:52 +03:00
|
|
|
event = pywmhelpers.getEvent ()
|
2007-12-16 00:41:50 +02:00
|
|
|
while not event is None:
|
|
|
|
if event['type'] == 'destroynotify':
|
2008-08-17 14:38:52 +03:00
|
|
|
sys.exit (0)
|
2007-12-16 00:41:50 +02:00
|
|
|
|
|
|
|
for evtype, key, area, callback in self._events:
|
|
|
|
if evtype is not None and evtype != event['type']: continue
|
|
|
|
if key is not None and key != event['button']: continue
|
|
|
|
if area is not None:
|
|
|
|
if not area[0] <= event['x'] <= area[2]: continue
|
|
|
|
if not area[1] <= event['y'] <= area[3]: continue
|
|
|
|
|
2008-08-17 14:38:52 +03:00
|
|
|
callback (event)
|
2007-12-16 00:41:50 +02:00
|
|
|
|
2008-08-17 14:38:52 +03:00
|
|
|
event = pywmhelpers.getEvent ()
|
|
|
|
self.redraw ()
|
2007-12-16 00:41:50 +02:00
|
|
|
#print "tick"
|
|
|
|
return True
|
|
|
|
|
2008-08-17 14:38:52 +03:00
|
|
|
def run_sleep (self):
|
2007-12-16 00:41:50 +02:00
|
|
|
self.go = True
|
|
|
|
while self.go:
|
2012-03-04 11:04:44 +02:00
|
|
|
while Gtk.events_pending ():
|
|
|
|
Gtk.main_iteration ()
|
2008-08-17 14:38:52 +03:00
|
|
|
self.do_dockapp ()
|
2012-03-04 11:04:44 +02:00
|
|
|
while Gtk.events_pending ():
|
|
|
|
Gtk.main_iteration ()
|
2008-08-17 14:38:52 +03:00
|
|
|
time.sleep (self._sleep)
|
|
|
|
|
|
|
|
def run_gtk (self):
|
2007-12-16 00:41:50 +02:00
|
|
|
#print self._sleep
|
2012-03-08 23:43:31 +02:00
|
|
|
GObject.timeout_add (int(self._sleep * 1000), self.do_dockapp, None)
|
2012-03-03 14:35:53 +02:00
|
|
|
Gtk.main ()
|
2007-12-16 00:41:50 +02:00
|
|
|
|
2008-08-17 14:38:52 +03:00
|
|
|
def run (self):
|
|
|
|
self.run_gtk ()
|
2012-03-19 03:49:43 +02:00
|
|
|
self.global_config.set_config_section (self.appname, self.config_dict)
|
2011-12-07 23:22:26 +02:00
|
|
|
self.global_config.save ()
|
2007-12-16 00:41:50 +02:00
|
|
|
|
2012-03-10 14:25:53 +02:00
|
|
|
def position_menu(self, menu, data):
|
|
|
|
_, x, y, _ = Gdk.Display.get_default().get_pointer()
|
|
|
|
return x, y, True
|
|
|
|
|
2012-03-09 13:47:45 +02:00
|
|
|
def menu_activate(self):
|
|
|
|
menu = self.create_menu()
|
2012-03-10 14:25:53 +02:00
|
|
|
try:
|
|
|
|
menu.popup(parent_menu_shell=None,
|
|
|
|
parent_menu_item=None,
|
|
|
|
func=self.position_menu,
|
|
|
|
data=None,
|
|
|
|
button=3,
|
|
|
|
activate_time=0)
|
2023-07-20 03:29:01 +03:00
|
|
|
except Exception as e:
|
|
|
|
print(repr(e))
|
2012-03-10 14:25:53 +02:00
|
|
|
pass
|
2012-03-09 13:47:45 +02:00
|
|
|
|
2012-03-03 14:35:53 +02:00
|
|
|
if __name__ == '__main__':
|
2012-03-03 14:41:13 +02:00
|
|
|
parser = argparse.ArgumentParser(description=_('Window maker dockapp for jackdbus'),
|
2012-03-03 14:35:53 +02:00
|
|
|
epilog=_('This program is part of the LADITools suite.'))
|
|
|
|
parser.add_argument('--version', action='version', version="%(prog)s " + get_version_string())
|
|
|
|
|
|
|
|
parser.parse_args()
|
|
|
|
wmladi().run ()
|
2012-03-03 14:48:44 +02:00
|
|
|
sys.exit(0)
|