fix style / color things

This commit is contained in:
Yann Leboulanger 2013-01-05 15:53:14 +01:00
parent 185d0d8c07
commit 86b256ac96
8 changed files with 70 additions and 84 deletions

View File

@ -672,7 +672,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
def connect_style_event(self, widget, set_fg=False, set_bg=False):
self.disconnect_style_event(widget)
id_ = widget.connect('style-set', self._on_style_set_event, set_fg,
set_bg)
set_bg)
self.handlers[id_] = widget
def _on_style_set_event(self, widget, style, *opts):
@ -683,12 +683,13 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
"""
banner_eventbox = self.xml.get_object('banner_eventbox')
self.disconnect_style_event(widget)
context = widget.get_style_context()
if opts[1]:
bg_color = widget.get_style().bg[Gtk.StateType.SELECTED]
banner_eventbox.modify_bg(Gtk.StateType.NORMAL, bg_color)
bg_color = context.get_background_color(Gtk.StateFlags.SELECTED)
banner_eventbox.override_background_color(Gtk.StateType.NORMAL, bg_color)
if opts[0]:
fg_color = widget.get_style().fg[Gtk.StateType.SELECTED]
widget.modify_fg(Gtk.StateType.NORMAL, fg_color)
fg_color = context.get_color(Gtk.StateFlags.SELECTED)
widget.override_color(Gtk.StateType.NORMAL, fg_color)
self.connect_style_event(widget, opts[0], opts[1])
def _conv_textview_key_press_event(self, widget, event):
@ -2510,34 +2511,38 @@ class ChatControl(ChatControlBase):
# Draw tab label using chatstate
theme = gajim.config.get('roster_theme')
color = None
color_s = None
if not chatstate:
chatstate = self.contact.chatstate
if chatstate is not None:
if chatstate == 'composing':
color = gajim.config.get_per('themes', theme,
'state_composing_color')
color_s = gajim.config.get_per('themes', theme,
'state_composing_color')
elif chatstate == 'inactive':
color = gajim.config.get_per('themes', theme,
'state_inactive_color')
color_s = gajim.config.get_per('themes', theme,
'state_inactive_color')
elif chatstate == 'gone':
color = gajim.config.get_per('themes', theme,
'state_gone_color')
color_s = gajim.config.get_per('themes', theme,
'state_gone_color')
elif chatstate == 'paused':
color = gajim.config.get_per('themes', theme,
'state_paused_color')
if color:
color_s = gajim.config.get_per('themes', theme,
'state_paused_color')
context = self.parent_win.notebook.get_style_context()
if color_s:
# We set the color for when it's the current tab or not
ok, color = Gdk.Color.parse(color)
color = Gdk.RGBA()
ok = Gdk.RGBA.parse(color, color_s)
if not ok:
color = self.parent_win.notebook.get_style().fg[Gtk.StateType.ACTIVE]
del color
color = context.get_color(Gtk.StateFlags.ACTIVE)
# In inactive tab color to be lighter against the darker inactive
# background
if chatstate in ('inactive', 'gone') and\
self.parent_win.get_active_control() != self:
color = self.lighten_color(color)
else: # active or not chatstate, get color from gtk
color = self.parent_win.notebook.get_style().fg[Gtk.StateType.ACTIVE]
color = context.get_color(Gtk.StateFlags.ACTIVE)
name = self.contact.get_shown_name()
if self.resource:

View File

@ -397,8 +397,11 @@ class PreferencesWindow:
# Default Status messages
self.default_msg_tree = self.xml.get_object('default_msg_treeview')
col2 = self.default_msg_tree.get_style().bg[Gtk.StateType.ACTIVE].\
to_string()
#FIXME: That doesn't seem to work:
context = self.default_msg_tree.get_style_context()
col2 = context.get_background_color(Gtk.StateFlags.ACTIVE)
# (status, translated_status, message, enabled)
model = Gtk.ListStore(str, str, str, bool)
self.default_msg_tree.set_model(model)
@ -416,7 +419,7 @@ class PreferencesWindow:
col.add_attribute(renderer, 'text', 2)
renderer.connect('edited', self.on_default_msg_cell_edited)
renderer.set_property('editable', True)
renderer.set_property('cell-background', col2)
renderer.set_property('cell-background-rgba', col2)
col = Gtk.TreeViewColumn(_('Enabled'))
col.set_resizable(True)
self.default_msg_tree.append_column(col)

View File

@ -679,12 +679,14 @@ _('Without a connection, you can not browse available services'))
opts[1] == True -> set bg color
"""
self.disconnect_style_event()
context = widget.get_style_context()
if opts[1]:
bg_color = widget.get_style().bg[Gtk.StateType.SELECTED]
self.banner_eventbox.modify_bg(Gtk.StateType.NORMAL, bg_color)
bg_color = context.get_background_color(Gtk.StateFlags.SELECTED)
self.banner_eventbox.override_background_color(Gtk.StateType.NORMAL,
bg_color)
if opts[0]:
fg_color = widget.get_style().fg[Gtk.StateType.SELECTED]
self.banner.modify_fg(Gtk.StateType.NORMAL, fg_color)
fg_color = context.get_color(Gtk.StateFlags.SELECTED)
self.banner.override_color(Gtk.StateType.NORMAL, fg_color)
self.banner.ensure_style()
self.connect_style_event(opts[0], opts[1])

