6 from addedit
import VSPACING
, HSPACING
8 from choices
import settings
11 plugins
.types
['netactivity'] = _("Network Activity")
14 platform
= plugins
.get_platform()
20 class Description(bardesc
.Description
):
21 def __init__(self
, num
):
22 bardesc
.Description
.__init
__(self
, num
)
23 self
.type = 'netactivity'
24 self
.dev
= settings
.get_bar(num
, 'dev', 'eth0')
25 self
.throughputs
= [settings
.get_throughput(self
.dev
+ '/r'),
26 settings
.get_throughput(self
.dev
+ '/w')]
27 self
.set_mode(settings
.get_bar_int(num
, 'rwmode', 3))
28 platform
.init_net_throughput(self
.dev
, self
.throughputs
)
30 def set_mode(self
, mode
):
32 throughput
= self
.throughputs
34 self
.throughput
= throughput
[0]
36 self
.throughput
= throughput
[1]
38 self
.throughput
= throughput
[0] + throughput
[1]
47 return _("Net adaptor %s (%s)") % (self
.dev
, mode
)
49 def change_num(self
, num
):
50 bardesc
.Description
.change_num(self
, num
)
51 settings
.set_bar(num
, 'dev', self
.dev
)
52 settings
.set_bar(num
, 'mode', self
.mode
)
55 drng
= platform
.get_net_activity_range(self
.dev
)
57 rng
= (drng
[0], drng
[1][0])
59 rng
= (drng
[0], drng
[1][1])
61 rng
= (drng
[0], drng
[1][0] + drng
[1][1])
62 if rng
[1] > self
.throughput
:
63 self
.throughput
= rng
[1]
64 if drng
[1][0] > self
.throughputs
[0]:
65 self
.throughputs
[0] = drng
[1][0]
66 settings
.set_throughput(self
.dev
+ '/r', drng
[1][0])
67 if drng
[1][1] > self
.throughputs
[1]:
68 self
.throughputs
[1] = drng
[1][1]
69 settings
.set_throughput(self
.dev
+ '/w', drng
[1][1])
72 def get_reading(self
):
73 readings
= platform
.get_net_activity(self
.dev
)
79 return readings
[0] + readings
[1]
83 class Dialog(addedit
.Dialog
):
84 def get_type_name(self
):
85 return _("Network Activity")
87 def layout_for_type(self
):
89 hbox
.pack_start(self
.make_label(_("Device")) , False, True, HSPACING
)
90 self
.dev_w
= g
.combo_box_new_text()
91 devs
= platform
.list_net_devices()
94 self
.dev_w
.append_text(d
)
95 if self
.desc
.dev
in devs
:
96 self
.dev_w
.set_active(devs
.index(self
.desc
.dev
))
98 self
.dev_w
.set_active(0)
99 hbox
.pack_start(self
.dev_w
, True, True, HSPACING
)
100 self
.vbox
.pack_start(hbox
, True, True, VSPACING
)
103 self
.ro_w
= g
.RadioButton(None, _("Received"))
104 self
.wo_w
= g
.RadioButton(self
.ro_w
, _("Sent"))
105 self
.rw_w
= g
.RadioButton(self
.ro_w
, _("Both"))
106 hbox
.pack_start(self
.ro_w
, True, True, HSPACING
)
107 hbox
.pack_start(self
.wo_w
, True, True, HSPACING
)
108 hbox
.pack_start(self
.rw_w
, True, True, HSPACING
)
109 if self
.desc
.mode
== RO
:
110 self
.ro_w
.set_active(True)
111 elif self
.desc
.mode
== WO
:
112 self
.wo_w
.set_active(True)
113 elif self
.desc
.mode
== RW
:
114 self
.rw_w
.set_active(True)
115 self
.vbox
.pack_start(hbox
, True, True, VSPACING
)
117 if self
.instant_apply
:
118 self
.dev_w
.connect("changed", self
.dev_changed_cb
)
119 self
.ro_w
.connect("toggled", self
.mode_toggled_cb
, RO
)
120 self
.wo_w
.connect("toggled", self
.mode_toggled_cb
, WO
)
121 self
.rw_w
.connect("toggled", self
.mode_toggled_cb
, RW
)
124 self
.dev_changed_cb()
125 addedit
.Dialog
.apply(self
)
126 for radio
, mode
in ((self
.ro_w
, RO
), (self
.wo_w
, WO
), (self
.rw_w
, RW
)):
127 if radio
.get_active():
131 def dev_changed_cb(self
, w
= None):
132 dev
= self
.devs
[self
.dev_w
.get_active()]
134 settings
.set_bar(self
.desc
.num
, 'dev', dev
)
135 if self
.instant_apply
:
136 self
.bar_w
.whole_redraw()
137 self
.parent_win
.update_bar_name(self
.desc
)
139 def mode_toggled_cb(self
, radio
, mode
):
140 if radio
.get_active():
142 self
.parent_win
.update_bar_name(self
.desc
)
144 def set_mode(self
, mode
):
145 settings
.set_bar(self
.desc
.num
, 'rwmode', mode
)
146 self
.desc
.set_mode(mode
)
148 def get_default_label(self
):