~mvo/software-center/lp955005

« back to all changes in this revision

Viewing changes to softwarecenter/ui/gtk3/widgets/oneconfviews.py

  • Committer: Anthony Lenton
  • Date: 2012-03-09 12:50:38 UTC
  • mto: This revision was merged to the branch mainline in revision 2840.
  • Revision ID: anthony.lenton@canonical.com-20120309125038-nnx8f8jw2nzg1r99
Made the pep8 test pass on 6 more files in ui.gtk3.widgets.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
class OneConfViews(Gtk.TreeView):
26
26
 
27
27
    __gsignals__ = {
28
 
        "computer-changed" : (GObject.SIGNAL_RUN_LAST,
29
 
                              GObject.TYPE_NONE, 
30
 
                              (GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT),
31
 
                         ),
32
 
        "current-inventory-refreshed" : (GObject.SIGNAL_RUN_LAST,
33
 
                                         GObject.TYPE_NONE,
34
 
                                         (),),
 
28
        "computer-changed": (GObject.SIGNAL_RUN_LAST,
 
29
                             GObject.TYPE_NONE,
 
30
                             (GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT),
 
31
                            ),
 
32
        "current-inventory-refreshed": (GObject.SIGNAL_RUN_LAST,
 
33
                                        GObject.TYPE_NONE,
 
34
                                        (),
 
35
                                       ),
35
36
    }
36
 
    
 
37
 
37
38
    (COL_ICON, COL_HOSTID, COL_HOSTNAME) = range(3)
38
39
 
39
40
    def __init__(self, icons):
40
41
        super(OneConfViews, self).__init__()
41
 
        model = Gtk.ListStore(GdkPixbuf.Pixbuf, GObject.TYPE_STRING, GObject.TYPE_STRING)
 
42
        model = Gtk.ListStore(GdkPixbuf.Pixbuf, GObject.TYPE_STRING,
 
43
            GObject.TYPE_STRING)
42
44
        model.set_sort_column_id(self.COL_HOSTNAME, Gtk.SortType.ASCENDING)
43
45
        model.set_sort_func(self.COL_HOSTNAME, self._sort_hosts)
44
46
        self.set_model(model)
45
47
        self.set_headers_visible(False)
46
48
        self.col = Gtk.TreeViewColumn('hostname')
47
 
        
 
49
 
48
50
        hosticon_renderer = Gtk.CellRendererPixbuf()
49
51
        hostname_renderer = Gtk.CellRendererText()
50
52
        self.col.pack_start(hosticon_renderer, False)
57
59
 
58
60
        # TODO: load the dynamic one (if present), later
59
61
        self.default_computer_icon = icons.load_icon("computer", 22, 0)
60
 
        
 
62
 
61
63
        self.connect("cursor-changed", self.on_cursor_changed)
62
 
        
 
64
 
63
65
    def register_computer(self, hostid, hostname):
64
66
        '''Add a new computer to the model'''
65
67
        model = self.get_model()
73
75
        model.append([self.default_computer_icon, hostid, hostname])
74
76
 
75
77
    def store_packagelist_changed(self, hostid):
76
 
        '''Emit a signal for refreshing the installedpane if current view is concerned'''
 
78
        '''Emit a signal for refreshing the installedpane if current view is
 
79
        concerned
 
80
        '''
77
81
        if hostid == self.current_hostid:
78
82
            self.emit("current-inventory-refreshed")
79
 
            
 
83
 
80
84
    def remove_computer(self, hostid):
81
85
        '''Remove a computer from the model'''
82
86
        model = self.get_model()
83
87
        if not model:
84
88
            return
85
89
        if hostid not in self.hostids:
86
 
            LOG.warning("ask to remove a computer that isn't registered: %s" % hostid)
 
90
            LOG.warning("ask to remove a computer that isn't registered: %s" %
 
91
                hostid)
87
92
            return
88
93
        iter_id = model.get_iter_first()
89
94
        while iter_id:
92
97
                self.hostids.remove(hostid)
93
98
                break
94
99
            iter_id = model.iter_next(iter_id)
95
 
        
96
 
        
 
100
 
97
101
    def on_cursor_changed(self, widget):
98
102
 
99
103
        (path, column) = self.get_cursor()
101
105
            return
102
106
        model = self.get_model()
103
107
        if not model:
104
 
            return                
 
108
            return
105
109
        hostid = model[path][self.COL_HOSTID]
106
110
        hostname = model[path][self.COL_HOSTNAME]
107
111
        if hostid != self.current_hostid:
108
112
            self.current_hostid = hostid
109
113
            self.emit("computer-changed", hostid, hostname)
110
 
            
 
114
 
111
115
    def select_first(self):
112
116
        '''Select first item'''
113
117
        self.set_cursor(Gtk.TreePath.new_first(), None, False)
114
 
        
 
118
 
115
119
    def _sort_hosts(self, model, iter1, iter2, user_data):
116
120
        '''Sort hosts, with "this computer" (NONE HOSTID) as first'''
117
121
        if not self.get_model().get_value(iter1, self.COL_HOSTID):
118
122
            return -1
119
123
        if not self.get_model().get_value(iter2, self.COL_HOSTID):
120
 
            return 1        
121
 
        if self.get_model().get_value(iter1, self.COL_HOSTNAME) > self.get_model().get_value(iter2, self.COL_HOSTNAME):
 
124
            return 1
 
125
        if (self.get_model().get_value(iter1, self.COL_HOSTNAME) >
 
126
            self.get_model().get_value(iter2, self.COL_HOSTNAME)):
122
127
            return 1
123
128
        else:
124
129
            return -1
125
 
        
 
130
 
 
131
 
126
132
def get_test_window():
127
133
 
128
134
    w = OneConfViews(Gtk.IconTheme.get_default())
141
147
    w.register_computer("CCCCC", "NameC")
142
148
    w.register_computer("", "This computer should be first")
143
149
    w.select_first()
144
 
    
 
150
 
145
151
    GObject.timeout_add_seconds(5, w.register_computer, "EEEEE", "NameE")
146
 
    
 
152
 
147
153
    def print_selected_hostid(widget, hostid, hostname):
148
154
        print "%s selected for %s" % (hostid, hostname)
149
 
    
 
155
 
150
156
    w.connect("computer-changed", print_selected_hostid)
151
 
    
 
157
 
152
158
    w.remove_computer("DDDDD")
153
159
    win.show_all()
154
160
    return win