Fix parsing of log files
[laditools/alessio.git] / wmladi
blob1a30f9cc5c20346e9a6681615b9e0a4dc0c1d1dd
1 #!/usr/bin/env python
3 # LADITools - Linux Audio Desktop Integration Tools
4 # wmladi - Window maker dockapp for jackdbus
5 # Copyright (C) 2007-2010, Marc-Olivier Barre <marco@marcochapeau.org>
6 # Copyright (C) 2007-2009, Nedko Arnaudov <nedko@arnaudov.name>
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 import sys
22 import os
23 from wmdocklib import wmoo, pywmhelpers
24 import laditools
25 import time
27 import pygtk
28 pygtk.require('2.0')
29 import gtk
30 import gobject
32 # Default configuration
33 autostart_default = 0
34 debug = False
36 class wmladi (wmoo.Application, laditools.manager):
37 def __init__ (self):
38 # Handle the configuration
39 self.global_config = laditools.config ()
40 self.param_dict = self.global_config.get_config_section ('wmladi')
41 if self.param_dict != None:
42 if 'autostart' not in self.param_dict:
43 self.param_dict['autostart'] = str (autostart_default)
44 else:
45 self.param_dict = {}
46 self.param_dict['autostart'] = str (autostart_default)
47 autostart = self.param_dict['autostart']
48 wmoo.Application.__init__ (
49 self,
50 #background = os.path.dirname(sys.argv[0]) + os.sep + "wmjackctl.xpm",
51 margin = 2,
52 debug = False)
54 laditools.manager.__init__(self, self.global_config.get_config_section ('ladimenu'), int(autostart))
56 self.addCallback (self.on_button_release, 'buttonrelease', area=(0,0,64,64))
58 self.lines = []
59 for i in range (6):
60 self.lines.append ("")
61 self.clear ()
62 self.started = False
64 def set_starting_status (self):
65 self.set_line (0, "JACK")
66 self.set_line (1, "Starting")
67 self.clear_line (2)
68 self.clear_line (3)
69 self.clear_line (4)
70 self.clear_line (5)
72 def on_button_release (self, event):
73 if event['button'] == 3:
74 self.menu_activate ()
76 def set_line (self, line, text):
77 self.lines[line] = text
78 while len (self.lines[line]) < 9:
79 self.lines[line] += ' '
81 def clear_line (self, line):
82 self.set_line (line, "")
84 def clear (self):
85 for i in range (6):
86 self.clear_line (i)
88 def update (self):
89 try:
90 if self.jack_is_started():
91 self.started = True
93 line0 = "JACK"
94 if self.jack_is_realtime():
95 line0 += " RT"
96 else:
97 line0 += " "
99 if self.a2j_is_available():
100 try:
101 if self.a2j_is_started():
102 line0 += ' A'
103 else:
104 line0 += ' a'
105 except:
106 pass
108 self.set_line(0, line0)
109 self.set_line(1, "started")
110 self.set_line(2, "%.3f %%" % self.jack_get_load())
112 xruns = self.jack_get_xruns()
113 if xruns == 0:
114 self.set_line(3, "no xruns")
115 elif xruns == 1:
116 self.set_line(3, "1 xrun")
117 elif xruns > 999:
118 self.set_line(3, "lot xruns")
119 else:
120 self.set_line(3, "%s xruns" % xruns)
122 rate = self.jack_get_sample_rate()
123 if rate % 1000.0 == 0:
124 self.set_line(4, "%.0f Khz" % (rate / 1000.0))
125 else:
126 self.set_line(4, "%.1f Khz" % (rate / 1000.0))
128 self.set_line(5, "%.1f ms" % self.jack_get_latency())
129 else:
130 self.set_line(0, "JACK")
131 self.set_line(1, "stopped")
132 if self.started:
133 self.clear_line(2)
134 self.clear_line(3)
135 self.clear_line(4)
136 self.clear_line(5)
137 self.started = False
138 self.clear_diagnose_text()
139 except Exception, e:
140 self.set_diagnose_text(repr(e))
141 if debug:
142 print repr (e)
143 self.set_line(0, "JACK")
144 self.set_line(1, "is sick")
145 self.clear_line(2)
146 self.clear_line(3)
147 self.clear_line(4)
148 self.clear_line(5)
149 self.clear_jack_proxies()
151 self.put_lines (self.lines)
152 wmoo.Application.update (self)
153 # Take a look at the processes we've started so we don't get any zombies
154 for i in self.proc_list:
155 i.poll ()
157 def put_lines (self, lines):
158 x = 3
159 y = 2
160 for line in lines:
161 self.putString (x, y, line)
162 y += 9
164 def do_dockapp (self):
165 """this is called from event loop. events are examined and if a
166 callback has been registered, it is called, passing it the event as
167 argument.
169 event = pywmhelpers.getEvent ()
170 while not event is None:
171 if event['type'] == 'destroynotify':
172 sys.exit (0)
174 for evtype, key, area, callback in self._events:
175 if evtype is not None and evtype != event['type']: continue
176 if key is not None and key != event['button']: continue
177 if area is not None:
178 if not area[0] <= event['x'] <= area[2]: continue
179 if not area[1] <= event['y'] <= area[3]: continue
181 callback (event)
183 event = pywmhelpers.getEvent ()
184 self.redraw ()
185 #print "tick"
186 return True
188 def run_sleep (self):
189 self.go = True
190 while self.go:
191 while gtk.events_pending ():
192 gtk.main_iteration ()
193 self.do_dockapp ()
194 while gtk.events_pending ():
195 gtk.main_iteration ()
196 time.sleep (self._sleep)
198 def run_gtk (self):
199 #print self._sleep
200 gobject.timeout_add (int(self._sleep * 1000), self.do_dockapp)
201 gtk.main ()
203 def run (self):
204 self.run_gtk ()
205 self.global_config.set_config_section ('wmladi', self.param_dict)
206 self.global_config.set_config_section ('ladimenu', self.menu_array)
207 self.global_config.save ()
209 wmladi ().run ()