[virt-tools-list] [virt-manager PATCH v2] details: introduce show_remove_button method

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Tue Apr 22 03:28:37 UTC 2014


Sometimes we need to set remove button as none-sensitive.

This patch introduces show_remove_button method as
the only interface for showing/removing,
also easy to maintain.

Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
---
v2: remove checks in refresh_* function,
invoked show_remove_button in hw_selected

 virtManager/details.py | 43 +++++++++++++++++++++++++++++++++++--------
 1 file changed, 35 insertions(+), 8 deletions(-)

diff --git a/virtManager/details.py b/virtManager/details.py
index 10afb68..dba6c0f 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -433,6 +433,32 @@ def _icon_for_device(dev):
     return typemap[devtype]
 
 
+def show_remove_button(dev):
+    # type, bus
+    # Can't remove primary Xen or PS/2 mice
+    Values = [[virtinst.VirtualController.TYPE_USB, None],
+            [virtinst.VirtualInputDevice.TYPE_MOUSE ,
+                virtinst.VirtualInputDevice.BUS_PS2],
+            [virtinst.VirtualInputDevice.TYPE_MOUSE,
+                virtinst.VirtualInputDevice.BUS_XEN]]
+    try:
+        DEV_TYPE = dev.type
+    except:
+        DEV_TYPE = None
+
+    try:
+        DEV_BUS = dev.bus
+    except:
+        DEV_BUS = None
+
+    DEV = [DEV_TYPE, DEV_BUS]
+
+    if DEV in Values:
+        return False
+    else:
+        return True
+
+
 class vmmDetails(vmmGObjectUI):
     __gsignals__ = {
         "action-save-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
@@ -1230,6 +1256,14 @@ class vmmDetails(vmmGObjectUI):
                 self.refresh_panic_page()
             else:
                 pagetype = -1
+
+            dev = self.get_hw_selection(HW_LIST_COL_DEVICE)
+
+            if show_remove_button(dev):
+                self.widget("config-remove").set_sensitive(True)
+            else:
+                self.widget("config-remove").set_sensitive(False)
+
         except Exception, e:
             self.err.show_err(_("Error refreshing hardware page: %s") % str(e))
             # Don't return, we want the rest of the bits to run regardless
@@ -2758,12 +2792,6 @@ class vmmDetails(vmmGObjectUI):
         self.widget("input-dev-type").set_text(dev)
         self.widget("input-dev-mode").set_text(mode)
 
-        # Can't remove primary Xen or PS/2 mice
-        if inp.type == "mouse" and inp.bus in ("xen", "ps2"):
-            self.widget("config-remove").set_sensitive(False)
-        else:
-            self.widget("config-remove").set_sensitive(True)
-
     def refresh_graphics_page(self):
         gfx = self.get_hw_selection(HW_LIST_COL_DEVICE)
         if not gfx:
@@ -3041,12 +3069,11 @@ class vmmDetails(vmmGObjectUI):
             model.append(["default", "Default"])
             model.append(["ich9-ehci1", "USB 2"])
             model.append(["nec-xhci", "USB 3"])
-            self.widget("config-remove").set_sensitive(False)
         elif dev.type == virtinst.VirtualController.TYPE_SCSI:
             model.append(["default", "Default"])
             model.append(["virtio-scsi", "VirtIO SCSI"])
         else:
-            self.widget("config-remove").set_sensitive(True)
+            pass
 
         uiutil.set_combo_entry(self.widget("controller-model"),
                              dev.model or "Default")
-- 
1.9.0




More information about the virt-tools-list mailing list