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

@ -683,12 +683,13 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
""" """
banner_eventbox = self.xml.get_object('banner_eventbox') banner_eventbox = self.xml.get_object('banner_eventbox')
self.disconnect_style_event(widget) self.disconnect_style_event(widget)
context = widget.get_style_context()
if opts[1]: if opts[1]:
bg_color = widget.get_style().bg[Gtk.StateType.SELECTED] bg_color = context.get_background_color(Gtk.StateFlags.SELECTED)
banner_eventbox.modify_bg(Gtk.StateType.NORMAL, bg_color) banner_eventbox.override_background_color(Gtk.StateType.NORMAL, bg_color)
if opts[0]: if opts[0]:
fg_color = widget.get_style().fg[Gtk.StateType.SELECTED] fg_color = context.get_color(Gtk.StateFlags.SELECTED)
widget.modify_fg(Gtk.StateType.NORMAL, fg_color) widget.override_color(Gtk.StateType.NORMAL, fg_color)
self.connect_style_event(widget, opts[0], opts[1]) self.connect_style_event(widget, opts[0], opts[1])
def _conv_textview_key_press_event(self, widget, event): def _conv_textview_key_press_event(self, widget, event):
@ -2510,34 +2511,38 @@ class ChatControl(ChatControlBase):
# Draw tab label using chatstate # Draw tab label using chatstate
theme = gajim.config.get('roster_theme') theme = gajim.config.get('roster_theme')
color = None color_s = None
if not chatstate: if not chatstate:
chatstate = self.contact.chatstate chatstate = self.contact.chatstate
if chatstate is not None: if chatstate is not None:
if chatstate == 'composing': if chatstate == 'composing':
color = gajim.config.get_per('themes', theme, color_s = gajim.config.get_per('themes', theme,
'state_composing_color') 'state_composing_color')
elif chatstate == 'inactive': elif chatstate == 'inactive':
color = gajim.config.get_per('themes', theme, color_s = gajim.config.get_per('themes', theme,
'state_inactive_color') 'state_inactive_color')
elif chatstate == 'gone': elif chatstate == 'gone':
color = gajim.config.get_per('themes', theme, color_s = gajim.config.get_per('themes', theme,
'state_gone_color') 'state_gone_color')
elif chatstate == 'paused': elif chatstate == 'paused':
color = gajim.config.get_per('themes', theme, color_s = gajim.config.get_per('themes', theme,
'state_paused_color') 'state_paused_color')
if 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 # 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: 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 # In inactive tab color to be lighter against the darker inactive
# background # background
if chatstate in ('inactive', 'gone') and\ if chatstate in ('inactive', 'gone') and\
self.parent_win.get_active_control() != self: self.parent_win.get_active_control() != self:
color = self.lighten_color(color) color = self.lighten_color(color)
else: # active or not chatstate, get color from gtk 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() name = self.contact.get_shown_name()
if self.resource: if self.resource:

View File

