From 5e2829fcd4abc7591098ab62421f42f7599342a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 27 Mar 2018 10:46:16 +0200 Subject: [PATCH] Disconnect focus-out callback when xxx2many widget is destroyed Once destroyed, the linked screen has no view to call set_value on. issue7259 review36071002 --- tryton/gui/window/view_form/view/form_gtk/many2many.py | 3 ++- tryton/gui/window/view_form/view/form_gtk/one2many.py | 5 +++-- tryton/gui/window/view_form/view/form_gtk/widget.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tryton/gui/window/view_form/view/form_gtk/many2many.py b/tryton/gui/window/view_form/view/form_gtk/many2many.py index 8fb545bb06..7ae5c416aa 100644 --- a/tryton/gui/window/view_form/view/form_gtk/many2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/many2many.py @@ -47,7 +47,7 @@ class Many2Many(Widget): self.wid_text = PlaceholderEntry() self.wid_text.set_placeholder_text(_('Search')) self.wid_text.set_property('width_chars', 13) - self.wid_text.connect('focus-out-event', lambda *a: self._focus_out()) + self.wid_text.connect('focus-out-event', self._focus_out) self.focus_out = True hbox.pack_start(self.wid_text, expand=True, fill=True) @@ -139,6 +139,7 @@ class Many2Many(Widget): return False def destroy(self): + self.wid_text.disconnect_by_func(self._focus_out) self.screen.destroy() def _sig_add(self, *args): diff --git a/tryton/gui/window/view_form/view/form_gtk/one2many.py b/tryton/gui/window/view_form/view/form_gtk/one2many.py index 84ed251ee8..b913abe493 100644 --- a/tryton/gui/window/view_form/view/form_gtk/one2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/one2many.py @@ -90,8 +90,7 @@ class One2Many(Widget): self.wid_text = PlaceholderEntry() self.wid_text.set_placeholder_text(_('Search')) self.wid_text.set_property('width_chars', 13) - self.wid_text.connect('focus-out-event', - lambda *a: self._focus_out()) + self.wid_text.connect('focus-out-event', self._focus_out) hbox.pack_start(self.wid_text, expand=True, fill=True) if int(self.attrs.get('completion', 1)): @@ -235,6 +234,8 @@ class One2Many(Widget): return False def destroy(self): + if self.attrs.get('add_remove'): + self.wid_text.disconnect_by_func(self._focus_out) self.screen.destroy() def _on_activate(self): diff --git a/tryton/gui/window/view_form/view/form_gtk/widget.py b/tryton/gui/window/view_form/view/form_gtk/widget.py index 9940ad5d85..ab744378b3 100644 --- a/tryton/gui/window/view_form/view/form_gtk/widget.py +++ b/tryton/gui/window/view_form/view/form_gtk/widget.py @@ -86,7 +86,7 @@ class Widget(object): self.visible = True widget.show() - def _focus_out(self): + def _focus_out(self, *args): if not self.field: return False if not self.visible: