~ubuntu-branches/ubuntu/wily/blueman/wily-proposed

« back to all changes in this revision

Viewing changes to blueman/gui/manager/ManagerStats.py

  • Committer: Package Import Robot
  • Author(s): Jackson Doak
  • Date: 2014-01-21 08:54:58 UTC
  • mfrom: (2.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140121085458-riy3j6wk9vfd599j
Tags: 1.23-git201312311147-1ubuntu1
* Merge from debian unstable. Remaining changes:
  - debian/patches/01_dont_autostart_lxde.patch:
    + Don't autostart the applet in LXDE
  - debian/patches/02_dont_crash_on_non-bluetooth_card.patch:
    + Avoid crashing when receiving event for cards blueman shouldn't handle
  - debian/control: Don't depend on python-appindicator
  - debian/patches/03_filemanager_fix.patch:
    + Add support for more filemanagers 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
#
3
 
# blueman - statusbar_with_stats module
4
 
# (c) 2007 Valmantas Paliksa <walmis at balticum-tv dot lt>
5
 
#
6
 
# This library is free software; you can redistribute it and/or
7
 
# modify it under the terms of the GNU General Public
8
 
# License as published by the Free Software Foundation; either
9
 
# version 2.1 of the License, or (at your option) any later version.
10
 
11
 
# This library is distributed in the hope that it will be useful,
12
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
# General Public License for more details.
15
 
16
 
# You should have received a copy of the GNU General Public
17
 
# License along with this program; if not, write to the Free Software
18
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
#
20
 
 
21
1
import blueman.Lib as Lib
22
2
import gobject
23
3
import gtk
28
8
from blueman.Functions import format_bytes
29
9
 
30
10
import gettext
 
11
 
31
12
_ = gettext.gettext
32
13
 
33
14
 
34
15
class ManagerStats:
35
 
        
36
 
        def __init__(self, blueman):
37
 
                
38
 
                blueman.List.connect("adapter-changed", self.on_adapter_changed)
39
 
                
40
 
                if blueman.List.Adapter:
41
 
                        self.hci = adapter_path_to_name(blueman.List.Adapter.GetObjectPath())
42
 
                else:
43
 
                        self.hci = None
44
 
                
45
 
                self.time= None
46
 
                
47
 
                self.up_speed = SpeedCalc()
48
 
                self.down_speed = SpeedCalc()
49
 
                        
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)
60
 
                
61
 
 
62
 
                
63
 
                self.down_rate = gtk.Label()
64
 
                self.down_rate.show()
65
 
                self.down_rate.set_alignment(1, 0.5)
66
 
                self.down_rate.set_tooltip_text(_("Total data received and rate of transmission"))
67
 
                
68
 
                self.up_rate = gtk.Label()
69
 
                self.up_rate.show()
70
 
                self.up_rate.set_alignment(1, 0.5)
71
 
                self.up_rate.set_tooltip_text(_("Total data sent and rate of transmission"))
72
 
                
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)
77
 
                
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)
81
 
                
82
 
                self.hbox = hbox = blueman.Builder.get_object("statusbar2")
83
 
 
84
 
                hbox.pack_start(self.uparrow, True, False)
85
 
                hbox.pack_start(self.up_rate, False, False)
86
 
                
87
 
                hbox.pack_start(self.downarrow, False, False)
88
 
                hbox.pack_start(self.down_rate, False, False)
89
 
                
90
 
                hbox.pack_start(gtk.VSeparator(), False, False)
91
 
                
92
 
                hbox.pack_start(self.im_upload, False, False)
93
 
                hbox.pack_start(self.im_download, False, False)
94
 
                hbox.show_all()
95
 
                self.on_adapter_changed(blueman.List, blueman.List.GetAdapterPath())
96
 
                
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)])
100
 
                
101
 
                self.start_update()
102
 
                
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
107
 
                else:
108
 
                        self.hci = None
109
 
                        self.hbox.props.sensitive = False
110
 
                        
111
 
                self.up_speed.reset()
112
 
                self.down_speed.reset()
113
 
                
114
 
        def set_blinker_by_speed(self, blinker, speed):
115
 
                
116
 
                if speed > 0 and not blinker.status():
117
 
                        blinker.start()
118
 
                        
119
 
                if speed > (30*1024) and blinker.status():
120
 
                        blinker.set_rate(20)
121
 
                elif speed > (20*1024) and blinker.status():
122
 
                        blinker.set_rate(15)
123
 
                elif speed > (10*1024) and blinker.status():
124
 
                        blinker.set_rate(10)
125
 
                elif speed > 1024 and blinker.status():
126
 
                        blinker.set_rate(5)
127
 
                elif speed == 0 and blinker.status():
128
 
 
129
 
                        blinker.stop()
130
 
                else:
131
 
                        blinker.set_rate(1)
132
 
        
133
 
        
134
 
        def _update(self):
135
 
                #if self.hbox.parent.parent.parent.props.visible:
136
 
 
137
 
                if self.hci != None:
138
 
                        devinfo = Lib.device_info(self.hci)
139
 
                        _tx = devinfo["stat"]["byte_tx"]
140
 
                        _rx = devinfo["stat"]["byte_rx"]
141
 
 
142
 
                        tx, s_tx = format_bytes(_tx)
143
 
                        rx, s_rx = format_bytes(_rx)
144
 
        
145
 
                        _u_speed = self.up_speed.calc(_tx)
