File: caspermon-applet

package info (click to toggle)
casper 1.77%2Bdebian-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 364 kB
  • ctags: 145
  • sloc: sh: 1,835; ansic: 467; makefile: 76; python: 43
file content (75 lines) | stat: -rwxr-xr-x 2,044 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python

import pygtk
pygtk.require('2.0')

import gtk
import gnome.applet
import subprocess
import os

# A simple applet to display the utilization of the snapshot device
# during a casper session
#
# Matt Zimmerman <mdz@canonical.com>

# TODO:
# - tooltip with details
# - flash at threshold

class CasperApplet:
    def __init__(self, applet, iid):
        self.timeout_interval = 1000
        self.device = 'casper-snapshot'
        self.capacity = [0,0]
        self.datafile = '/var/lib/casper/snapshot-status'
        
        # initializate the gnome internals
        gnome.init("casper", "0.1")

        self.applet = applet

        self.tooltips = gtk.Tooltips()
        self.hbox = gtk.HBox()
        applet.add(self.hbox)

        # add the second button event for the popup menu and the enter mouse event to change the tooltip value
        self.ev_box = gtk.EventBox()
        #self.ev_box.connect("button-press-event",self.button_press)
        self.ev_box.connect("enter-notify-event", self.update_info)
        self.hbox.add(self.ev_box)

        self.prog = gtk.ProgressBar()
        self.ev_box.add(self.prog)

        self.update_info()
        
        gtk.timeout_add(self.timeout_interval,self.update_info, self)

        applet.connect("destroy",self.cleanup)
        applet.show_all()
      
    def update_info(self, event=None):
        self.capacity = self.read_info()
        self.prog.set_fraction(float(self.capacity[0]) / self.capacity[1])
        self.prog.update()

    def read_info(self):
        fields = open(self.datafile).readline().split()
        if fields[2] != 'snapshot':
            return None

        return map(int,fields[3].split('/', 1))

    def cleanup(self):
        # what goes here?
        pass

def casper_factory(applet, iid):
    CasperApplet(applet, iid)

    return gtk.TRUE

gnome.applet.bonobo_factory("OAFIID:GNOME_PythonAppletCasper_Factory", 
                             gnome.applet.Applet.__gtype__, 
                             "casper", "0", casper_factory)