From 9622ad9bd789f5490f7af0515a3dfd77fd1ce3e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 8 Dec 2008 10:29:51 +0100 Subject: [PATCH] Improve colors management to use the default style colors as much as possible --- tryton/common/cellrendererdate.py | 30 ++++++++++++------ tryton/common/cellrenderertext.py | 31 +++++++++++++------ tryton/common/common.py | 2 -- .../view_form/view/form_gtk/interface.py | 28 +++++++++++++---- .../window/view_form/view/list_gtk/parser.py | 23 +++++++++----- 5 files changed, 80 insertions(+), 34 deletions(-) diff --git a/tryton/common/cellrendererdate.py b/tryton/common/cellrendererdate.py index 81507952e0..01a149b9fd 100644 --- a/tryton/common/cellrendererdate.py +++ b/tryton/common/cellrendererdate.py @@ -1,4 +1,5 @@ -#This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. +#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 gtk import gobject from date_widget import mapping, DateEntry, compute_date @@ -10,8 +11,12 @@ class CellRendererDate(gtk.GenericCellRenderer): 'Text', gobject.PARAM_READWRITE), 'foreground': (gobject.TYPE_STRING, None, 'Foreground', 'Foreground', gobject.PARAM_WRITABLE), + 'foreground-set': (gobject.TYPE_INT, 'Foreground Set', + 'Foreground Set', 0, 10, 0, gobject.PARAM_READWRITE), 'background': (gobject.TYPE_STRING, None, 'Background', 'Background', gobject.PARAM_WRITABLE), + 'background-set': (gobject.TYPE_INT, 'Background Set', + 'Background Set', 0, 10, 0, gobject.PARAM_READWRITE), 'editable': (gobject.TYPE_INT, 'Editable', 'Editable', 0, 10, 0, gobject.PARAM_READWRITE), } @@ -63,15 +68,22 @@ class CellRendererDate(gtk.GenericCellRenderer): editable = DateEntry(self.format, self._date_cb, self._process_cb) colormap = editable.get_colormap() - if hasattr(self, 'background'): - colour = colormap.alloc_color(getattr(self, 'background')) + style = editable.get_style() + if hasattr(self, 'background') \ + and getattr(self, 'background') != 'white': + bg_color = colormap.alloc_color(getattr(self, 'background')) + fg_color = gtk.gdk.color_parse("black") + editable.modify_bg(gtk.STATE_ACTIVE, bg_color) + editable.modify_base(gtk.STATE_NORMAL, bg_color) + editable.modify_fg(gtk.STATE_NORMAL, fg_color) + editable.modify_text(gtk.STATE_NORMAL, fg_color) + editable.modify_text(gtk.STATE_INSENSITIVE, fg_color) else: - colour = colormap.alloc_color('white') - editable.modify_bg(gtk.STATE_ACTIVE, colour) - editable.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse("black")) - editable.modify_base(gtk.STATE_NORMAL, colour) - editable.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("black")) - editable.modify_text(gtk.STATE_INSENSITIVE, gtk.gdk.color_parse("black")) + editable.modify_bg(gtk.STATE_ACTIVE, style.bg[gtk.STATE_ACTIVE]) + editable.modify_base(gtk.STATE_NORMAL, style.base[gtk.STATE_NORMAL]) + editable.modify_fg(gtk.STATE_NORMAL, style.fg[gtk.STATE_NORMAL]) + editable.modify_text(gtk.STATE_NORMAL, style.text[gtk.STATE_NORMAL]) + editable.modify_text(gtk.STATE_INSENSITIVE, style.text[gtk.STATE_INSENSITIVE]) if self.text: editable.set_text(self.text) diff --git a/tryton/common/cellrenderertext.py b/tryton/common/cellrenderertext.py index 673968193d..e4c64ba0fb 100644 --- a/tryton/common/cellrenderertext.py +++ b/tryton/common/cellrenderertext.py @@ -1,4 +1,5 @@ -#This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. +#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 gtk import gobject import pango @@ -10,8 +11,12 @@ class CellRendererText(gtk.GenericCellRenderer): 'Text', gobject.PARAM_READWRITE), 'foreground': (gobject.TYPE_STRING, None, 'Foreground', 'Foreground', gobject.PARAM_WRITABLE), + 'foreground-set': (gobject.TYPE_INT, 'Foreground Set', + 'Foreground Set', 0, 10, 0, gobject.PARAM_READWRITE), 'background': (gobject.TYPE_STRING, None, 'Background', 'Background', gobject.PARAM_WRITABLE), + 'background-set': (gobject.TYPE_INT, 'Background Set', + 'Background Set', 0, 10, 0, gobject.PARAM_READWRITE), 'editable': (gobject.TYPE_INT, 'Editable', 'Editable', 0, 10, 0, gobject.PARAM_READWRITE), 'xalign': (gobject.TYPE_FLOAT, 'XAlign', @@ -65,16 +70,22 @@ class CellRendererText(gtk.GenericCellRenderer): background_area, cell_area, flags) colormap = editable.get_colormap() - if hasattr(self, 'background'): - colour = colormap.alloc_color(getattr(self, 'background')) + style = editable.get_style() + if hasattr(self, 'background') \ + and getattr(self, 'background') != 'white': + bg_color = colormap.alloc_color(getattr(self, 'background')) + fg_color = gtk.gdk.color_parse("black") + editable.modify_bg(gtk.STATE_ACTIVE, bg_color) + editable.modify_base(gtk.STATE_NORMAL, bg_color) + editable.modify_fg(gtk.STATE_NORMAL, fg_color) + editable.modify_text(gtk.STATE_NORMAL, fg_color) + editable.modify_text(gtk.STATE_INSENSITIVE, fg_color) else: - colour = colormap.alloc_color('white') - editable.modify_bg(gtk.STATE_ACTIVE, colour) - editable.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse("black")) - editable.modify_base(gtk.STATE_NORMAL, colour) - editable.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("black")) - editable.modify_text(gtk.STATE_INSENSITIVE, gtk.gdk.color_parse("black")) - + editable.modify_bg(gtk.STATE_ACTIVE, style.bg[gtk.STATE_ACTIVE]) + editable.modify_base(gtk.STATE_NORMAL, style.base[gtk.STATE_NORMAL]) + editable.modify_fg(gtk.STATE_NORMAL, style.fg[gtk.STATE_NORMAL]) + editable.modify_text(gtk.STATE_NORMAL, style.text[gtk.STATE_NORMAL]) + editable.modify_text(gtk.STATE_INSENSITIVE, style.text[gtk.STATE_INSENSITIVE]) return editable gobject.type_register(CellRendererText) diff --git a/tryton/common/common.py b/tryton/common/common.py index 53ab91c1ab..38a5bb0c51 100644 --- a/tryton/common/common.py +++ b/tryton/common/common.py @@ -880,9 +880,7 @@ COLOR_SCHEMES = { COLORS = { 'invalid':'#ff6969', - 'readonly':'#eeebe7', 'required':'#d2d2ff', - 'normal':'white' } DT_FORMAT = '%Y-%m-%d' diff --git a/tryton/gui/window/view_form/view/form_gtk/interface.py b/tryton/gui/window/view_form/view/form_gtk/interface.py index 28b8dc1ffb..47a68651bf 100644 --- a/tryton/gui/window/view_form/view/form_gtk/interface.py +++ b/tryton/gui/window/view_form/view/form_gtk/interface.py @@ -89,6 +89,7 @@ class WidgetInterface(object): ] self.widget = None self.position = 0 + self.bg_color = None def destroy(self): pass @@ -126,12 +127,27 @@ class WidgetInterface(object): def color_set(self, name): widget = self._color_widget() colormap = widget.get_colormap() - colour = colormap.alloc_color(COLORS.get(name,'white')) - widget.modify_bg(gtk.STATE_ACTIVE, colour) - widget.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse("black")) - widget.modify_base(gtk.STATE_NORMAL, colour) - widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("black")) - widget.modify_text(gtk.STATE_INSENSITIVE, gtk.gdk.color_parse("black")) + style = widget.get_style() + if COLORS.get(name): + bg_color = colormap.alloc_color(COLORS.get(name, 'white')) + fg_color = gtk.gdk.color_parse("black") + widget.modify_bg(gtk.STATE_ACTIVE, bg_color) + widget.modify_base(gtk.STATE_NORMAL, bg_color) + widget.modify_fg(gtk.STATE_NORMAL, fg_color) + widget.modify_text(gtk.STATE_NORMAL, fg_color) + widget.modify_text(gtk.STATE_INSENSITIVE, fg_color) + elif name == 'readonly': + widget.modify_bg(gtk.STATE_ACTIVE, style.bg[gtk.STATE_INSENSITIVE]) + widget.modify_base(gtk.STATE_NORMAL, style.base[gtk.STATE_INSENSITIVE]) + widget.modify_fg(gtk.STATE_NORMAL, style.fg[gtk.STATE_INSENSITIVE]) + widget.modify_text(gtk.STATE_NORMAL, style.text[gtk.STATE_INSENSITIVE]) + widget.modify_text(gtk.STATE_INSENSITIVE, style.text[gtk.STATE_INSENSITIVE]) + else: + widget.modify_bg(gtk.STATE_ACTIVE, style.bg[gtk.STATE_ACTIVE]) + widget.modify_base(gtk.STATE_NORMAL, style.base[gtk.STATE_NORMAL]) + widget.modify_fg(gtk.STATE_NORMAL, style.fg[gtk.STATE_NORMAL]) + widget.modify_text(gtk.STATE_NORMAL, style.text[gtk.STATE_NORMAL]) + widget.modify_text(gtk.STATE_INSENSITIVE, style.text[gtk.STATE_INSENSITIVE]) def invisible_set(self, value): widget = self._invisible_widget() diff --git a/tryton/gui/window/view_form/view/list_gtk/parser.py b/tryton/gui/window/view_form/view/list_gtk/parser.py index 60594ce483..2c290b3616 100644 --- a/tryton/gui/window/view_form/view/list_gtk/parser.py +++ b/tryton/gui/window/view_form/view/list_gtk/parser.py @@ -248,8 +248,12 @@ class Char(object): model = store.get_value(iter, 0) text = self.get_textual_value(model) cell.set_property('text', text) - color = self.get_color(model) - cell.set_property('foreground', str(color)) + fg_color = self.get_color(model) + cell.set_property('foreground', fg_color) + if fg_color == 'black': + cell.set_property('foreground-set', False) + else: + cell.set_property('foreground-set', True) if self.attrs['type'] in ('float', 'integer', 'biginteger', 'boolean', 'numeric', 'float_time'): align = 1 @@ -259,12 +263,17 @@ class Char(object): and self.treeview.editable: field = model[self.field_name] field.state_set(model) + bg_color = 'white' if not field.get_state_attrs(model).get('valid', True): - cell.set_property('background', - COLORS.get('invalid', 'white')) + bg_color = COLORS.get('invalid', 'white') elif bool(int(field.get_state_attrs(model).get('required', 0))): - cell.set_property('background', - COLORS.get('required', 'white')) + bg_color = COLORS.get('required', 'white') + cell.set_property('background', bg_color) + if bg_color == 'white': + cell.set_property('background-set', False) + else: + cell.set_property('background-set', True) + cell.set_property('foreground-set', True) readonly = field.get_state_attrs(model).get('readonly', False) if isinstance(cell, gtk.CellRendererToggle): cell.set_property('activatable', not readonly) @@ -279,7 +288,7 @@ class Char(object): to_display = '' for color, expr in self.treeview.colors.items(): if model.expr_eval(expr, check_load=False): - to_display = color + to_display = str(color) break return to_display or 'black'