28
8
from blueman.Functions import format_bytes
31
12
_ = gettext.gettext
34
15
class ManagerStats:
36
def __init__(self, blueman):
38
blueman.List.connect("adapter-changed", self.on_adapter_changed)
40
if blueman.List.Adapter:
41
self.hci = adapter_path_to_name(blueman.List.Adapter.GetObjectPath())
47
self.up_speed = SpeedCalc()
48
self.down_speed = SpeedCalc()
50
up = get_icon("blueman-up-inactive", 15)
51
down = get_icon("blueman-down-inactive", 15)
52
self.im_upload = gtk.Image()
53
self.im_upload.set_tooltip_text(_("Data activity indication"))
54
self.im_upload.set_from_pixbuf(up)
55
self.im_download = gtk.Image()
56
self.im_download.set_tooltip_text(_("Data activity indication"))
57
self.im_download.set_from_pixbuf(down)
58
self.im_upload.set_alignment(1, 0.5)
59
self.im_download.set_alignment(1, 0.5)
63
self.down_rate = gtk.Label()
65
self.down_rate.set_alignment(1, 0.5)
66
self.down_rate.set_tooltip_text(_("Total data received and rate of transmission"))
68
self.up_rate = gtk.Label()
70
self.up_rate.set_alignment(1, 0.5)
71
self.up_rate.set_tooltip_text(_("Total data sent and rate of transmission"))
73
self.uparrow = gtk.Image()
74
self.uparrow.set_tooltip_text(_("Total data sent and rate of transmission"))
75
self.uparrow.set_from_stock(gtk.STOCK_GO_UP, 1)
76
self.uparrow.set_alignment(1, 0.5)
78
self.downarrow = gtk.Image()
79
self.downarrow.set_tooltip_text(_("Total data received and rate of transmission"))
80
self.downarrow.set_from_stock(gtk.STOCK_GO_DOWN, 1)
82
self.hbox = hbox = blueman.Builder.get_object("statusbar2")
84
hbox.pack_start(self.uparrow, True, False)
85
hbox.pack_start(self.up_rate, False, False)
87
hbox.pack_start(self.downarrow, False, False)
88
hbox.pack_start(self.down_rate, False, False)
90
hbox.pack_start(gtk.VSeparator(), False, False)
92
hbox.pack_start(self.im_upload, False, False)
93
hbox.pack_start(self.im_download, False, False)
95
self.on_adapter_changed(blueman.List, blueman.List.GetAdapterPath())
97
self.up_blinker = Animation(self.im_upload, [get_icon("blueman-up-inactive", 15), get_icon("blueman-up-active", 15)])
98
#self.down_blinker = Animation(self.im_download, ["/down_inactive.png", "/down_active.png"])
99
self.down_blinker = Animation(self.im_download, [get_icon("blueman-down-inactive", 16), get_icon("blueman-down-active", 16)])
103
def on_adapter_changed(self, List, adapter_path):
104
if adapter_path != None:
105
self.hci = adapter_path_to_name(adapter_path)
106
self.hbox.props.sensitive = True
109
self.hbox.props.sensitive = False
111
self.up_speed.reset()
112
self.down_speed.reset()
114
def set_blinker_by_speed(self, blinker, speed):
116
if speed > 0 and not blinker.status():
119
if speed > (30*1024) and blinker.status():
121
elif speed > (20*1024) and blinker.status():
123
elif speed > (10*1024) and blinker.status():
125
elif speed > 1024 and blinker.status():
127
elif speed == 0 and blinker.status():
135
#if self.hbox.parent.parent.parent.props.visible:
138
devinfo = Lib.device_info(self.hci)
139
_tx = devinfo["stat"]["byte_tx"]
140
_rx = devinfo["stat"]["byte_rx"]
142
tx, s_tx = format_bytes(_tx)
143
rx, s_rx = format_bytes(_rx)
145
_u_speed = self.up_speed.calc(_tx)
146
_d_speed = self.down_speed.calc(_rx)
148
self.set_blinker_by_speed(self.up_blinker, _u_speed)
149
self.set_blinker_by_speed(self.down_blinker, _d_speed)
153
u_speed, s_u_speed = format_bytes(_u_speed)
154
d_speed, s_d_speed = format_bytes(_d_speed)
156
self.set_data(tx, s_tx, rx, s_rx, u_speed, s_u_speed, d_speed, s_d_speed)
162
def start_update(self):
164
self.timer = gobject.timeout_add (1000, self._update)
166
def stop_update(self):
168
gobject.source_remove(self.timer)
170
def set_data(self, uploaded, u_name, downloaded, d_name, u_speed, us_name, d_speed, ds_name):
171
self.down_rate.set_markup('<span size="small">%.2f %s <i>%5.2f %s/s</i></span>' % (downloaded, d_name, d_speed, ds_name))
172
self.up_rate.set_markup('<span size="small">%.2f %s <i>%5.2f %s/s</i></span>' % (uploaded, u_name, u_speed, us_name))
16
def __init__(self, blueman):
18
blueman.List.connect("adapter-changed", self.on_adapter_changed)
20
if blueman.List.Adapter:
21
self.hci = adapter_path_to_name(blueman.List.Adapter.GetObjectPath())
27
self.up_speed = SpeedCalc()
28
self.down_speed = SpeedCalc()
30
up = get_icon("blueman-up-inactive", 15)
31
down = get_icon("blueman-down-inactive", 15)
32
self.im_upload = gtk.Image()
33
self.im_upload.set_tooltip_text(_("Data activity indication"))
34
self.im_upload.set_from_pixbuf(up)
35
self.im_download = gtk.Image()
36
self.im_download.set_tooltip_text(_("Data activity indication"))
37
self.im_download.set_from_pixbuf(down)
38
self.im_upload.set_alignment(1, 0.5)
39
self.im_download.set_alignment(1, 0.5)
41
self.down_rate = gtk.Label()
43
self.down_rate.set_alignment(1, 0.5)
44
self.down_rate.set_tooltip_text(_("Total data received and rate of transmission"))
46
self.up_rate = gtk.Label()
48
self.up_rate.set_alignment(1, 0.5)
49
self.up_rate.set_tooltip_text(_("Total data sent and rate of transmission"))
51
self.uparrow = gtk.Image()
52
self.uparrow.set_tooltip_text(_("Total data sent and rate of transmission"))
53
self.uparrow.set_from_stock(gtk.STOCK_GO_UP, 1)
54
self.uparrow.set_alignment(1, 0.5)
56
self.downarrow = gtk.Image()
57
self.downarrow.set_tooltip_text(_("Total data received and rate of transmission"))
58
self.downarrow.set_from_stock(gtk.STOCK_GO_DOWN, 1)
60
self.hbox = hbox = blueman.Builder.get_object("statusbar2")
62
hbox.pack_start(self.uparrow, True, False)
63
hbox.pack_start(self.up_rate, False, False)
65
hbox.pack_start(self.downarrow, False, False)
66
hbox.pack_start(self.down_rate, False, False)
68
hbox.pack_start(gtk.VSeparator(), False, False)
70
hbox.pack_start(self.im_upload, False, False)
71
hbox.pack_start(self.im_download, False, False)
73
self.on_adapter_changed(blueman.List, blueman.List.GetAdapterPath())
75
self.up_blinker = Animation(self.im_upload,
76
[get_icon("blueman-up-inactive", 15), get_icon("blueman-up-active", 15)])
77
#self.down_blinker = Animation(self.im_download, ["/down_inactive.png", "/down_active.png"])
78
self.down_blinker = Animation(self.im_download,
79
[get_icon("blueman-down-inactive", 16), get_icon("blueman-down-active", 16)])
83
def on_adapter_changed(self, List, adapter_path):
84
if adapter_path != None:
85
self.hci = adapter_path_to_name(adapter_path)
86
self.hbox.props.sensitive = True
89
self.hbox.props.sensitive = False
92
self.down_speed.reset()
94
def set_blinker_by_speed(self, blinker, speed):
96
if speed > 0 and not blinker.status():
99
if speed > (30 * 1024) and blinker.status():
101
elif speed > (20 * 1024) and blinker.status():
103
elif speed > (10 * 1024) and blinker.status():
105
elif speed > 1024 and blinker.status():
107
elif speed == 0 and blinker.status():
115
#if self.hbox.parent.parent.parent.props.visible:
118
devinfo = Lib.device_info(self.hci)
119
_tx = devinfo["stat"]["byte_tx"]
120
_rx = devinfo["stat"]["byte_rx"]
122
tx, s_tx = format_bytes(_tx)
123
rx, s_rx = format_bytes(_rx)
125
_u_speed = self.up_speed.calc(_tx)
126
_d_speed = self.down_speed.calc(_rx)
128
self.set_blinker_by_speed(self.up_blinker, _u_speed)
129
self.set_blinker_by_speed(self.down_blinker, _d_speed)
131
u_speed, s_u_speed = format_bytes(_u_speed)
132
d_speed, s_d_speed = format_bytes(_d_speed)
134
self.set_data(tx, s_tx, rx, s_rx, u_speed, s_u_speed, d_speed, s_d_speed)
139
def start_update(self):
141
self.timer = gobject.timeout_add(1000, self._update)
143
def stop_update(self):
145
gobject.source_remove(self.timer)
147
def set_data(self, uploaded, u_name, downloaded, d_name, u_speed, us_name, d_speed, ds_name):
148
self.down_rate.set_markup(
149
'<span size="small">%.2f %s <i>%5.2f %s/s</i></span>' % (downloaded, d_name, d_speed, ds_name))
150
self.up_rate.set_markup(
151
'<span size="small">%.2f %s <i>%5.2f %s/s</i></span>' % (uploaded, u_name, u_speed, us_name))