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

Chen Hanxiao chen_han_xiao at 126.com
Thu Apr 24 15:22:32 UTC 2014


On 04/24/2014 11:12 PM, Cole Robinson wrote:
> On 04/21/2014 07:39 PM, Chen Hanxiao wrote:
>> 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 at cn.fujitsu.com>
>>>> ---
>>>>    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 :(
>>
> Can you describe how to reproduce? I'll take a look.
>
> - Cole
>

a)  vm -> details
b) select one device(not USB controller)
c) right click on USB controller
d) we could use the popup menu to remove USB controller

- Chen





More information about the virt-tools-list mailing list