From 92aea7c56554397138154544f36c2ca6b4cbdc52 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Wed, 14 Mar 2018 19:06:30 -0400 Subject: [PATCH] engine: Have windows increment/decrement windows directly --- virtManager/create.py | 6 ++---- virtManager/details.py | 6 ++---- virtManager/engine.py | 25 +++++++++++-------------- virtManager/host.py | 6 ++---- virtManager/manager.py | 6 ++---- 5 files changed, 19 insertions(+), 30 deletions(-) diff --git a/virtManager/create.py b/virtManager/create.py index 2f0a732a8..188ded4ce 100644 --- a/virtManager/create.py +++ b/virtManager/create.py @@ -120,8 +120,6 @@ def is_virt_bootstrap_installed(): class vmmCreate(vmmGObjectUI): __gsignals__ = { "action-show-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]), - "create-opened": (GObject.SignalFlags.RUN_FIRST, None, []), - "create-closed": (GObject.SignalFlags.RUN_FIRST, None, []), } def __init__(self): @@ -210,14 +208,14 @@ class vmmCreate(vmmGObjectUI): if not self.is_visible(): self._reset_state(uri) self.topwin.set_transient_for(parent) - self.emit("create-opened") + vmmEngine.get_instance().increment_window_counter() self.topwin.present() def _close(self, ignore1=None, ignore2=None): if self.is_visible(): logging.debug("Closing new vm wizard") - self.emit("create-closed") + vmmEngine.get_instance().decrement_window_counter() self.topwin.hide() diff --git a/virtManager/details.py b/virtManager/details.py index 8df91719c..0912ac56d 100644 --- a/virtManager/details.py +++ b/virtManager/details.py @@ -341,8 +341,6 @@ def _label_for_os_type(os_type): class vmmDetails(vmmGObjectUI): __gsignals__ = { "action-view-manager": (GObject.SignalFlags.RUN_FIRST, None, []), - "details-closed": (GObject.SignalFlags.RUN_FIRST, None, []), - "details-opened": (GObject.SignalFlags.RUN_FIRST, None, []), "customize-finished": (GObject.SignalFlags.RUN_FIRST, None, []), } @@ -627,7 +625,7 @@ class vmmDetails(vmmGObjectUI): if vis: return - self.emit("details-opened") + vmmEngine.get_instance().increment_window_counter() self.refresh_vm_state() def customize_finish(self, src): @@ -675,7 +673,7 @@ class vmmDetails(vmmGObjectUI): except Exception: logging.error("Failure when disconnecting from desktop server") - self.emit("details-closed") + vmmEngine.get_instance().decrement_window_counter() return 1 def is_visible(self): diff --git a/virtManager/engine.py b/virtManager/engine.py index cfd4efb12..aabc79830 100644 --- a/virtManager/engine.py +++ b/virtManager/engine.py @@ -416,16 +416,21 @@ class vmmEngine(vmmGObject): # window counting and exit handling # ##################################### - def increment_window_counter(self, src): - ignore = src + def increment_window_counter(self): + """ + Public function, called by toplevel windows + """ self.windows += 1 logging.debug("window counter incremented to %s", self.windows) - def decrement_window_counter(self, src): + def decrement_window_counter(self): + """ + Public function, called by toplevel windows + """ self.windows -= 1 logging.debug("window counter decremented to %s", self.windows) - self._exit_app_if_no_windows(src) + self._exit_app_if_no_windows() def _can_exit(self): # Don't exit if system tray is enabled @@ -433,11 +438,11 @@ class vmmEngine(vmmGObject): self._systray and not self._systray.is_visible()) - def _exit_app_if_no_windows(self, src=None): + def _exit_app_if_no_windows(self): def cb(): if self._can_exit(): logging.debug("No windows found, requesting app exit") - self.exit_app(src or self) + self.exit_app() self.idle_add(cb) def exit_app(self): @@ -627,8 +632,6 @@ class vmmEngine(vmmGObject): obj = vmmHost(conn) obj.connect("action-view-manager", self._do_show_manager) - obj.connect("host-opened", self.increment_window_counter) - obj.connect("host-closed", self.decrement_window_counter) connstate.windowHost = obj return connstate.windowHost @@ -676,8 +679,6 @@ class vmmEngine(vmmGObject): from .details import vmmDetails obj = vmmDetails(self._connobjs[uri].get_vm(connkey)) obj.connect("action-view-manager", self._do_show_manager) - obj.connect("details-opened", self.increment_window_counter) - obj.connect("details-closed", self.decrement_window_counter) detailsmap[connkey] = obj return detailsmap[connkey] @@ -713,8 +714,6 @@ class vmmEngine(vmmGObject): obj.connect("action-show-create", self._do_show_create) obj.connect("action-show-host", self._do_show_host) obj.connect("action-show-connect", self._do_show_connect) - obj.connect("manager-opened", self.increment_window_counter) - obj.connect("manager-closed", self.decrement_window_counter) obj.connect("remove-conn", self._remove_conn) self.windowManager = obj @@ -743,8 +742,6 @@ class vmmEngine(vmmGObject): from .create import vmmCreate obj = vmmCreate() obj.connect("action-show-domain", self._do_show_vm) - obj.connect("create-opened", self.increment_window_counter) - obj.connect("create-closed", self.decrement_window_counter) self.windowCreate = obj return self.windowCreate diff --git a/virtManager/host.py b/virtManager/host.py index 89f0fbe0d..b56c7c864 100644 --- a/virtManager/host.py +++ b/virtManager/host.py @@ -54,8 +54,6 @@ EDIT_INTERFACE_STARTMODE, class vmmHost(vmmGObjectUI): __gsignals__ = { "action-view-manager": (GObject.SignalFlags.RUN_FIRST, None, []), - "host-closed": (GObject.SignalFlags.RUN_FIRST, None, []), - "host-opened": (GObject.SignalFlags.RUN_FIRST, None, []), } def __init__(self, conn): @@ -254,7 +252,7 @@ class vmmHost(vmmGObjectUI): if vis: return - self.emit("host-opened") + vmmEngine.get_instance().increment_window_counter() def is_visible(self): return self.topwin.get_visible() @@ -267,7 +265,7 @@ class vmmHost(vmmGObjectUI): self.confirm_changes() self.topwin.hide() - self.emit("host-closed") + vmmEngine.get_instance().decrement_window_counter() return 1 diff --git a/virtManager/manager.py b/virtManager/manager.py index 398e16b07..e3a3939d4 100644 --- a/virtManager/manager.py +++ b/virtManager/manager.py @@ -96,8 +96,6 @@ class vmmManager(vmmGObjectUI): "action-show-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]), "action-show-host": (GObject.SignalFlags.RUN_FIRST, None, [str]), "action-show-create": (GObject.SignalFlags.RUN_FIRST, None, [str]), - "manager-closed": (GObject.SignalFlags.RUN_FIRST, None, []), - "manager-opened": (GObject.SignalFlags.RUN_FIRST, None, []), "remove-conn": (GObject.SignalFlags.RUN_FIRST, None, [str]), } @@ -203,7 +201,7 @@ class vmmManager(vmmGObjectUI): self.topwin.move(*self.prev_position) self.prev_position = None - self.emit("manager-opened") + vmmEngine.get_instance().increment_window_counter() def close(self, src_ignore=None, src2_ignore=None): if not self.is_visible(): @@ -212,7 +210,7 @@ class vmmManager(vmmGObjectUI): logging.debug("Closing manager") self.prev_position = self.topwin.get_position() self.topwin.hide() - self.emit("manager-closed") + vmmEngine.get_instance().decrement_window_counter() return 1