[virt-tools-list] [RFC PATCH 09/10] connection: Remove gtk and gobject dep

Cole Robinson crobinso at redhat.com
Mon Apr 18 18:06:51 UTC 2011


Use vmmGObject.signal_new. The few other locations with gtk deps are just
pushed further down. TUI can still trigger these paths but they aren't
critical path for now.

Most of the conversion was done with this vim replace:

%s/.*\(".*"\): (gobject.SIGNAL_RUN_FIRST,.*gobject.TYPE_NONE,\n.*\(\[.*\]\)),/v
mmGObject.signal_new(vmmConnection, \1, \2)/gc

Signed-off-by: Cole Robinson <crobinso at redhat.com>
---
 src/virtManager/connection.py |   91 ++++++++++++++++-------------------------
 1 files changed, 35 insertions(+), 56 deletions(-)

diff --git a/src/virtManager/connection.py b/src/virtManager/connection.py
index 001389f..c71ed2a 100644
--- a/src/virtManager/connection.py
+++ b/src/virtManager/connection.py
@@ -18,9 +18,6 @@
 # MA 02110-1301 USA.
 #
 
-import gobject
-import gtk
-
 import logging
 import os
 import sys
@@ -35,66 +32,17 @@ import libvirt
 import virtinst
 
 from virtManager import util
+from virtManager.baseclass import vmmGObject
+
 from virtManager.domain import vmmDomain
 from virtManager.network import vmmNetwork
 from virtManager.storagepool import vmmStoragePool
 from virtManager.interface import vmmInterface
 from virtManager.netdev import vmmNetDevice
 from virtManager.mediadev import vmmMediaDevice
-from virtManager.baseclass import vmmGObject
 from virtManager.nodedev import vmmNodeDevice
 
 class vmmConnection(vmmGObject):
-    __gsignals__ = {
-        "vm-added": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                     [str, str]),
-        "vm-removed": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                       [str, str]),
-
-        "net-added": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                      [str, str]),
-        "net-removed": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                        [str, str]),
-        "net-started": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                        [str, str]),
-        "net-stopped": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                        [str, str]),
-
-        "pool-added": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                       [str, str]),
-        "pool-removed": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                         [str, str]),
-        "pool-started": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                         [str, str]),
-        "pool-stopped": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                         [str, str]),
-
-        "interface-added": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                            [str, str]),
-        "interface-removed": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                              [str, str]),
-        "interface-started": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                              [str, str]),
-        "interface-stopped": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                              [str, str]),
-
-        "nodedev-added": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                          [str, str]),
-        "nodedev-removed": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                            [str, str]),
-
-        "mediadev-added": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                          [object]),
-        "mediadev-removed": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                            [str]),
-
-        "resources-sampled": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                              []),
-        "state-changed": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                          []),
-        "connect-error": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                          [str]),
-        }
 
     STATE_DISCONNECTED = 0
     STATE_CONNECTING = 1
@@ -993,6 +941,8 @@ class vmmConnection(vmmGObject):
         return 0
 
     def _do_creds_dialog(self, creds):
+        import gtk
+
         try:
             gtk.gdk.threads_enter()
             return self._do_creds_dialog_main(creds)
@@ -1000,6 +950,8 @@ class vmmConnection(vmmGObject):
             gtk.gdk.threads_leave()
 
     def _do_creds_dialog_main(self, creds):
+        import gtk
+
         dialog = gtk.Dialog("Authentication required", None, 0,
                             (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                              gtk.STOCK_OK, gtk.RESPONSE_OK))
@@ -1149,8 +1101,8 @@ class vmmConnection(vmmGObject):
 
             self.connectError = "%s\n\n%s" % (str(value), str(tb))
 
-        # We want to kill off this thread asap, so schedule a gobject
-        # idle even to inform the UI of result
+        # We want to kill off this thread asap, so schedule an
+        # idle event to inform the UI of result
         logging.debug("Background open thread complete, scheduling notify")
         self.safe_idle_add(self._open_notify)
         self.connectThread = None
@@ -1642,3 +1594,30 @@ class vmmConnection(vmmGObject):
                                        self.config.get_iso_paths)
 
 vmmGObject.type_register(vmmConnection)
+vmmGObject.signal_new(vmmConnection, "vm-added", [str, str])
+vmmGObject.signal_new(vmmConnection, "vm-removed", [str, str])
+
+vmmGObject.signal_new(vmmConnection, "net-added", [str, str])
+vmmGObject.signal_new(vmmConnection, "net-removed", [str, str])
+vmmGObject.signal_new(vmmConnection, "net-started", [str, str])
+vmmGObject.signal_new(vmmConnection, "net-stopped", [str, str])
+
+vmmGObject.signal_new(vmmConnection, "pool-added", [str, str])
+vmmGObject.signal_new(vmmConnection, "pool-removed", [str, str])
+vmmGObject.signal_new(vmmConnection, "pool-started", [str, str])
+vmmGObject.signal_new(vmmConnection, "pool-stopped", [str, str])
+
+vmmGObject.signal_new(vmmConnection, "interface-added", [str, str])
+vmmGObject.signal_new(vmmConnection, "interface-removed", [str, str])
+vmmGObject.signal_new(vmmConnection, "interface-started", [str, str])
+vmmGObject.signal_new(vmmConnection, "interface-stopped", [str, str])
+
+vmmGObject.signal_new(vmmConnection, "nodedev-added", [str, str])
+vmmGObject.signal_new(vmmConnection, "nodedev-removed", [str, str])
+
+vmmGObject.signal_new(vmmConnection, "mediadev-added", [object])
+vmmGObject.signal_new(vmmConnection, "mediadev-removed", [str])
+
+vmmGObject.signal_new(vmmConnection, "resources-sampled", [])
+vmmGObject.signal_new(vmmConnection, "state-changed", [])
+vmmGObject.signal_new(vmmConnection, "connect-error", [str])
-- 
1.7.4




More information about the virt-tools-list mailing list