From ca0450b7adb572fcb87b2c48a09a6f4618b415bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 20 Sep 2019 11:47:15 +0200 Subject: [PATCH] Add visual context on tree view issue8562 review261951002 --- CHANGELOG | 1 + tryton/config.py | 1 + .../window/view_form/view/list_gtk/widget.py | 32 +++++++++++++++---- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index cef3f8f17c..92f1fb3bbb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Support visual context on tree view * Support multiselection field * Support dot notation on PYSON Eval * Order Dict keys by sequence diff --git a/tryton/config.py b/tryton/config.py index fc5e5d4659..04f06895fd 100644 --- a/tryton/config.py +++ b/tryton/config.py @@ -56,6 +56,7 @@ class ConfigManager(object): 'client.check_version': True, 'client.bus_timeout': 10 * 60, 'icon.colors': '#3465a4,#555753,#cc0000', + 'tree.colors': '#777,#dff0d8,#fcf8e3,#f2dede', 'image.max_size': 10 ** 6, 'bug.url': 'https://bugs.tryton.org/', 'download.url': 'https://downloads-cdn.tryton.org/', diff --git a/tryton/gui/window/view_form/view/list_gtk/widget.py b/tryton/gui/window/view_form/view/list_gtk/widget.py index e35a212a03..d391edfcde 100644 --- a/tryton/gui/window/view_form/view/list_gtk/widget.py +++ b/tryton/gui/window/view_form/view/list_gtk/widget.py @@ -31,6 +31,10 @@ from tryton.config import CONFIG _ = gettext.gettext +COLORS = {n: v for n, v in zip( + ['muted', 'success', 'warning', 'danger'], + CONFIG['tree.colors'].split(','))} + def send_keys(renderer, editable, position, treeview): editable.connect('key_press_event', treeview.on_keypressed, renderer) @@ -133,6 +137,17 @@ class Cell(object): field = record[self.attrs['name']] return record, field + def _set_visual(self, cell, record): + visual = record.expr_eval(self.attrs.get('visual')) + if not visual: + visual = record.expr_eval(self.view.attributes.get('visual')) + background = COLORS.get(visual) if visual != 'muted' else None + foreground = COLORS.get(visual) if visual == 'muted' else None + cell.set_property('cell-background', background) + if isinstance(cell, Gtk.CellRendererText): + cell.set_property('foreground', foreground) + cell.set_property('foreground-set', bool(foreground)) + class Affix(Cell): expand = False @@ -173,6 +188,7 @@ class Affix(Cell): if not text: text = field.get_client(record) or '' cell.set_property('text', text) + self._set_visual(cell, record) def clicked(self, renderer, path): record, field = self._get_record_field_from_path(path) @@ -215,20 +231,17 @@ class GenericText(Cell): @realized @CellCache.cache def setter(self, column, cell, store, iter_, user_data=None): - record = store.get_value(iter_, 0) + record, field = self._get_record_field_from_iter(iter_, store) text = self.get_textual_value(record) - if isinstance(cell, CellRendererToggle): + if isinstance(cell, Gtk.CellRendererToggle): cell.set_active(bool(text)) else: cell.set_sensitive(not (record.deleted or record.removed)) - if isinstance(cell, - (CellRendererText, CellRendererDate, CellRendererCombo)): + if isinstance(cell, Gtk.CellRendererText): cell.set_property('strikethrough', record.deleted) cell.set_property('text', text) - field = record[self.attrs['name']] - editable = getattr(self.view.treeview, 'editable', False) states = ('invisible',) if editable: @@ -261,6 +274,7 @@ class GenericText(Cell): else: if isinstance(cell, CellRendererToggle): cell.set_property('activatable', False) + self._set_visual(cell, record) def open_remote(self, record, create, changed=False, text=None, callback=None): @@ -475,6 +489,7 @@ class Binary(GenericText): field.state_set(record, states=states) invisible = field.get_state_attrs(record).get('invisible', False) cell.set_property('visible', not invisible) + self._set_visual(cell, record) def get_data(self, record, field): if hasattr(field, 'get_data'): @@ -537,6 +552,7 @@ class _BinarySave(_BinaryIcon): field.state_set(record, states=['invisible']) invisible = field.get_state_attrs(record).get('invisible', False) cell.set_property('visible', not invisible and size) + self._set_visual(cell, record) class _BinarySelect(_BinaryIcon): @@ -587,6 +603,7 @@ class _BinarySelect(_BinaryIcon): cell.set_property('visible', False) else: cell.set_property('visible', not invisible) + self._set_visual(cell, record) class _BinaryOpen(_BinarySave): @@ -639,6 +656,7 @@ class Image(GenericText): if pixbuf and (width != -1 or height != -1): pixbuf = common.resize_pixbuf(pixbuf, width, height) cell.set_property('pixbuf', pixbuf) + self._set_visual(cell, record) def get_textual_value(self, record): if not record: @@ -1128,6 +1146,7 @@ class ProgressBar(Cell): cell.set_property('text', text) value = field.get(record) or 0.0 cell.set_property('value', value * 100) + self._set_visual(cell, record) def open_remote(self, record, create, changed=False, text=None, callback=None): @@ -1170,6 +1189,7 @@ class Button(Cell): break parent = parent.parent # TODO icon + self._set_visual(cell, record) def button_clicked(self, widget, path): if not path: