-
Notifications
You must be signed in to change notification settings - Fork 1
/
gauges.py
71 lines (51 loc) · 1.79 KB
/
gauges.py
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
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk as gtk
class Gauges:
def __init__(self):
self.container = gtk.VBox(homogeneous=True, spacing=5)
self.container.show()
self.rows = list()
self.last_row = 0
def create_row(self):
row = gtk.HBox(homogeneous=True, spacing=5)
row.show()
self.container.pack_start(row, True, True, padding=5)
self.rows.append(row)
self.last_row = 0
def add(self, gauge):
if len(self.rows) == 0 or self.last_row == 3:
self.create_row()
row = self.rows[-1]
row.pack_start(gauge, False, True, padding=5)
gauge.show()
self.last_row += 1
def widget(self):
return self.container
class LabelWidget:
def __init__(self, heading, default="", fetcher=None):
self.container = gtk.VBox(spacing=5)
self.create_heading(heading)
self.create_label(default)
if fetcher:
fetcher.connect("updated", self.on_update)
fetcher.update()
self.container.show()
def on_update(self, fetcher, data):
self.set_text(data)
def widget(self):
return self.container
def create_heading(self, heading):
label = gtk.Label(heading + ":")
label.show()
self.container.pack_start(label,
expand=False, fill=True, padding=5)
def create_label(self, default=""):
self.label = gtk.Label()
self.label.set_use_markup(True)
self.label.show()
self.set_text(default)
self.container.pack_start(self.label,
expand=True, fill=True, padding=5)
def set_text(self, text):
self.label.set_markup("<span weight='bold' font='16'>%s</span>" % text)