[virt-tools-list] [virt-manager PATCH 3/4] addhardware: introduce populate_conroller_model_combo

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Wed Apr 16 09:51:51 UTC 2014


Introduce populate_conroller_model_combo for details
and addhardware.

Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
---
 virtManager/addhardware.py | 34 ++++++++++++++++++++++++++++++++++
 virtManager/details.py     | 14 ++------------
 2 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index b22a339..60e8033 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -113,6 +113,8 @@ class vmmAddHardware(vmmGObjectUI):
             "on_rng_type_changed": self.change_rng,
             "on_rng_backend_mode_changed": self.change_rng,
             "on_rng_backend_type_changed": self.change_rng,
+
+            "on_controller_type_changed": self.populate_controller_model,
         })
         self.bind_escape_key_close()
 
@@ -737,6 +739,27 @@ class vmmAddHardware(vmmGObjectUI):
                     combo.set_active_iter(row.iter)
                     break
 
+    @staticmethod
+    def populate_conroller_model_combo(combo, controller_type, widget_name, add_default=False):
+        model = combo.get_model()
+        model.clear()
+
+        if controller_type == virtinst.VirtualController.TYPE_USB:
+            model.append(["default", "Default"])
+            model.append(["ich9-ehci1", "USB 2"])
+            model.append(["nec-xhci", "USB 3"])
+            if widget_name is not None:
+                widget_name.set_sensitive(False)
+        elif controller_type == virtinst.VirtualController.TYPE_SCSI:
+            model.append(["default", "Default"])
+            model.append(["virtio-scsi", "VirtIO SCSI"])
+        else:
+            if add_default:
+                model.append([None, "Default"])
+                combo.set_sensitive(False)
+            if widget_name is not None:
+                widget_name.set_sensitive(True)
+
 
     #########################
     # UI population methods #
@@ -844,6 +867,17 @@ class vmmAddHardware(vmmGObjectUI):
         if len(model) > 0:
             widget.set_active(0)
 
+    def populate_controller_model(self, src):
+        ignore = src
+
+        controller_type = self.get_config_controller_type()
+        modellist = self.widget("controller-model")
+        modellist.set_sensitive(True)
+        self.populate_conroller_model_combo(modellist, controller_type, None, True)
+
+        if len(modellist.get_model()) > 0:
+            modellist.set_active(0)
+
 
     ########################
     # get_config_* methods #
diff --git a/virtManager/details.py b/virtManager/details.py
index 2e8991b..6fd48e7 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -3032,18 +3032,8 @@ class vmmDetails(vmmGObjectUI):
         combo = self.widget("controller-model")
         uiutil.set_grid_row_visible(combo, True)
 
-        model = combo.get_model()
-        model.clear()
-        if dev.type == virtinst.VirtualController.TYPE_USB:
-            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)
+        vmmAddHardware.populate_conroller_model_combo(combo, dev.type,
+                self.widget("config-remove"), False)
 
         uiutil.set_combo_entry(self.widget("controller-model"),
                              dev.model or "Default")
-- 
1.9.0




More information about the virt-tools-list mailing list