Improve colors management to use the default style colors as much as possible

This commit is contained in:
Cédric Krier committed 2008-12-08 10:29:51 +01:00
1 parent 2d387743ed
commit 9622ad9bd7
5 files changed
+80 -34

No files matched your search

+21 -9
View File
@@ -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)
+21 -10
View File
@@ -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)
-2
View File
@@ -880,9 +880,7 @@ COLOR_SCHEMES = {
COLORS = {
'invalid':'#ff6969',
'readonly':'#eeebe7',
'required':'#d2d2ff',
'normal':'white'
}
DT_FORMAT = '%Y-%m-%d'
@@ -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()
@@ -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'