~ubuntu-branches/ubuntu/karmic/sonata/karmic

« back to all changes in this revision

Viewing changes to sonata/plugins/localmpd.py

  • Committer: Bazaar Package Importer
  • Author(s): Michal Čihař
  • Date: 2009-05-11 09:10:00 UTC
  • mfrom: (4.2.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090511091000-jzspxudws5ngxb5e
Tags: 1.6.2-1
New upstream version (Closes: #528045).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
# this is the magic interpreted by Sonata, referring to construct_tab below:
 
3
 
 
4
### BEGIN PLUGIN INFO
 
5
# [plugin]
 
6
# plugin_format: 0, 0
 
7
# name: Local MPD
 
8
# version: 0, 0, 0
 
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
 
13
# [capabilities]
 
14
# tabs: construct_tab
 
15
### END PLUGIN INFO
 
16
 
 
17
import subprocess, locale
 
18
 
 
19
import gobject, gtk
 
20
 
 
21
from sonata.misc import escape_html
 
22
 
 
23
def update(label):
 
24
        # schedule next update
 
25
        gobject.timeout_add(1000, update, label)
 
26
 
 
27
        # don't update if not visible
 
28
        if not label.window or not label.window.is_viewable():
 
29
                return
 
30
 
 
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"]),
 
34
                    ]
 
35
        outputs = [(title, subprocess.Popen(command, 
 
36
                                            stdout=subprocess.PIPE,
 
37
                                            stderr=subprocess.PIPE
 
38
                                            ).communicate())
 
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(), 
 
44
                                     'replace'))
 
45
 
 
46
# nothing magical here, this constructs the parts of the tab when called:
 
47
def construct_tab():
 
48
        vbox = gtk.VBox()
 
49
        label = gtk.Label()
 
50
        label.set_properties(xalign=0.0, xpad=5, yalign=0.0, ypad=5, 
 
51
                             selectable=True)
 
52
        vbox.pack_start(label)
 
53
 
 
54
        update(label)
 
55
 
 
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)
 
60
        window.show_all()
 
61
 
 
62
        # (tab content, icon name, tab name, the widget to focus on tab switch)
 
63
        return (window, None, "Local MPD", None)