View File

@ -73,12 +73,13 @@ def set_renderer_color(treeview, renderer, set_background=True):
"""
Set style for group row, using PRELIGHT system color
"""
context = treeview.get_style_context()
if set_background:
bgcolor = treeview.get_style().bg[Gtk.StateType.PRELIGHT]
renderer.set_property('cell-background-gdk', bgcolor)
bgcolor = context.get_background_color(Gtk.StateFlags.PRELIGHT)
renderer.set_property('cell-background-rgba', bgcolor)
else:
fgcolor = treeview.get_style().fg[Gtk.StateType.PRELIGHT]
renderer.set_property('foreground-gdk', fgcolor)
fgcolor = context.get_color(Gtk.StateFlags.PRELIGHT)
renderer.set_property('foreground-rgba', fgcolor)
def tree_cell_data_func(column, renderer, model, iter_, tv=None):
# cell data func is global, because we don't want it to keep
@ -661,21 +662,26 @@ class GroupchatControl(ChatControlBase):
color_name = None
color = None
theme = gajim.config.get('roster_theme')
context = self.parent_win.notebook.get_style_context()
if chatstate == 'attention' and (not has_focus or not current_tab):
self.attention_flag = True
color_name = gajim.config.get_per('themes', theme,
'state_muc_directed_msg_color')
'state_muc_directed_msg_color')
elif chatstate:
if chatstate == 'active' or (current_tab and has_focus):
self.attention_flag = False
# get active color from gtk
color = self.parent_win.notebook.get_style().fg[Gtk.StateType.ACTIVE]
color = context.get_color(Gtk.StateFlags.ACTIVE)
elif chatstate == 'newmsg' and (not has_focus or not current_tab) \
and not self.attention_flag:
color_name = gajim.config.get_per('themes', theme,
'state_muc_msg_color')
'state_muc_msg_color')
if color_name:
color = Gdk.colormap_get_system().alloc_color(color_name)
color = Gdk.RGBA()
ok = Gdk.RGBA.parse(color, color_name)
if not ok:
del color
color = context.get_color(Gtk.StateFlags.ACTIVE)
if self.is_continued:
# if this is a continued conversation

View File

