engine: Have windows increment/decrement windows directly

This commit is contained in:
Cole Robinson 2018-03-14 19:06:30 -04:00
parent 9fa9777f1c
commit 92aea7c565
5 changed files with 19 additions and 30 deletions

View File

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

View File

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

View File

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

View File

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

View File

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