From 5a9954fa889f425c2b8d7b0148cb7a72d4cebb24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 15 Apr 2012 17:02:09 +0200 Subject: [PATCH] Enforce nomodal to try to put focus back The widget with the focus could disappear when setting back the focus so it tries to put the focus to one of its parents. --- tryton/gui/window/nomodal.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tryton/gui/window/nomodal.py b/tryton/gui/window/nomodal.py index 95e5206602..b4bc0dc309 100644 --- a/tryton/gui/window/nomodal.py +++ b/tryton/gui/window/nomodal.py @@ -12,7 +12,11 @@ class NoModal(object): self.parent = common.get_toplevel_window() self.sensible_widget = common.get_sensible_widget(self.parent) self.page = None - self.parent_focus = self.parent.get_focus() + self.parent_focus = [] + focus = self.parent.get_focus() + while focus: + self.parent_focus.append(focus) + focus = focus.get_parent() def register(self): main = Main.get_main() @@ -29,5 +33,7 @@ class NoModal(object): return self.parent.present() self.sensible_widget.props.sensitive = True - if self.parent_focus: - self.parent_focus.grab_focus() + for focus in self.parent_focus: + if focus and focus.is_ancestor(self.parent): + focus.grab_focus() + break