Re: [virt-manager PATCH 2/2] details: introduce show_remove_button method

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 04/22/2014 04:02 AM, Cole Robinson wrote:
On 04/21/2014 02:39 AM, Chen Hanxiao wrote:
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@xxxxxxxxxxxxxx>
---
  virtManager/details.py | 37 +++++++++++++++++++++++++++++++++----
  1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/virtManager/details.py b/virtManager/details.py
index 86a81eb..4944bce 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -433,6 +433,31 @@ def _icon_for_device(dev):
      return typemap[devtype]
+def show_remove_button(dev):
+    # type, bus
+    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]),
@@ -2754,10 +2779,10 @@ class vmmDetails(vmmGObjectUI):
          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:
+        if show_remove_button(inp):
              self.widget("config-remove").set_sensitive(True)
+        else:
+            self.widget("config-remove").set_sensitive(False)
def refresh_graphics_page(self):
          gfx = self.get_hw_selection(HW_LIST_COL_DEVICE)
@@ -3036,12 +3061,16 @@ 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:
+            pass
+
+        if show_remove_button(dev):
              self.widget("config-remove").set_sensitive(True)
+        else:
+            self.widget("config-remove").set_sensitive(False)
uiutil.set_combo_entry(self.widget("controller-model"),
                               dev.model or "Default")

Hmm, I don't really understand the point of centralizing the logic in an
external function, yet still requiring refresh_* functions to call the
function manually. As is this patch doesn't improve things IMO. Do you need it
for a later patch?

- Cole
I tried to solve the right-click popup menu issue,
at that time I think we need this interface.

But could not find a way currently :(

Still I think if we had this patch, it will be easier for others to know which device
need to hide remove buttons. Just a tiny improvement.

- Chen

_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list



_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list




[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux