~ubuntu-branches/ubuntu/maverick/awn-extras-applets/maverick

« back to all changes in this revision

Viewing changes to applets/maintained/bandwidth-monitor/bwmprefs.py

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2010-08-29 14:29:52 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100829142952-rhvuetyms9bv5uu7
Tags: upstream-0.4.0+bzr1372
ImportĀ upstreamĀ versionĀ 0.4.0+bzr1372

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
'''
21
21
 
22
22
from awn.extras import _
 
23
 
23
24
import gobject
24
25
import gtk
25
26
 
29
30
    def __init__(self, applet, parent):
30
31
        self.applet = applet
31
32
        self.parent = parent
 
33
        self.preferences_dialog = self.applet.dialog.new('preferences')
 
34
        self.preferences_dialog.connect('show', self.show_event_cb)
 
35
 
 
36
    def create_display_parameter_list(self):
 
37
        cell_box = self.create_treeview()
 
38
        store = cell_box.liststore
 
39
        ddps = 'device_display_parameters'
 
40
        prefs = self.parent.applet.settings[ddps]
 
41
        for device_pref in prefs:
 
42
            dpv = device_pref.split('|')
 
43
            iface = dpv[0]
 
44
            sum_include = dpv[1]
 
45
            muti_include = dpv[2]
 
46
            current_iter = store.append([iface, sum_include,
 
47
                muti_include, '', '', '#ff0000', '#ffff00'])
 
48
        ifaces = self.parent.netstats.ifaces
 
49
        for iface in sorted(self.parent.netstats.ifaces):
 
50
            if not 'Multi Interface' in iface \
 
51
            and not 'Sum Interface' in iface and \
 
52
            not iface in prefs.__str__():
 
53
                sum_include = True if ifaces[iface]['sum_include'] \
 
54
                    else False
 
55
                multi_include = True if ifaces[iface]['multi_include'] \
 
56
                    else False
 
57
                current_iter = store.append([iface, sum_include,
 
58
                    multi_include, '', '', '#ff0000', '#ffff00'])
 
59
        for child in self.prefs_ui.get_object('scrolledwindow1').get_children():
 
60
            self.prefs_ui.get_object('scrolledwindow1').remove(child)
 
61
            del child
 
62
        self.prefs_ui.get_object('scrolledwindow1').add_with_viewport(cell_box)
 
63
        cell_box.show_all()
32
64
 
33
65
    def setup(self):
34
66
        prefs_ui = gtk.Builder()
 
67
        self.prefs_ui = prefs_ui
35
68
        prefs_ui.add_from_file(self.parent.UI_FILE)
36
 
        preferences_vbox = self.applet.dialog.new('preferences').vbox
37
 
        cell_box = self.create_treeview()
38
 
        store = cell_box.liststore
 
69
        preferences_vbox = self.preferences_dialog.vbox
39
70
        scaleThresholdSBtn = prefs_ui.get_object('scaleThresholdSBtn')
40
71
        thresholdLabel = prefs_ui.get_object('label-scaleThreshold')
41
72
        scaleThresholdSBtn.set_value(
88
119
        labelNoneRadiobutton.connect('toggled', self.labelRadio_cb, 0)
89
120
        labelSumRadiobutton.connect('toggled', self.labelRadio_cb, 1)
90
121
        labelBothRadiobutton.connect('toggled', self.labelRadio_cb, 2)
91
 
        for iface in sorted(self.parent.netstats.ifaces):
92
 
            if not 'Multi Interface' in iface \
93
 
            and not 'Sum Interface' in iface:
94
 
                if self.parent.netstats.ifaces[iface]['sum_include'] == True:
95
 
                    sum_include = 1
96
 
                else:
97
 
                    sum_include = 0
98
 
                if self.parent.netstats.ifaces[iface]['multi_include'] == True:
99
 
                    muti_include = 1
100
 
                else:
101
 
                    muti_include = 0
102
 
                current_iter = store.append([iface, sum_include,
103
 
                    muti_include, '', '', '#ff0000', '#ffff00'])
104
 
        prefs_ui.get_object('scrolledwindow1').add_with_viewport(cell_box)
105
122
        prefs_ui.get_object('dialog-notebook').reparent(preferences_vbox)
106
123
 
107
124
    def graphZeroToggle_cb(self, widget):
123
140
        treeview.set_enable_search(True)
124
141
        treeview.position = 0
125
142
        rows = gtk.VBox(False, 3)
 
143
        if hasattr(self, 'liststore'):
 
144
            del self.liststore
126
145
        self.liststore = liststore
127
146
        listcols = gtk.HBox(False, 0)
128
147
        prows = gtk.VBox(False, 0)
193
212
 
194
213
    def devlist_cell_func(self, column, cell, model, iter):
195
214
        ''' Changes the cell color to match the preferece or selected value '''
196
 
        device = self.liststore.get_value(iter, 0)
197
 
        column_title = column.get_title().lower().split(' ')[0]
198
 
        cell.set_property('cell-background',
199
 
            self.get_color(device, column_title))
 
215
        try:
 
216
            device = self.liststore.get_value(iter, 0)
 
217
            column_title = column.get_title().lower().split(' ')[0]
 
218
            cell.set_property('cell-background',
 
219
                self.get_color(device, column_title))
 
220
        except:
 
221
            pass
200
222
 
201
223
    def bgCheckbutton_cb(self, widget):
202
224
        self.applet.settings['background'] = widget.get_active()
246
268
        response = colorseldlg.run()
247
269
        if response == gtk.RESPONSE_OK:
248
270
            self.color_choice = colorseldlg.colorsel.get_current_color()
249
 
            self.parent.netstats.ifaces[model[path][0]]['%s_color' \
250
 
                % prop.lower()] = self.color_choice.to_string()
 
271
            if model[path][0] in self.parent.netstats.ifaces:
 
272
                self.parent.netstats.ifaces[model[path][0]]['%s_color' \
 
273
                    % prop.lower()] = self.color_choice.to_string()
251
274
            prefs = self.applet.settings['device_display_parameters']
252
275
            if not prefs:
253
276
                prefs = ['%s|True|True|None|None' % (model[path][0])]
278
301
                dpv[col_number] = str(parameter)
279
302
                prefs[i] = '|'.join(dpv)
280
303
        self.applet.settings['device_display_parameters'] = prefs
 
304
 
 
305
    def show_event_cb(self, *args):
 
306
        self.create_display_parameter_list()