Thanks for the patch. We can simplify code here and make this mistake
more obvious with a helper function. I'm pushing the attached commit to
add a _disable_device_remove helper that takes only a tooltip as an
argument, will save having to track can_remove. Please adapt patch #2
and this one to use it.
On 07/18/2018 06:00 AM, Lin Ma wrote:
It informs users that why the device can't be removed.
Signed-off-by: Lin Ma <lma@xxxxxxxx>
---
virtManager/details.py | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/virtManager/details.py b/virtManager/details.py
index cb298f3f..7308cde3 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -3016,6 +3016,7 @@ class vmmDetails(vmmGObjectUI):
can_remove = True
if self.vm.xmlobj.devices.graphics:
can_remove = False
+ tooltip = _("Please remove the Graphics/Display devices first.")
I prefer "Cannot remove device while Graphics/Display is attached."
self.widget("config-remove").set_sensitive(can_remove)
self.widget("config-remove").set_tooltip_text(tooltip)
@@ -3043,8 +3044,10 @@ class vmmDetails(vmmGObjectUI):
can_remove = True
if self.vm.get_xmlobj().os.is_x86() and controller.type == "usb":
can_remove = False
+ tooltip = _("Hypervisor does not support removing this device")
if controller.type == "pci":
can_remove = False
+ tooltip = _("Hypervisor does not support removing this device")
elif controller.type in ["scsi", "sata", "ide", "fdc"]:
model = self.widget("controller-device-list").get_model()
model.clear()
@@ -3056,6 +3059,8 @@ class vmmDetails(vmmGObjectUI):
model.append([infoStr])
uiutil.set_grid_row_visible(self.widget("device-list-label"), True)
uiutil.set_grid_row_visible(self.widget("controller-device-box"), True)
+ if can_remove is False:
+ tooltip = _("Disks are attaching to it")
I prefer: _("Cannot remove controller while devices are attached.")
elif controller.type == "virtio-serial":
for dev in self.vm.xmlobj.devices.channel:
if dev.address.compare_controller(controller, dev.address.type):
@@ -3069,6 +3074,8 @@ class vmmDetails(vmmGObjectUI):
if controller.index == 0 and dev.target_type == "virtio":
can_remove = False
break
+ if can_remove is False:
+ tooltip = _("Channels or Consoles are attaching to it")
Same as above
self.widget("config-remove").set_sensitive(can_remove)
self.widget("config-remove").set_tooltip_text(tooltip)
Thanks,
Cole
>From 6099ca674ed2f4c19da39f395e75fb410efb83f1 Mon Sep 17 00:00:00 2001
Message-Id: <6099ca674ed2f4c19da39f395e75fb410efb83f1.1533048617.git.crobinso@xxxxxxxxxx>
From: Cole Robinson <crobinso@xxxxxxxxxx>
Date: Tue, 31 Jul 2018 10:47:18 -0400
Subject: [PATCH virt-manager] details: Add _disable_device_remove helper
Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
---
virtManager/details.py | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/virtManager/details.py b/virtManager/details.py
index c5f231ed..e80a081c 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -147,7 +147,6 @@ remove_pages = [HW_LIST_TYPE_NIC, HW_LIST_TYPE_INPUT,
DETAILS_PAGE_CONSOLE,
DETAILS_PAGE_SNAPSHOTS) = range(3)
-_remove_tooltip = _("Remove this device from the virtual machine")
def _calculate_disk_bus_index(disklist):
@@ -1189,11 +1188,16 @@ class vmmDetails(vmmGObjectUI):
self.oldhwkey = newrow[HW_LIST_COL_DEVICE]
self.hw_selected()
+ def _disable_device_remove(self, tooltip):
+ self.widget("config-remove").set_sensitive(False)
+ self.widget("config-remove").set_tooltip_text(tooltip)
+
def hw_selected(self, page=None):
pagetype = self.force_get_hw_pagetype(page)
self.widget("config-remove").set_sensitive(True)
- self.widget("config-remove").set_tooltip_text(_remove_tooltip)
+ self.widget("config-remove").set_tooltip_text(
+ _("Remove this device from the virtual machine"))
self.widget("hw-panel").set_sensitive(True)
self.widget("hw-panel").show()
@@ -2732,15 +2736,10 @@ class vmmDetails(vmmGObjectUI):
self.widget("input-dev-mode").set_text(mode or "")
uiutil.set_grid_row_visible(self.widget("input-dev-mode"), bool(mode))
- tooltip = _remove_tooltip
- sensitive = True
if ((inp.type == "mouse" and inp.bus in ("xen", "ps2")) or
(inp.type == "keyboard" and inp.bus in ("xen", "ps2"))):
- sensitive = False
- tooltip = _("Hypervisor does not support removing this device")
-
- self.widget("config-remove").set_sensitive(sensitive)
- self.widget("config-remove").set_tooltip_text(tooltip)
+ self._disable_device_remove(
+ _("Hypervisor does not support removing this device"))
def refresh_graphics_page(self):
gfx = self.get_hw_selection(HW_LIST_COL_DEVICE)
--
2.17.1
_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list