From f58c282c4888a05819f866d21900b1f934004043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=C3=89vrard?= Date: Tue, 29 Mar 2011 11:19:17 +0200 Subject: [PATCH 1/2] Add checkbutton to show content of sha field --- .../window/view_form/view/form_gtk/char.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tryton/gui/window/view_form/view/form_gtk/char.py b/tryton/gui/window/view_form/view/form_gtk/char.py index a99550a0e0..28fad0dde1 100644 --- a/tryton/gui/window/view_form/view/form_gtk/char.py +++ b/tryton/gui/window/view_form/view/form_gtk/char.py @@ -1,7 +1,12 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. +import gettext + import gtk from interface import WidgetInterface +from tryton.common import Tooltips + +_ = gettext.gettext class Char(WidgetInterface): "Char" @@ -50,4 +55,21 @@ class Sha(Char): def __init__(self, field_name, model_name, window, attrs=None): super(Sha, self).__init__(field_name, model_name, window, attrs=attrs) - self.entry.set_visibility(False) + self.entry.props.visibility = False + + self.visibility_checkbox = gtk.CheckButton() + self.visibility_checkbox.connect('toggled', self.toggle_visibility) + Tooltips().set_tip(self.visibility_checkbox, _('Show plain text')) + self.widget.pack_start(self.visibility_checkbox, expand=False) + + def _readonly_set(self, value): + super(Char, self)._readonly_set(value) + self.entry.set_editable(not value) + self.visibility_checkbox.props.visible = not value + if value: + self.widget.set_focus_chain([]) + else: + self.widget.set_focus_chain([self.entry, self.visibility_checkbox]) + + def toggle_visibility(self, button): + self.entry.props.visibility = not self.entry.props.visibility From 978890855b898573b9742d6ea045c92db9e9cca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=C3=89vrard?= Date: Tue, 29 Mar 2011 15:20:39 +0200 Subject: [PATCH 2/2] Fix domain inversion localization --- tryton/common/domain_inversion.py | 22 ++++++++++++++++++---- tryton/gui/window/view_form/model/field.py | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tryton/common/domain_inversion.py b/tryton/common/domain_inversion.py index 5004ead4ba..b0222ce68e 100644 --- a/tryton/common/domain_inversion.py +++ b/tryton/common/domain_inversion.py @@ -22,7 +22,9 @@ OPERATORS = { 'not child_of': lambda a, b: True, } -def locale_part(expression): +def locale_part(expression, field_name): + if expression == field_name: + return 'id' if '.' in expression: fieldname, local = expression.split('.', 1) return local @@ -75,14 +77,14 @@ def eval_domain(domain, context, boolop=operator.and_): return boolop(eval_domain(domain[0], context), eval_domain(domain[1:], context, boolop)) -def localize_domain(domain): +def localize_domain(domain, field_name=None): "returns only locale part of domain. eg: langage.code -> code" if domain in ('AND', 'OR', True, False): return domain elif is_leaf(domain): - return [locale_part(domain[0])] + domain[1:] + return [locale_part(domain[0], field_name)] + domain[1:] else: - return [localize_domain(part) for part in domain] + return [localize_domain(part, field_name) for part in domain] def unlocalize_domain(domain, fieldname): if domain in ('AND', 'OR', True, False): @@ -403,6 +405,17 @@ def test_evaldomain(): assert not eval_domain(domain, {'x': 5}) assert not eval_domain(domain, {'x': 11}) +def test_localize(): + domain = [['x', '=', 5]] + assert localize_domain(domain) == [['x', '=', 5]] + + domain = [['x', '=', 5], ['x.code', '=', 7]] + assert localize_domain(domain, 'x') == [['id', '=', 5], ['code', '=', 7]] + + domain = ['OR', ['AND', ['x', '>', 7], ['x', '<', 15]], ['x.code', '=', 8]] + assert localize_domain(domain, 'x') == \ + ['OR', ['AND', ['id', '>', 7], ['id', '<', 15]], ['code', '=', 8]] + if __name__ == '__main__': test_simple_inversion() test_and_inversion() @@ -414,3 +427,4 @@ if __name__ == '__main__': test_parse() test_simplify() test_evaldomain() + test_localize() diff --git a/tryton/gui/window/view_form/model/field.py b/tryton/gui/window/view_form/model/field.py index 9d24c5f782..3275a97843 100644 --- a/tryton/gui/window/view_form/model/field.py +++ b/tryton/gui/window/view_form/model/field.py @@ -394,7 +394,7 @@ class M2OField(CharField): def domain_get(self, record): screen_domain, attr_domain = self.domains_get(record) - return localize_domain(inverse_leaf(screen_domain)) + attr_domain + return localize_domain(inverse_leaf(screen_domain), self.name) + attr_domain class O2OField(M2OField):