From 56b7542557e75354b82bdc8e50fb8df4a478fee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 29 Aug 2018 09:03:10 +0200 Subject: [PATCH] Use apply_label_attributes instead of get_label_attributes and do not set editable class to label not linked to field issue7631 issue7644 review58381002 --- CHANGELOG | 1 + tryton/client.py | 6 +++++ tryton/common/common.py | 23 ++++++------------- .../view_form/view/form_gtk/many2many.py | 7 ++---- .../view_form/view/form_gtk/one2many.py | 7 ++---- .../view_form/view/form_gtk/state_widget.py | 8 ++----- tryton/gui/window/view_form/view/list.py | 6 +---- 7 files changed, 21 insertions(+), 37 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c14c81b4dc..660ee81b9d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Use CSS to style label * New icons * Support timestamp field * Add support for Python 3.7 diff --git a/tryton/client.py b/tryton/client.py index eaedefa0a2..53fdfbcbe3 100644 --- a/tryton/client.py +++ b/tryton/client.py @@ -26,6 +26,12 @@ def main(): .invalid entry, entry.invalid, .invalid text, text.invalid { border-color: @error_color; } + label.required { + font-weight: bold; + } + label.editable { + font-style: italic; + } """ screen = Gdk.Screen.get_default() diff --git a/tryton/common/common.py b/tryton/common/common.py index e7e6c2fd2e..3a47e70182 100644 --- a/tryton/common/common.py +++ b/tryton/common/common.py @@ -50,6 +50,7 @@ from tryton import __version__ from tryton.exceptions import TrytonServerError, TrytonError from tryton.pyson import PYSONEncoder from .underline import set_underline +from .widget_style import widget_class _ = gettext.gettext logger = logging.getLogger(__name__) @@ -1291,23 +1292,13 @@ def data2pixbuf(data, width=None, height=None): pass -def get_label_attributes(readonly, required): - "Return the pango attributes applied to a label according to its state" - if readonly: - style = pango.STYLE_NORMAL - weight = pango.WEIGHT_NORMAL +def apply_label_attributes(label, readonly, required): + if not readonly: + widget_class(label, 'editable', True) + widget_class(label, 'required', required) else: - style = pango.STYLE_ITALIC - if required: - weight = pango.WEIGHT_BOLD - else: - weight = pango.WEIGHT_NORMAL - attrlist = pango.AttrList() - if hasattr(pango, 'AttrWeight'): - attrlist.change(pango.AttrWeight(weight, 0, -1)) - if hasattr(pango, 'AttrStyle'): - attrlist.change(pango.AttrStyle(style, 0, -1)) - return attrlist + widget_class(label, 'editable', False) + widget_class(label, 'required', False) def ellipsize(string, length): 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 f401059d48..cada3f26b5 100644 --- a/tryton/gui/window/view_form/view/form_gtk/many2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/many2many.py @@ -10,7 +10,6 @@ import tryton.common as common import gettext from tryton.common.completion import get_completion, update_completion from tryton.common.domain_parser import quote -from tryton.common.widget_style import widget_class from tryton.common.underline import set_underline _ = gettext.gettext @@ -231,10 +230,8 @@ class Many2Many(Widget): self._set_label_state() def _set_label_state(self): - attrlist = common.get_label_attributes(self._readonly, self._required) - self.title.set_attributes(attrlist) - widget_class(self.title, 'readonly', self._readonly) - widget_class(self.title, 'required', self._required) + common.apply_label_attributes( + self.title, self._readonly, self._required) def _set_button_sensitive(self): if self.record and self.field: 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 c4c1dc5f9c..abb9550526 100644 --- a/tryton/gui/window/view_form/view/form_gtk/one2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/one2many.py @@ -11,7 +11,6 @@ from tryton.gui.window.win_form import WinForm import tryton.common as common from tryton.common.completion import get_completion, update_completion from tryton.common.domain_parser import quote -from tryton.common.widget_style import widget_class from tryton.common.underline import set_underline _ = gettext.gettext @@ -241,10 +240,8 @@ class One2Many(Widget): self._set_label_state() def _set_label_state(self): - attrlist = common.get_label_attributes(self._readonly, self._required) - self.title.set_attributes(attrlist) - widget_class(self.title, 'readonly', self._readonly) - widget_class(self.title, 'required', self._required) + common.apply_label_attributes( + self.title, self._readonly, self._required) def _set_button_sensitive(self): access = common.MODELACCESS[self.screen.model_name] diff --git a/tryton/gui/window/view_form/view/form_gtk/state_widget.py b/tryton/gui/window/view_form/view/form_gtk/state_widget.py index d4939cbae9..da142c8d4f 100644 --- a/tryton/gui/window/view_form/view/form_gtk/state_widget.py +++ b/tryton/gui/window/view_form/view/form_gtk/state_widget.py @@ -3,7 +3,6 @@ import gtk import tryton.common as common -from tryton.common.widget_style import widget_class class StateMixin(object): @@ -44,11 +43,8 @@ class Label(StateMixin, gtk.Label): required = ((field and field.attrs.get('required')) or state_changes.get('required')) readonly = ((field and field.attrs.get('readonly')) - or state_changes.get('readonly')) - attrlist = common.get_label_attributes(readonly, required) - self.set_attributes(attrlist) - widget_class(self, 'readonly', readonly) - widget_class(self, 'required', required) + or state_changes.get('readonly', not bool(field))) + common.apply_label_attributes(self, readonly, required) class VBox(StateMixin, gtk.VBox): diff --git a/tryton/gui/window/view_form/view/list.py b/tryton/gui/window/view_form/view/list.py index 9acca3da46..d49da65ebf 100644 --- a/tryton/gui/window/view_form/view/list.py +++ b/tryton/gui/window/view_form/view/list.py @@ -15,7 +15,6 @@ from tryton.gui.window import Window from tryton.common.popup_menu import populate from tryton.common import RPCExecute, RPCException, node_attributes, Tooltips from tryton.common import domain_inversion, simplify, unique_value -from tryton.common.widget_style import widget_class from tryton.pyson import PYSONDecoder import tryton.common as common from . import View @@ -457,10 +456,7 @@ class ViewTree(View): if field and self.editable: required = field.attrs.get('required') readonly = field.attrs.get('readonly') - attrlist = common.get_label_attributes(readonly, required) - label.set_attributes(attrlist) - widget_class(label, 'readonly', readonly) - widget_class(label, 'required', required) + common.apply_label_attributes(label, readonly, required) label.show() help = None if field and field.attrs.get('help'):