@ -397,8 +397,11 @@ class PreferencesWindow:
# Default Status messages # Default Status messages
self.default_msg_tree = self.xml.get_object('default_msg_treeview') 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) # (status, translated_status, message, enabled)
model = Gtk.ListStore(str, str, str, bool) model = Gtk.ListStore(str, str, str, bool)
self.default_msg_tree.set_model(model) self.default_msg_tree.set_model(model)
@ -416,7 +419,7 @@ class PreferencesWindow:
col.add_attribute(renderer, 'text', 2) col.add_attribute(renderer, 'text', 2)
renderer.connect('edited', self.on_default_msg_cell_edited) renderer.connect('edited', self.on_default_msg_cell_edited)
renderer.set_property('editable', True) renderer.set_property('editable', True)
renderer.set_property('cell-background', col2) renderer.set_property('cell-background-rgba', col2)
col = Gtk.TreeViewColumn(_('Enabled')) col = Gtk.TreeViewColumn(_('Enabled'))
col.set_resizable(True) col.set_resizable(True)
self.default_msg_tree.append_column(col) 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 opts[1] == True -> set bg color
""" """
self.disconnect_style_event() self.disconnect_style_event()
context = widget.get_style_context()
if opts[1]: if opts[1]:
bg_color = widget.get_style().bg[Gtk.StateType.SELECTED] bg_color = context.get_background_color(Gtk.StateFlags.SELECTED)
self.banner_eventbox.modify_bg(Gtk.StateType.NORMAL, bg_color) self.banner_eventbox.override_background_color(Gtk.StateType.NORMAL,
bg_color)
if opts[0]: if opts[0]:
fg_color = widget.get_style().fg[Gtk.StateType.SELECTED] fg_color = context.get_color(Gtk.StateFlags.SELECTED)
self.banner.modify_fg(Gtk.StateType.NORMAL, fg_color) self.banner.override_color(Gtk.StateType.NORMAL, fg_color)
self.banner.ensure_style() self.banner.ensure_style()
self.connect_style_event(opts[0], opts[1]) 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 Set style for group row, using PRELIGHT system color
""" """
context = treeview.get_style_context()
if set_background: if set_background:
bgcolor = treeview.get_style().bg[Gtk.StateType.PRELIGHT] bgcolor = context.get_background_color(Gtk.StateFlags.PRELIGHT)
renderer.set_property('cell-background-gdk', bgcolor) renderer.set_property('cell-background-rgba', bgcolor)
else: else:
fgcolor = treeview.get_style().fg[Gtk.StateType.PRELIGHT] fgcolor = context.get_color(Gtk.StateFlags.PRELIGHT)
renderer.set_property('foreground-gdk', fgcolor) renderer.set_property('foreground-rgba', fgcolor)
def tree_cell_data_func(column, renderer, model, iter_, tv=None): def tree_cell_data_func(column, renderer, model, iter_, tv=None):
# cell data func is global, because we don't want it to keep # cell data func is global, because we don't want it to keep
@ -661,6 +662,7 @@ class GroupchatControl(ChatControlBase):
color_name = None color_name = None
color = None color = None
theme = gajim.config.get('roster_theme') 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): if chatstate == 'attention' and (not has_focus or not current_tab):
self.attention_flag = True self.attention_flag = True
color_name = gajim.config.get_per('themes', theme, color_name = gajim.config.get_per('themes', theme,
@ -669,13 +671,17 @@ class GroupchatControl(ChatControlBase):
if chatstate == 'active' or (current_tab and has_focus): if chatstate == 'active' or (current_tab and has_focus):
self.attention_flag = False self.attention_flag = False
# get active color from gtk # 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) \ elif chatstate == 'newmsg' and (not has_focus or not current_tab) \
and not self.attention_flag: and not self.attention_flag:
color_name = gajim.config.get_per('themes', theme, color_name = gajim.config.get_per('themes', theme,
'state_muc_msg_color') 'state_muc_msg_color')
if color_name: 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 self.is_continued:
# if this is a continued conversation # 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): 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 0.7 respectively colors of the cell for the given treeview
""" """
context = treeview.get_style_context()
style = treeview.get_style() style = treeview.get_style()
if selected: if selected:
if focused: # is the window focused? 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 else: # is it not? NOTE: many gtk themes change bg on this
state = Gtk.StateType.ACTIVE state = Gtk.StateFlags.ACTIVE
else: else:
state = Gtk.StateType.NORMAL state = Gtk.StateFlags.NORMAL
bg = style.base[state] bg = context.get_background_color(state)
fg = style.text[state] fg = context.get_color(state)
p = 0.3 # background p = 0.3 # background
q = 0.7 # foreground # p + q should do 1.0 q = 0.7 # foreground # p + q should do 1.0
return Gdk.Color(int(bg.red*p + fg.red*q), return Gdk.RGBA(bg.red*p + fg.red*q, bg.green*p + fg.green*q,
int(bg.green*p + fg.green*q), bg.blue*p + fg.blue*q)
int(bg.blue*p + fg.blue*q))
def get_scaled_pixbuf(pixbuf, kind): 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].send_tune(artist, title, source)
gajim.connections[acct].music_track_info = music_track_info 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): def read_sleepy(self):
""" """
Check idle status and change that status if needed 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) (tab_label_str, tab_label_color) = ctrl.get_tab_label(chatstate)
nick_label.set_markup(tab_label_str) nick_label.set_markup(tab_label_str)
if tab_label_color: if tab_label_color:
nick_label.modify_fg(Gtk.StateType.NORMAL, tab_label_color) nick_label.override_color(Gtk.StateFlags.NORMAL, tab_label_color)
nick_label.modify_fg(Gtk.StateType.ACTIVE, tab_label_color) nick_label.override_color(Gtk.StateFlags.ACTIVE, tab_label_color)
tab_img = ctrl.get_tab_image() tab_img = ctrl.get_tab_image()
if tab_img: if tab_img:

View File

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