@ -523,25 +523,25 @@ def file_is_locked(path_to_file):
def get_fade_color(treeview, selected, focused):
"""
Get a gdk color that is between foreground and background in 0.3
Get a gdk RGBA color that is between foreground and background in 0.3
0.7 respectively colors of the cell for the given treeview
"""
context = treeview.get_style_context()
style = treeview.get_style()
if selected:
if focused: # is the window focused?
state = Gtk.StateType.SELECTED
state = Gtk.StateFlags.SELECTED
else: # is it not? NOTE: many gtk themes change bg on this
state = Gtk.StateType.ACTIVE
state = Gtk.StateFlags.ACTIVE
else:
state = Gtk.StateType.NORMAL
bg = style.base[state]
fg = style.text[state]
state = Gtk.StateFlags.NORMAL
bg = context.get_background_color(state)
fg = context.get_color(state)
p = 0.3 # background
q = 0.7 # foreground # p + q should do 1.0
return Gdk.Color(int(bg.red*p + fg.red*q),
int(bg.green*p + fg.green*q),
int(bg.blue*p + fg.blue*q))
return Gdk.RGBA(bg.red*p + fg.red*q, bg.green*p + fg.green*q,
bg.blue*p + fg.blue*q)
def get_scaled_pixbuf(pixbuf, kind):
"""

View File

@ -2299,38 +2299,6 @@ class Interface:
gajim.connections[acct].send_tune(artist, title, source)
gajim.connections[acct].music_track_info = music_track_info
def get_bg_fg_colors(self):
def gdkcolor_to_rgb (gdkcolor):
return [c / 65535. for c in (gdkcolor.red, gdkcolor.green,
gdkcolor.blue)]
def format_rgb (r, g, b):
return ' '.join([str(c) for c in ('rgb', r, g, b)])
def format_gdkcolor (gdkcolor):
return format_rgb (*gdkcolor_to_rgb (gdkcolor))
# get style colors and create string for dvipng
dummy = Gtk.Invisible()
dummy.ensure_style()
style = dummy.get_style()
bg_str = format_gdkcolor(style.base[Gtk.StateType.NORMAL])
fg_str = format_gdkcolor(style.text[Gtk.StateType.NORMAL])
return (bg_str, fg_str)
def get_fg_color(self, fmt='hex'):
def format_gdkcolor (c):
if fmt == 'tex':
return ' '.join([str(s) for s in
('rgb', c.red_float, c.green_float, c.blue_float)])
elif fmt == 'hex':
return str(c)
# get foreground style color and create string
dummy = Gtk.Invisible()
dummy.ensure_style()
return format_gdkcolor(dummy.get_style().text[Gtk.StateType.NORMAL])
def read_sleepy(self):
"""
Check idle status and change that status if needed

View File

@ -639,8 +639,8 @@ class MessageWindow(object):
(tab_label_str, tab_label_color) = ctrl.get_tab_label(chatstate)
nick_label.set_markup(tab_label_str)
if tab_label_color:
nick_label.modify_fg(Gtk.StateType.NORMAL, tab_label_color)
nick_label.modify_fg(Gtk.StateType.ACTIVE, tab_label_color)
nick_label.override_color(Gtk.StateFlags.NORMAL, tab_label_color)
nick_label.override_color(Gtk.StateFlags.ACTIVE, tab_label_color)
tab_img = ctrl.get_tab_image()
if tab_img:

View File

@ -5064,11 +5064,13 @@ class RosterWindow:
Set style for treeview cell, using PRELIGHT system color
"""
if set_background:
bgcolor = self.tree.get_style().bg[style]
renderer.set_property('cell-background-gdk', bgcolor)
context = self.tree.get_style_context()
bgcolor = context.get_background_color(style)
renderer.set_property('cell-background-rgba', bgcolor)
else:
fgcolor = self.tree.get_style().fg[style]
renderer.set_property('foreground-gdk', fgcolor)
context = self.tree.get_style_context()
fgcolor = context.get_color(style)
renderer.set_property('foreground-rgba', fgcolor)
def _iconCellDataFunc(self, column, renderer, model, titer, data=None):
"""
@ -5117,7 +5119,7 @@ class RosterWindow:
if color:
renderer.set_property('foreground', color)
else:
self.set_renderer_color(renderer, Gtk.StateType.ACTIVE, False)
self.set_renderer_color(renderer, Gtk.StateFlags.ACTIVE, False)
renderer.set_property('font',
gtkgui_helpers.get_theme_font_for_option(theme, 'accountfont'))
renderer.set_property('xpad', 0)
@ -5128,7 +5130,7 @@ class RosterWindow:
if color:
renderer.set_property('foreground', color)
else:
self.set_renderer_color(renderer, Gtk.StateType.PRELIGHT, False)
self.set_renderer_color(renderer, Gtk.StateFlags.PRELIGHT, False)
renderer.set_property('font',
gtkgui_helpers.get_theme_font_for_option(theme, 'groupfont'))
parent_iter = model.iter_parent(titer)
@ -5255,7 +5257,7 @@ class RosterWindow:
if color:
renderer.set_property('cell-background', color)
else:
self.set_renderer_color(renderer, Gtk.StateType.ACTIVE)
self.set_renderer_color(renderer, Gtk.StateFlags.ACTIVE)
def _set_contact_row_background_color(self, renderer, jid, account):
theme = gajim.config.get('roster_theme')
@ -5275,7 +5277,7 @@ class RosterWindow:
if color:
renderer.set_property('cell-background', color)
else:
self.set_renderer_color(renderer, Gtk.StateType.PRELIGHT)
self.set_renderer_color(renderer, Gtk.StateFlags.PRELIGHT)
################################################################################
### Everything about building menus