From 6802d9925d44dc6f3114712a94dc61fc0d903733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 5 Oct 2016 22:39:06 +0200 Subject: [PATCH] Avoid calling unnecessary domain_parser The construction of the domain_parser can generate RPC calls so it is better to avoid construct it if possible. issue5918 review26741002 --- tryton/gui/window/view_form/screen/screen.py | 3 +- .../window/view_form/view/screen_container.py | 35 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/tryton/gui/window/view_form/screen/screen.py b/tryton/gui/window/view_form/screen/screen.py index 4881484f31..036ff6d069 100644 --- a/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/gui/window/view_form/screen/screen.py @@ -288,7 +288,8 @@ class Screen(SignalEvent): def search_domain(self, search_string=None, set_text=False): domain = [] - if self.domain_parser and not self.parent: + # Test first parent to avoid calling unnecessary domain_parser + if not self.parent and self.domain_parser: if search_string is not None: domain = self.domain_parser.parse(search_string) else: diff --git a/tryton/gui/window/view_form/view/screen_container.py b/tryton/gui/window/view_form/view/screen_container.py index 0028de5c1a..17827c8f55 100644 --- a/tryton/gui/window/view_form/view/screen_container.py +++ b/tryton/gui/window/view_form/view/screen_container.py @@ -347,24 +347,25 @@ class ScreenContainer(object): self.do_search() def bookmark_match(self): - current_text = self.get_text() - current_domain = self.screen.domain_parser.parse(current_text) - self.search_entry.set_icon_activatable(gtk.ENTRY_ICON_SECONDARY, - bool(current_text)) - self.search_entry.set_icon_sensitive(gtk.ENTRY_ICON_SECONDARY, - bool(current_text)) icon_stock = self.search_entry.get_icon_stock(gtk.ENTRY_ICON_SECONDARY) - for id_, name, domain in self.bookmarks(): - text = self.screen.domain_parser.string(domain) - domain = self.screen.domain_parser.parse(text.decode('utf-8')) - if (text == current_text - or domain == current_domain): - if icon_stock != 'tryton-star': - self.search_entry.set_icon_from_stock( - gtk.ENTRY_ICON_SECONDARY, 'tryton-star') - self.search_entry.set_icon_tooltip_text( - gtk.ENTRY_ICON_SECONDARY, _('Remove this bookmark')) - return id_ + current_text = self.get_text() + if current_text: + current_domain = self.screen.domain_parser.parse(current_text) + self.search_entry.set_icon_activatable(gtk.ENTRY_ICON_SECONDARY, + bool(current_text)) + self.search_entry.set_icon_sensitive(gtk.ENTRY_ICON_SECONDARY, + bool(current_text)) + for id_, name, domain in self.bookmarks(): + text = self.screen.domain_parser.string(domain) + domain = self.screen.domain_parser.parse(text.decode('utf-8')) + if (text == current_text + or domain == current_domain): + if icon_stock != 'tryton-star': + self.search_entry.set_icon_from_stock( + gtk.ENTRY_ICON_SECONDARY, 'tryton-star') + self.search_entry.set_icon_tooltip_text( + gtk.ENTRY_ICON_SECONDARY, _('Remove this bookmark')) + return id_ if icon_stock != 'tryton-unstar': self.search_entry.set_icon_from_stock(gtk.ENTRY_ICON_SECONDARY, 'tryton-unstar')