25
25
class OneConfViews(Gtk.TreeView):
28
"computer-changed" : (GObject.SIGNAL_RUN_LAST,
30
(GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT),
32
"current-inventory-refreshed" : (GObject.SIGNAL_RUN_LAST,
28
"computer-changed": (GObject.SIGNAL_RUN_LAST,
30
(GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT),
32
"current-inventory-refreshed": (GObject.SIGNAL_RUN_LAST,
37
38
(COL_ICON, COL_HOSTID, COL_HOSTNAME) = range(3)
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,
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')
48
50
hosticon_renderer = Gtk.CellRendererPixbuf()
49
51
hostname_renderer = Gtk.CellRendererText()
50
52
self.col.pack_start(hosticon_renderer, False)
58
60
# TODO: load the dynamic one (if present), later
59
61
self.default_computer_icon = icons.load_icon("computer", 22, 0)
61
63
self.connect("cursor-changed", self.on_cursor_changed)
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])
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
77
81
if hostid == self.current_hostid:
78
82
self.emit("current-inventory-refreshed")
80
84
def remove_computer(self, hostid):
81
85
'''Remove a computer from the model'''
82
86
model = self.get_model()
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" %
88
93
iter_id = model.get_iter_first()
92
97
self.hostids.remove(hostid)
94
99
iter_id = model.iter_next(iter_id)
97
101
def on_cursor_changed(self, widget):
99
103
(path, column) = self.get_cursor()
102
106
model = self.get_model()
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)
111
115
def select_first(self):
112
116
'''Select first item'''
113
117
self.set_cursor(Gtk.TreePath.new_first(), None, False)
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):
119
123
if not self.get_model().get_value(iter2, self.COL_HOSTID):
121
if self.get_model().get_value(iter1, self.COL_HOSTNAME) > self.get_model().get_value(iter2, self.COL_HOSTNAME):
125
if (self.get_model().get_value(iter1, self.COL_HOSTNAME) >
126
self.get_model().get_value(iter2, self.COL_HOSTNAME)):
126
132
def get_test_window():
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")
145
151
GObject.timeout_add_seconds(5, w.register_computer, "EEEEE", "NameE")
147
153
def print_selected_hostid(widget, hostid, hostname):
148
154
print "%s selected for %s" % (hostid, hostname)
150
156
w.connect("computer-changed", print_selected_hostid)
152
158
w.remove_computer("DDDDD")