[virt-tools-list] [PATCH] Let user select between VNC and Spice during vm create

Marc-André Lureau marcandre.lureau at redhat.com
Thu Mar 17 19:21:17 UTC 2011


---
 src/virtManager/create.py |   45 ++++++++++++++++++++++++--------
 src/vmm-create.glade      |   63 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 95 insertions(+), 13 deletions(-)

diff --git a/src/virtManager/create.py b/src/virtManager/create.py
index f742ac5..1921de8 100644
--- a/src/virtManager/create.py
+++ b/src/virtManager/create.py
@@ -289,6 +289,11 @@ class vmmCreate(vmmGObjectUI):
         hyperList.add_attribute(text, 'sensitive', 3)
         hyperList.set_model(hyperModel)
 
+        # Graphics
+        graphics_list = self.window.get_widget("config-graphics")
+        graphics_model = gtk.ListStore(str, str)
+        graphics_list.set_model(graphics_model)
+
         # Sparse tooltip
         sparse_info = self.window.get_widget("config-storage-nosparse-info")
         uihelpers.set_sparse_tooltip(sparse_info)
@@ -374,6 +379,7 @@ class vmmCreate(vmmGObjectUI):
         net_warn_icon.hide()
         net_warn_box.hide()
         net_expander.set_expanded(False)
+        self.populate_graphics()
 
 
     def set_conn_state(self):
@@ -706,6 +712,14 @@ class vmmCreate(vmmGObjectUI):
         for url in urls:
             model.append([url])
 
+    def populate_graphics(self):
+        graphics_list = self.window.get_widget("config-graphics")
+        model = graphics_list.get_model()
+        model.clear()
+        model.append(["VNC", virtinst.VirtualGraphics.TYPE_VNC])
+        if not bool(self.config.get_spice_error()):
+            model.append(["Spice", virtinst.VirtualGraphics.TYPE_SPICE])
+        graphics_list.set_active(0)
 
     def change_caps(self, gtype=None, dtype=None, arch=None):
 
@@ -855,6 +869,14 @@ class vmmCreate(vmmGObjectUI):
     def get_config_import_path(self):
         return self.window.get_widget("install-import-entry").get_text()
 
+    def get_config_graphics(self):
+        list = self.window.get_widget("config-graphics")
+        idx = list.get_active()
+        gtype = 'vnc'
+        if idx >= 0:
+            strtype, gtype = list.get_model()[idx]
+        return gtype
+
     def get_default_path(self, name):
         # Don't generate a new path if the install failed
         if self.failed_guest:
@@ -1191,17 +1213,6 @@ class vmmCreate(vmmGObjectUI):
                               "".join(traceback.format_exc()))
             return None
 
-        # Set up graphics device
-        try:
-            guest.add_device(virtinst.VirtualGraphics(
-                                        type=virtinst.VirtualGraphics.TYPE_VNC,
-                                        conn=guest.conn))
-            guest.add_device(virtinst.VirtualVideoDevice(conn=guest.conn))
-        except Exception, e:
-            self.err.show_err(_("Error setting up graphics device:") + str(e),
-                              "".join(traceback.format_exc()))
-            return None
-
         # Set up sound device (if present)
         guest.sound_devs = []
         try:
@@ -1462,6 +1473,18 @@ class vmmCreate(vmmGObjectUI):
         self.guest.installer.os_type = self.capsguest.os_type
         self.guest.installer.arch = self.capsguest.arch
 
+        # Set up graphics device
+        try:
+            gtype = self.get_config_graphics()
+            self.guest.add_device(virtinst.VirtualGraphics(
+                    type=gtype,
+                    conn=self.guest.conn))
+            self.guest.add_device(virtinst.VirtualVideoDevice(conn=self.guest.conn))
+        except Exception, e:
+            self.err.show_err(_("Error setting up graphics device:") + str(e),
+                              "".join(traceback.format_exc()))
+            return None
+
         nettype, devname, macaddr = self.get_config_network_info()
 
         if nettype is None:
diff --git a/src/vmm-create.glade b/src/vmm-create.glade
index 4882e7f..e5d5b95 100644
--- a/src/vmm-create.glade
+++ b/src/vmm-create.glade
@@ -1613,8 +1613,8 @@ User shouldn't see this.</property>
                                       <packing>
                                         <property name="left_attach">1</property>
                                         <property name="right_attach">2</property>
-                                        <property name="top_attach">5</property>
-                                        <property name="bottom_attach">6</property>
+                                        <property name="top_attach">6</property>
+                                        <property name="bottom_attach">7</property>
                                         <property name="x_options">GTK_FILL</property>
                                       </packing>
                                     </child>
@@ -1631,6 +1631,65 @@ User shouldn't see this.</property>
                                         <property name="x_options">GTK_FILL</property>
                                       </packing>
                                     </child>
+				  <child>
+				    <widget class="GtkLabel" id="label125">
+				      <property name="visible">True</property>
+				      <property name="label" translatable="yes"><span color='#484848'>Graphics:</span></property>
+				      <property name="use_underline">False</property>
+				      <property name="use_markup">True</property>
+				      <property name="justify">GTK_JUSTIFY_LEFT</property>
+				      <property name="wrap">False</property>
+				      <property name="selectable">False</property>
+				      <property name="xalign">1</property>
+				      <property name="yalign">0.5</property>
+				      <property name="xpad">0</property>
+				      <property name="ypad">0</property>
+				      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+				      <property name="width_chars">-1</property>
+				      <property name="single_line_mode">False</property>
+				      <property name="angle">0</property>
+				    </widget>
+				    <packing>
+				      <property name="left_attach">0</property>
+				      <property name="right_attach">1</property>
+				      <property name="top_attach">5</property>
+				      <property name="bottom_attach">6</property>
+				      <property name="x_options">fill</property>
+				      <property name="y_options"></property>
+				    </packing>
+				  </child>
+
+				  <child>
+				    <widget class="GtkAlignment" id="alignment24">
+				      <property name="visible">True</property>
+				      <property name="xalign">0</property>
+				      <property name="yalign">0.5</property>
+				      <property name="xscale">0</property>
+				      <property name="yscale">1</property>
+				      <property name="top_padding">0</property>
+				      <property name="bottom_padding">0</property>
+				      <property name="left_padding">0</property>
+				      <property name="right_padding">0</property>
+
+				      <child>
+					<widget class="GtkComboBox" id="config-graphics">
+					  <property name="visible">True</property>
+					  <property name="items" translatable="yes"></property>
+					  <property name="add_tearoffs">False</property>
+					  <property name="focus_on_click">True</property>
+					</widget>
+				      </child>
+				    </widget>
+				    <packing>
+				      <property name="left_attach">1</property>
+				      <property name="right_attach">2</property>
+				      <property name="top_attach">5</property>
+				      <property name="bottom_attach">6</property>
+				      <property name="x_options">fill</property>
+				      <property name="y_options">fill</property>
+				    </packing>
+				  </child>
+
                                   </widget>
                                 </child>
                               </widget>
-- 
1.7.4




More information about the virt-tools-list mailing list