Version 0.1.1.
[SysBars.git] / plugins / diskactivity.py
blobc2471d735c4c498024456d46dd53e37568a6369e
1 import os
3 import gtk as g
5 import addedit
6 from addedit import VSPACING, HSPACING
7 import bardesc
8 from choices import settings
9 import plugins
11 plugins.types['diskactivity'] = _("Disk Activity")
14 platform = plugins.get_platform()
17 class Description(bardesc.Description):
18 def __init__(self, num):
19 bardesc.Description.__init__(self, num)
20 self.type = 'diskactivity'
21 self.disk = settings.get_bar(num, 'disk', 'sda')
22 self.throughput = settings.get_throughput(self.disk)
23 platform.init_disk_throughput(self.disk, self.throughput)
25 def get_name(self):
26 return _("Disk %s") % self.disk
28 def change_num(self, num):
29 bardesc.Description.change_num(self, num)
30 settings.set_bar(num, 'disk', self.disk)
32 def get_range(self):
33 rng = platform.get_disk_activity_range(self.disk)
34 if rng[1] > self.throughput:
35 self.throughput = rng[1]
36 settings.set_throughput(self.disk, self.throughput)
37 return rng
39 def get_reading(self):
40 return platform.get_disk_activity(self.disk)
44 class Dialog(addedit.Dialog):
45 def get_type_name(self):
46 return _("Disk Activity")
48 def layout_for_type(self):
49 hbox = g.HBox(False)
50 hbox.pack_start(self.make_label(_("Disk")) , False, True, HSPACING)
51 self.disk_w = g.combo_box_new_text()
52 disks = platform.list_disks()
53 self.disks = disks
54 for d in disks:
55 self.disk_w.append_text(d)
56 if self.desc.disk in disks:
57 self.disk_w.set_active(disks.index(self.desc.disk))
58 else:
59 self.disk_w.set_active(0)
60 hbox.pack_start(self.disk_w, True, True, HSPACING)
61 self.vbox.pack_start(hbox, True, True, VSPACING)
62 if self.instant_apply:
63 self.disk_w.connect("changed", self.disk_changed_cb)
65 def apply(self):
66 self.disk_changed_cb()
67 addedit.Dialog.apply(self)
69 def disk_changed_cb(self, w = None):
70 disk = self.disks[self.disk_w.get_active()]
71 self.desc.disk = disk
72 settings.set_bar(self.desc.num, 'disk', disk)
73 if self.instant_apply:
74 self.bar_w.whole_redraw()
75 self.parent_win.update_bar_name(self.desc)
77 def get_default_label(self):
78 return _("D")