[virt-tools-list] [PATCH 3/4] Display operating system inspection icons in main vmlist.
Richard W.M. Jones
rjones at redhat.com
Thu Jun 30 08:02:24 UTC 2011
From: "Richard W.M. Jones" <rjones at redhat.com>
---
src/virtManager/manager.py | 41 +++++++++++++++++++++++++++++++++++++++--
1 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/src/virtManager/manager.py b/src/virtManager/manager.py
index c7cca67..a52fd90 100644
--- a/src/virtManager/manager.py
+++ b/src/virtManager/manager.py
@@ -43,6 +43,7 @@ ROW_IS_CONN_CONNECTED = 8
ROW_IS_VM = 9
ROW_IS_VM_RUNNING = 10
ROW_COLOR = 11
+ROW_INSPECTION_OS_ICON = 12
# Columns in the tree view
COL_NAME = 0
@@ -352,9 +353,10 @@ class vmmManager(vmmGObjectUI):
self.window.get_widget("vm-notebook").set_show_tabs(False)
# Handle, name, markup, status, status icon, key/uuid, hint, is conn,
- # is conn connected, is vm, is vm running, fg color
+ # is conn connected, is vm, is vm running, fg color, inspection icon
model = gtk.TreeStore(object, str, str, str, gtk.gdk.Pixbuf, str, str,
- bool, bool, bool, bool, gtk.gdk.Color)
+ bool, bool, bool, bool, gtk.gdk.Color,
+ gtk.gdk.Pixbuf)
vmlist.set_model(model)
util.tooltip_wrapper(vmlist, ROW_HINT, "set_tooltip_column")
@@ -384,6 +386,12 @@ class vmmManager(vmmGObjectUI):
statusCol.add_attribute(status_icon, 'pixbuf', ROW_STATUS_ICON)
statusCol.add_attribute(status_icon, 'visible', ROW_IS_VM)
+ inspection_os_icon = gtk.CellRendererPixbuf()
+ statusCol.pack_start(inspection_os_icon, False)
+ statusCol.add_attribute(inspection_os_icon, 'pixbuf',
+ ROW_INSPECTION_OS_ICON)
+ statusCol.add_attribute(inspection_os_icon, 'visible', ROW_IS_VM)
+
name_txt = gtk.CellRendererText()
nameCol.pack_start(name_txt, True)
nameCol.add_attribute(name_txt, 'markup', ROW_MARKUP)
@@ -679,6 +687,7 @@ class vmmManager(vmmGObjectUI):
vm.connect("status-changed", self.vm_status_changed)
vm.connect("resources-sampled", self.vm_resources_sampled)
vm.connect("config-changed", self.vm_resources_sampled)
+ vm.connect("inspection-changed", self.vm_inspection_changed)
vmlist = self.window.get_widget("vm-list")
model = vmlist.get_model()
@@ -747,6 +756,8 @@ class vmmManager(vmmGObjectUI):
row.insert(ROW_IS_VM, True)
row.insert(ROW_IS_VM_RUNNING, vm.is_active())
row.insert(ROW_COLOR, gtk.gdk.Color(0, 0, 0))
+ row.insert(ROW_INSPECTION_OS_ICON,
+ self.get_inspection_icon_pixbuf(vm,16,16))
row[ROW_MARKUP] = self._build_vm_markup(vm, row)
@@ -784,6 +795,7 @@ class vmmManager(vmmGObjectUI):
row.insert(ROW_IS_VM, False)
row.insert(ROW_IS_VM_RUNNING, False)
row.insert(ROW_COLOR, self._build_conn_color(conn))
+ row.insert(ROW_INSPECTION_OS_ICON, None)
_iter = model.append(None, row)
path = model.get_path(_iter)
@@ -883,6 +895,31 @@ class vmmManager(vmmGObjectUI):
row[ROW_MARKUP] = self._build_vm_markup(vm, row)
model.row_changed(row.path, row.iter)
+ def vm_inspection_changed(self, vm):
+ vmlist = self.window.get_widget("vm-list")
+ model = vmlist.get_model()
+
+ if self.vm_row_key(vm) not in self.rows:
+ return
+
+ row = self.rows[self.vm_row_key(vm)]
+ row[ROW_INSPECTION_OS_ICON] = self.get_inspection_icon_pixbuf(vm,16,16)
+ model.row_changed(row.path, row.iter)
+
+ def get_inspection_icon_pixbuf(self, vm, w, h):
+ # libguestfs gives us the PNG data as a string.
+ png_data = vm.get_inspection_icon()
+ if png_data == None:
+ return None
+ try:
+ pb = gtk.gdk.PixbufLoader(image_type="png")
+ pb.set_size(w, h)
+ pb.write (png_data)
+ pb.close()
+ return pb.get_pixbuf()
+ except:
+ return None
+
def conn_state_changed(self, conn):
self.conn_refresh_resources(conn)
self.vm_selected()
--
1.7.5.2
More information about the virt-tools-list
mailing list