From f7b05912f00bc97dca0e2925f8911d169c033f46 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Sat, 11 Apr 2015 14:34:38 -0400 Subject: [PATCH] engine: Before launching any error, try to find a parent dialog --- virtManager/engine.py | 28 ++++++++++++++++++++++++---- virtManager/error.py | 15 ++++++++++++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/virtManager/engine.py b/virtManager/engine.py index ea7749c4..01101f8b 100644 --- a/virtManager/engine.py +++ b/virtManager/engine.py @@ -75,6 +75,7 @@ class vmmEngine(vmmGObject): self.conns = {} self.err = vmmErrorDialog() + self.err.set_find_parent_cb(self._find_error_parent_cb) self.timer = None self.last_timeout = 0 @@ -456,6 +457,29 @@ class vmmEngine(vmmGObject): self.connect("conn-removed", self.inspection.conn_removed) return + def _find_error_parent_cb(self): + """ + Search over the toplevel windows for any that are visible or have + focus, and use that + """ + windowlist = [self.windowManager] + for conndict in self.conns.values(): + windowlist.extend(conndict["windowDetails"].values()) + windowlist.extend( + [conndict["windowHost"] for conndict in self.conns.values()]) + + use_win = None + for window in windowlist: + if not window: + continue + if window.topwin.has_focus(): + use_win = window + break + if not use_win and window.is_visible(): + use_win = window + + if use_win: + return use_win.topwin def make_conn(self, uri, probe=False): conn = self._check_conn(uri) @@ -620,10 +644,6 @@ class vmmEngine(vmmGObject): msg += "\n\n" msg += _("Would you still like to remember this connection?") - if (self.windowManager and - self.windowManager.is_visible()): - self.err.set_parent(self.windowManager.topwin) - title = _("Virtual Machine Manager Connection Failure") if probe_connection: remember_connection = self.err.show_err(msg, details, title, diff --git a/virtManager/error.py b/virtManager/error.py index 7dc53a7c..30fc67e3 100644 --- a/virtManager/error.py +++ b/virtManager/error.py @@ -54,18 +54,27 @@ class vmmErrorDialog(vmmGObject): self._parent = parent self._simple = None + # Callback to lookup the parent window if none is specified. + # Used by engine.py for properly parenting windows + self._find_parent_cb = None + # Allows the error owner to easily override default modality self._modal_default = False def _cleanup(self): - pass + self._find_parent_cb = None def set_modal_default(self, val): self._modal_default = val + def set_find_parent_cb(self, cb): + self._find_parent_cb = cb def set_parent(self, parent): self._parent = parent def get_parent(self): - return self._parent + parent = self._parent + if parent is None and self._find_parent_cb: + parent = self._find_parent_cb() + return parent def show_err(self, summary, details=None, title="", modal=None, debug=True, @@ -243,7 +252,7 @@ class vmmErrorDialog(vmmGObject): choose_button = Gtk.STOCK_OPEN fcdialog = Gtk.FileChooserDialog(title=dialog_name, - parent=self._parent, + parent=self.get_parent(), action=dialog_type, buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,