Improve color_set
- use style only once - get colormap only when needed
This commit is contained in:
1 parent
763523b65d
commit
2b126c8dd4
1 file changed
+33
-33
@@ -93,13 +93,7 @@ class WidgetInterface(object):
|
||||
]
|
||||
self.widget = None
|
||||
self.position = 0
|
||||
self.bg_color_active = None
|
||||
self.bg_color_insensitive = None
|
||||
self.base_color_normal = None
|
||||
self.base_color_insensitive = None
|
||||
self.fg_color_normal = None
|
||||
self.fg_color_insensitive = None
|
||||
self.text_color_normal = None
|
||||
self.colors = {}
|
||||
self.visible = True
|
||||
|
||||
def destroy(self):
|
||||
@@ -156,25 +150,21 @@ class WidgetInterface(object):
|
||||
|
||||
def color_set(self, name):
|
||||
widget = self._color_widget()
|
||||
colormap = widget.get_colormap()
|
||||
style = widget.get_style()
|
||||
|
||||
if self.bg_color_active is None:
|
||||
self.bg_color_active = style.bg[gtk.STATE_ACTIVE]
|
||||
if self.bg_color_insensitive is None:
|
||||
self.bg_color_insensitive = style.bg[gtk.STATE_INSENSITIVE]
|
||||
if self.base_color_normal is None:
|
||||
self.base_color_normal = style.base[gtk.STATE_NORMAL]
|
||||
if self.base_color_insensitive is None:
|
||||
self.base_color_insensitive = style.base[gtk.STATE_INSENSITIVE]
|
||||
if self.fg_color_normal is None:
|
||||
self.fg_color_normal = style.fg[gtk.STATE_NORMAL]
|
||||
if self.fg_color_insensitive is None:
|
||||
self.fg_color_insensitive = style.fg[gtk.STATE_INSENSITIVE]
|
||||
if self.text_color_normal is None:
|
||||
self.text_color_normal = style.text[gtk.STATE_NORMAL]
|
||||
if not self.colors:
|
||||
style = widget.get_style()
|
||||
self.colors = {
|
||||
'bg_color_active': style.bg[gtk.STATE_ACTIVE],
|
||||
'bg_color_insensitive': style.bg[gtk.STATE_INSENSITIVE],
|
||||
'base_color_normal': style.base[gtk.STATE_NORMAL],
|
||||
'base_color_insensitive': style.base[gtk.STATE_INSENSITIVE],
|
||||
'fg_color_normal': style.fg[gtk.STATE_NORMAL],
|
||||
'fg_color_insensitive': style.fg[gtk.STATE_INSENSITIVE],
|
||||
'text_color_normal': style.text[gtk.STATE_NORMAL],
|
||||
}
|
||||
|
||||
if COLORS.get(name):
|
||||
colormap = widget.get_colormap()
|
||||
bg_color = colormap.alloc_color(COLORS.get(name, 'white'))
|
||||
fg_color = gtk.gdk.color_parse("black")
|
||||
widget.modify_bg(gtk.STATE_ACTIVE, bg_color)
|
||||
@@ -183,17 +173,27 @@ class WidgetInterface(object):
|
||||
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, self.bg_color_insensitive)
|
||||
widget.modify_base(gtk.STATE_NORMAL, self.base_color_insensitive)
|
||||
widget.modify_fg(gtk.STATE_NORMAL, self.fg_color_insensitive)
|
||||
widget.modify_text(gtk.STATE_NORMAL, self.text_color_normal)
|
||||
widget.modify_text(gtk.STATE_INSENSITIVE, self.text_color_normal)
|
||||
widget.modify_bg(gtk.STATE_ACTIVE,
|
||||
self.colors['bg_color_insensitive'])
|
||||
widget.modify_base(gtk.STATE_NORMAL,
|
||||
self.colors['base_color_insensitive'])
|
||||
widget.modify_fg(gtk.STATE_NORMAL,
|
||||
self.colors['fg_color_insensitive'])
|
||||
widget.modify_text(gtk.STATE_NORMAL,
|
||||
self.colors['text_color_normal'])
|
||||
widget.modify_text(gtk.STATE_INSENSITIVE,
|
||||
self.colors['text_color_normal'])
|
||||
else:
|
||||
widget.modify_bg(gtk.STATE_ACTIVE, self.bg_color_active)
|
||||
widget.modify_base(gtk.STATE_NORMAL, self.base_color_normal)
|
||||
widget.modify_fg(gtk.STATE_NORMAL, self.fg_color_normal)
|
||||
widget.modify_text(gtk.STATE_NORMAL, self.text_color_normal)
|
||||
widget.modify_text(gtk.STATE_INSENSITIVE, self.text_color_normal)
|
||||
widget.modify_bg(gtk.STATE_ACTIVE,
|
||||
self.colors['bg_color_active'])
|
||||
widget.modify_base(gtk.STATE_NORMAL,
|
||||
self.colors['base_color_normal'])
|
||||
widget.modify_fg(gtk.STATE_NORMAL,
|
||||
self.colors['fg_color_normal'])
|
||||
widget.modify_text(gtk.STATE_NORMAL,
|
||||
self.colors['text_color_normal'])
|
||||
widget.modify_text(gtk.STATE_INSENSITIVE,
|
||||
self.colors['text_color_normal'])
|
||||
|
||||
def invisible_set(self, value):
|
||||
widget = self._invisible_widget()
|
||||
|
||||
Reference in new issue
Block a user