Use apply_label_attributes instead of get_label_attributes
and do not set editable class to label not linked to field issue7631 issue7644 review58381002
This commit is contained in:
1 parent
167ec92964
commit
56b7542557
7 files changed
+21
-37
No files matched your search
@@ -1,3 +1,4 @@
|
||||
* Use CSS to style label
|
||||
* New icons
|
||||
* Support timestamp field
|
||||
* Add support for Python 3.7
|
||||
|
||||
@@ -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()
|
||||
|
||||
+7
-16
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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'):
|
||||
|
||||
Reference in new issue
Block a user