2
# this is the magic interpreted by Sonata, referring to construct_tab below:
9
# description: A tab for controlling local MPD
10
# author: Tuukka Hastrup
11
# author_email: Tuukka.Hastrup@iki.fi
12
# url: http://sonata.berlios.de
17
import subprocess, locale
21
from sonata.misc import escape_html
24
# schedule next update
25
gobject.timeout_add(1000, update, label)
27
# don't update if not visible
28
if not label.window or not label.window.is_viewable():
31
commands = [("Processes", ["sh", "-c", "ps wwu -C mpd"]),
32
("Networking", ["sh", "-c", "netstat -Watue --numeric-hosts | egrep ':6600|^Proto'"]),
33
("Files", ["sh", "-c", "ls -lRh /etc/mpd.conf /var/lib/mpd"]),
35
outputs = [(title, subprocess.Popen(command,
36
stdout=subprocess.PIPE,
37
stderr=subprocess.PIPE
39
for title, command in commands]
40
text = '\n'.join(["<b>%s</b>\n<tt>%s</tt><i>%s</i>\n" %
41
(title, escape_html(stdout), escape_html(stderr))
42
for title, (stdout, stderr) in outputs])
43
label.set_markup(text.decode(locale.getpreferredencoding(),
46
# nothing magical here, this constructs the parts of the tab when called:
50
label.set_properties(xalign=0.0, xpad=5, yalign=0.0, ypad=5,
52
vbox.pack_start(label)
56
window = gtk.ScrolledWindow()
57
window.set_properties(hscrollbar_policy=gtk.POLICY_AUTOMATIC,
58
vscrollbar_policy=gtk.POLICY_AUTOMATIC)
59
window.add_with_viewport(vbox)
62
# (tab content, icon name, tab name, the widget to focus on tab switch)
63
return (window, None, "Local MPD", None)