From b7de618897ffb1e4f32c3fe7fe1dc47ee08b1f56 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Sun, 17 Apr 2011 18:27:41 -0400 Subject: [PATCH] Move connect helpers from util to baseclass Signed-off-by: Cole Robinson --- src/virt-manager.py.in | 3 +-- src/virtManager/baseclass.py | 27 +++++++++++++++++++++++++++ src/virtManager/create.py | 8 ++++---- src/virtManager/domain.py | 2 +- src/virtManager/util.py | 27 --------------------------- 5 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/virt-manager.py.in b/src/virt-manager.py.in index 5affdc601..002c71a16 100755 --- a/src/virt-manager.py.in +++ b/src/virt-manager.py.in @@ -265,8 +265,7 @@ def show_engine(engine, show, uri, uuid, no_conn_auto): conn = engine.add_connection(uri) if conn and show: - import virtManager.util as util - util.connect_opt_out(conn, "state-changed", + conn.connect_opt_out("state-changed", _conn_state_changed, engine, show, uri, uuid) diff --git a/src/virtManager/baseclass.py b/src/virtManager/baseclass.py index 866cb6a2a..5add1d10f 100644 --- a/src/virtManager/baseclass.py +++ b/src/virtManager/baseclass.py @@ -95,6 +95,33 @@ class vmmGObject(gobject.GObject): from virtManager import halhelper return halhelper.get_hal_helper() + def connect_once(self, signal, func, *args): + id_list = [] + + def wrap_func(*wrapargs): + if id_list: + self.disconnect(id_list[0]) + + return func(*wrapargs) + + conn_id = self.connect(signal, wrap_func, *args) + id_list.append(conn_id) + + return conn_id + + def connect_opt_out(self, signal, func, *args): + id_list = [] + + def wrap_func(*wrapargs): + ret = func(*wrapargs) + if ret and id_list: + self.disconnect(id_list[0]) + + conn_id = self.connect(signal, wrap_func, *args) + id_list.append(conn_id) + + return conn_id + def __del__(self): if hasattr(gobject.GObject, "__del__"): getattr(gobject.GObject, "__del__")(self) diff --git a/src/virtManager/create.py b/src/virtManager/create.py index 67702339d..9ec7ea012 100644 --- a/src/virtManager/create.py +++ b/src/virtManager/create.py @@ -1691,8 +1691,8 @@ class vmmCreate(vmmGObjectUI): else: # Register a status listener, which will restart the # guest after the install has finished - util.connect_opt_out(vm, "status-changed", - self.check_install_status, guest) + vm.connect_opt_out("status-changed", + self.check_install_status, guest) def check_install_status(self, vm, ignore1, ignore2, virtinst_guest=None): @@ -1714,8 +1714,8 @@ class vmmCreate(vmmGObjectUI): # will force one final restart. virtinst_guest.continue_install() - util.connect_opt_out(vm, "status-changed", - self.check_install_status, None) + vm.connect_opt_out("status-changed", + self.check_install_status, None) return True if vm.get_install_abort(): diff --git a/src/virtManager/domain.py b/src/virtManager/domain.py index 69d3529fd..16c271006 100644 --- a/src/virtManager/domain.py +++ b/src/virtManager/domain.py @@ -1100,7 +1100,7 @@ class vmmDomain(vmmDomainBase): # Request a shutdown self.shutdown() - self.reboot_listener = util.connect_opt_out(self, "status-changed", + self.reboot_listener = self.connect_opt_out("status-changed", reboot_listener, self) def shutdown(self): diff --git a/src/virtManager/util.py b/src/virtManager/util.py index 947110493..057baadc2 100644 --- a/src/virtManager/util.py +++ b/src/virtManager/util.py @@ -305,33 +305,6 @@ def pretty_hv(gtype, domtype): return label -def connect_once(obj, signal, func, *args): - id_list = [] - - def wrap_func(*wrapargs): - if id_list: - obj.disconnect(id_list[0]) - - return func(*wrapargs) - - conn_id = obj.connect(signal, wrap_func, *args) - id_list.append(conn_id) - - return conn_id - -def connect_opt_out(obj, signal, func, *args): - id_list = [] - - def wrap_func(*wrapargs): - ret = func(*wrapargs) - if ret and id_list: - obj.disconnect(id_list[0]) - - conn_id = obj.connect(signal, wrap_func, *args) - id_list.append(conn_id) - - return conn_id - def idle_emit(self, signal, *args): """ Safe wrapper for using 'self.emit' with gobject.idle_add