Include manpages.
[laditools.git] / wmladi
blob9b4fcd801bc5a6514f740753b7c8c88a27a2a444
1 #!/usr/bin/python
3 # LADITools - Linux Audio Desktop Integration Tools
4 # wmladi - Window maker dockapp for jackdbus
5 # Copyright (C) 2012 Alessio Treglia <quadrispro@ubuntu.com>
6 # Copyright (C) 2007-2010, Marc-Olivier Barre <marco@marcochapeau.org>
7 # Copyright (C) 2007-2009, Nedko Arnaudov <nedko@arnaudov.name>
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 import sys
23 import os
24 import signal
25 from wmdocklib import wmoo, pywmhelpers
26 import time
27 import argparse
28 import gettext
29 from gi.repository import Gdk
31 sig_handler = signal.getsignal(signal.SIGTERM)
32 signal.signal(signal.SIGINT, sig_handler)
34 from laditools import _gettext_domain
35 gettext.install(_gettext_domain)
37 from laditools import get_version_string
38 from laditools import LadiConfiguration
39 from laditools import LadiApp
41 from gi.repository import Gtk
42 from gi.repository import GObject
44 from laditools.gtk import LadiMenu
46 # Default configuration
47 autostart_default = 0
48 debug = False
50 class wmladi (wmoo.Application, LadiMenu, LadiApp):
52 _appname = 'wmladi'
53 _appname_long = _("LADI WindowMaker dockapp")
54 _appid = 'org.linuxaudio.ladi.wmlami'
56 # Default configuration
57 _default_config = {
58 'autostart' : False,
61 def on_about(self, *args):
62 LadiMenu.on_about(self, version=get_version_string())
64 def quit(self, *args):
65 Gtk.main_quit()
67 def __init__ (self):
68 # Handle the configuration
69 self.global_config = LadiConfiguration (self.appname,
70 self._default_config)
71 self.config_dict = self.global_config.get_config_section (self.appname)
72 autostart = bool(eval(self.config_dict['autostart']))
73 wmoo.Application.__init__ (
74 self,
75 #background = os.path.dirname(sys.argv[0]) + os.sep + "wmjackctl.xpm",
76 margin = 2,
77 debug = False)
79 LadiMenu.__init__(self, autostart)
80 LadiApp.__init__(self)
81 self.connect_signals_quit()
83 self.addCallback (self.on_button_release, 'buttonrelease', area=(0,0,64,64))
85 self.lines = []
86 for i in range (6):
87 self.lines.append ("")
88 self.clear ()
89 self.started = False
91 def set_starting_status (self):
92 self.set_line (0, "JACK")
93 self.set_line (1, "Starting")
94 self.clear_line (2)
95 self.clear_line (3)
96 self.clear_line (4)
97 self.clear_line (5)
99 def on_button_release (self, event):
100 if event['button'] == 3:
101 self.menu_activate ()
103 def set_line (self, line, text):
104 self.lines[line] = text
105 while len (self.lines[line]) < 9:
106 self.lines[line] += ' '
108 def clear_line (self, line):
109 self.set_line (line, "")
111 def clear (self):
112 for i in range (6):
113 self.clear_line (i)
115 def update (self):
116 try:
117 if self.jack_is_started():
118 self.started = True
120 line0 = "JACK"
121 if self.jack_is_realtime():
122 line0 += " RT"
123 else:
124 line0 += " "
126 if self.a2j_is_available():
127 try:
128 if self.a2j_is_started():
129 line0 += ' A'
130 else:
131 line0 += ' a'
132 except:
133 pass
135 self.set_line(0, line0)
136 self.set_line(1, "started")
137 self.set_line(2, "%.3f %%" % self.jack_get_load())
139 xruns = self.jack_get_xruns()
140 if xruns == 0:
141 self.set_line(3, "no xruns")
142 elif xruns == 1:
143 self.set_line(3, "1 xrun")
144 elif xruns > 999:
145 self.set_line(3, "lot xruns")
146 else:
147 self.set_line(3, "%s xruns" % xruns)
149 rate = self.jack_get_sample_rate()
150 if rate % 1000.0 == 0:
151 self.set_line(4, "%.0f Khz" % (rate / 1000.0))
152 else:
153 self.set_line(4, "%.1f Khz" % (rate / 1000.0))
155 self.set_line(5, "%.1f ms" % self.jack_get_latency())
156 else:
157 self.set_line(0, "JACK")
158 self.set_line(1, "stopped")
159 if self.started:
160 self.clear_line(2)
161 self.clear_line(3)
162 self.clear_line(4)
163 self.clear_line(5)
164 self.started = False
165 self.clear_diagnose_text()
166 except Exception, e:
167 self.set_diagnose_text(repr(e))
168 if debug:
169 print repr (e)
170 self.set_line(0, "JACK")
171 self.set_line(1, "is sick")
172 self.clear_line(2)
173 self.clear_line(3)
174 self.clear_line(4)
175 self.clear_line(5)
176 self.clear_jack_proxies()
178 self.put_lines (self.lines)
179 wmoo.Application.update (self)
180 LadiMenu.update(self)
182 def put_lines (self, lines):
183 x = 3
184 y = 2
185 for line in lines:
186 self.putString (x, y, line)
187 y += 9
189 def do_dockapp (self, user_data = None):
190 """this is called from event loop. events are examined and if a
191 callback has been registered, it is called, passing it the event as
192 argument.
194 event = pywmhelpers.getEvent ()
195 while not event is None:
196 if event['type'] == 'destroynotify':
197 sys.exit (0)
199 for evtype, key, area, callback in self._events:
200 if evtype is not None and evtype != event['type']: continue
201 if key is not None and key != event['button']: continue
202 if area is not None:
203 if not area[0] <= event['x'] <= area[2]: continue
204 if not area[1] <= event['y'] <= area[3]: continue
206 callback (event)
208 event = pywmhelpers.getEvent ()
209 self.redraw ()
210 #print "tick"
211 return True
213 def run_sleep (self):
214 self.go = True
215 while self.go:
216 while Gtk.events_pending ():
217 Gtk.main_iteration ()
218 self.do_dockapp ()
219 while Gtk.events_pending ():
220 Gtk.main_iteration ()
221 time.sleep (self._sleep)
223 def run_gtk (self):
224 #print self._sleep
225 GObject.timeout_add (int(self._sleep * 1000), self.do_dockapp, None)
226 Gtk.main ()
228 def run (self):
229 self.run_gtk ()
230 self.global_config.set_config_section (self.appname, self.config_dict)
231 self.global_config.save ()
233 def position_menu(self, menu, data):
234 _, x, y, _ = Gdk.Display.get_default().get_pointer()
235 return x, y, True
237 def menu_activate(self):
238 menu = self.create_menu()
239 try:
240 menu.popup(parent_menu_shell=None,
241 parent_menu_item=None,
242 func=self.position_menu,
243 data=None,
244 button=3,
245 activate_time=0)
246 except Exception, e:
247 print repr(e)
248 pass
250 if __name__ == '__main__':
251 parser = argparse.ArgumentParser(description=_('Window maker dockapp for jackdbus'),
252 epilog=_('This program is part of the LADITools suite.'))
253 parser.add_argument('--version', action='version', version="%(prog)s " + get_version_string())
255 parser.parse_args()
256 wmladi().run ()
257 sys.exit(0)