146
 
                        _d_speed = self.down_speed.calc(_rx)
147
 
        
148
 
                        self.set_blinker_by_speed(self.up_blinker, _u_speed)
149
 
                        self.set_blinker_by_speed(self.down_blinker, _d_speed)
150
 
        
151
 
 
152
 
        
153
 
                        u_speed, s_u_speed = format_bytes(_u_speed)
154
 
                        d_speed, s_d_speed = format_bytes(_d_speed)
155
 
        
156
 
                        self.set_data(tx, s_tx, rx, s_rx, u_speed, s_u_speed, d_speed, s_d_speed)
157
 
                
158
 
                return 1
159
 
 
160
 
 
161
 
 
162
 
        def start_update(self):
163
 
                self._update()
164
 
                self.timer = gobject.timeout_add (1000, self._update)
165
 
                
166
 
        def stop_update(self):
167
 
                if self.timer:
168
 
                        gobject.source_remove(self.timer)
169
 
        
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):
 
17
 
 
18
        blueman.List.connect("adapter-changed", self.on_adapter_changed)
 
19
 
 
20
        if blueman.List.Adapter:
 
21
            self.hci = adapter_path_to_name(blueman.List.Adapter.GetObjectPath())
 
22
        else:
 
23
            self.hci = None
 
24
 
 
25
        self.time = None
 
26
 
 
27
        self.up_speed = SpeedCalc()
 
28
        self.down_speed = SpeedCalc()
 
29
 
 
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)
 
40
 
 
41
        self.down_rate = gtk.Label()
 
42
        self.down_rate.show()
 
43
        self.down_rate.set_alignment(1, 0.5)
 
44
        self.down_rate.set_tooltip_text(_("Total data received and rate of transmission"))
 
45
 
 
46
        self.up_rate = gtk.Label()
 
47
        self.up_rate.show()
 
48
        self.up_rate.set_alignment(1, 0.5)
 
49
        self.up_rate.set_tooltip_text(_("Total data sent and rate of transmission"))
 
50
 
 
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)
 
55
 
 
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)
 
59
 
 
60
        self.hbox = hbox = blueman.Builder.get_object("statusbar2")
 
61
 
 
62
        hbox.pack_start(self.uparrow, True, False)
 
63
        hbox.pack_start(self.up_rate, False, False)
 
64
 
 
65
        hbox.pack_start(self.downarrow, False, False)
 
66
        hbox.pack_start(self.down_rate, False, False)
 
67
 
 
68
        hbox.pack_start(gtk.VSeparator(), False, False)
 
69
 
 
70
        hbox.pack_start(self.im_upload, False, False)
 
71
        hbox.pack_start(self.im_download, False, False)
 
72
        hbox.show_all()
 
73
        self.on_adapter_changed(blueman.List, blueman.List.GetAdapterPath())
 
74
 
 
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)])
 
80
 
 
81
        self.start_update()
 
82
 
 
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
 
87
        else:
 
88
            self.hci = None
 
89
            self.hbox.props.sensitive = False
 
90
 
 
91
        self.up_speed.reset()
 
92
        self.down_speed.reset()
 
93
 
 
94
    def set_blinker_by_speed(self, blinker, speed):
 
95
 
 
96
        if speed > 0 and not blinker.status():
 
97
            blinker.start()
 
98
 
 
99
        if speed > (30 * 1024) and blinker.status():
 
100
            blinker.set_rate(20)
 
101
        elif speed > (20 * 1024) and blinker.status():
 
102
            blinker.set_rate(15)
 
103
        elif speed > (10 * 1024) and blinker.status():
 
104
            blinker.set_rate(10)
 
105
        elif speed > 1024 and blinker.status():
 
106
            blinker.set_rate(5)
 
107
        elif speed == 0 and blinker.status():
 
108
 
 
109
            blinker.stop()
 
110
        else:
 
111
            blinker.set_rate(1)
 
112
 
 
113
 
 
114
    def _update(self):
 
115
        #if self.hbox.parent.parent.parent.props.visible:
 
116
 
 
117
        if self.hci != None:
 
118
            devinfo = Lib.device_info(self.hci)
 
119
            _tx = devinfo["stat"]["byte_tx"]
 
120
            _rx = devinfo["stat"]["byte_rx"]
 
121
 
 
122
            tx, s_tx = format_bytes(_tx)
 
123
            rx, s_rx = format_bytes(_rx)
 
124
 
 
125
            _u_speed = self.up_speed.calc(_tx)
 
126
            _d_speed = self.down_speed.calc(_rx)
 
127
 
 
128
            self.set_blinker_by_speed(self.up_blinker, _u_speed)
 
129
            self.set_blinker_by_speed(self.down_blinker, _d_speed)
 
130
 
 
131
            u_speed, s_u_speed = format_bytes(_u_speed)
 
132
            d_speed, s_d_speed = format_bytes(_d_speed)
 
133
 
 
134
            self.set_data(tx, s_tx, rx, s_rx, u_speed, s_u_speed, d_speed, s_d_speed)
 
135
 
 
136
        return 1
 
137
 
 
138
 
 
139
    def start_update(self):
 
140
        self._update()
 
141
        self.timer = gobject.timeout_add(1000, self._update)
 
142
 
 
143
    def stop_update(self):
 
144
        if self.timer:
 
145
            gobject.source_remove(self.timer)
 
146
 
 
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))