Move connect helpers from util to baseclass

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2011-04-17 18:27:41 -04:00
parent ad8060d191
commit b7de618897
5 changed files with 33 additions and 34 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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():

View File

@ -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):

View File

@ -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