diff --git a/data/gui/chat_control.ui b/data/gui/chat_control.ui index 5d5b97145..1d1140258 100644 --- a/data/gui/chat_control.ui +++ b/data/gui/chat_control.ui @@ -382,6 +382,7 @@ 5 + ChatControl-BannerEventBox True False @@ -411,6 +412,7 @@ vertical + ChatControl-BannerNameLabel True False <span weight="heavy" size="large">Contact name</span> @@ -425,6 +427,7 @@ + ChatControl-BannerLabel True False label diff --git a/data/gui/service_discovery_window.ui b/data/gui/service_discovery_window.ui index db01476f0..16fe77569 100644 --- a/data/gui/service_discovery_window.ui +++ b/data/gui/service_discovery_window.ui @@ -24,6 +24,7 @@ 6 + Discovery-BannerEventBox True False @@ -33,6 +34,7 @@ 6 + Discovery-BannerLabel True False 6 diff --git a/src/chat_control.py b/src/chat_control.py index 8db855f29..8b740db0e 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -1024,8 +1024,8 @@ class ChatControl(ChatControlBase): displaymarking = None if self.correcting: self.correcting = False - self.msg_textview.override_background_color( - Gtk.StateType.NORMAL, self.old_message_tv_color) + gtkgui_helpers.remove_css_class( + self.msg_textview, 'msgcorrectingcolor') self.print_conversation(message, self.contact.jid, encrypted=encrypted, xep0184_id=xep0184_id, xhtml=xhtml, diff --git a/src/chat_control_base.py b/src/chat_control_base.py index d05d5ceb0..47394f09f 100644 --- a/src/chat_control_base.py +++ b/src/chat_control_base.py @@ -158,7 +158,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): """ Derived types MAY implement this """ - self._paint_banner() self.draw_banner() def _update_banner_state_image(self): @@ -371,7 +370,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): if gajim.config.get('use_speller') and HAS_GTK_SPELL: self.set_speller() self.conv_textview.tv.show() - self._paint_banner() # For XEP-0172 self.user_nick = None @@ -503,76 +501,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): # send the message self.send_message(message, xhtml=xhtml) - def _paint_banner(self): - """ - Repaint banner with theme color - """ - theme = gajim.config.get('roster_theme') - bgcolor = gajim.config.get_per('themes', theme, 'bannerbgcolor') - textcolor = gajim.config.get_per('themes', theme, 'bannertextcolor') - # the backgrounds are colored by using an eventbox by - # setting the bg color of the eventbox and the fg of the name_label - banner_eventbox = self.xml.get_object('banner_eventbox') - banner_name_label = self.xml.get_object('banner_name_label') - self.disconnect_style_event(banner_name_label) - self.disconnect_style_event(self.banner_status_label) - if bgcolor: - color = Gdk.RGBA() - Gdk.RGBA.parse(color, bgcolor) - banner_eventbox.override_background_color(Gtk.StateType.NORMAL, - color) - default_bg = False - else: - default_bg = True - if textcolor: - color = Gdk.RGBA() - Gdk.RGBA.parse(color, textcolor) - banner_name_label.override_color(Gtk.StateType.NORMAL, - color) - self.banner_status_label.override_color( - Gtk.StateType.NORMAL, color) - default_fg = False - else: - default_fg = True - if default_bg or default_fg: - self._on_style_set_event(banner_name_label, None, default_fg, - default_bg) - if self.banner_status_label.get_realized(): - # Widget is realized - self._on_style_set_event(self.banner_status_label, None, default_fg, - default_bg) - - def disconnect_style_event(self, widget): - # Try to find the event_id - for id_ in self.handlers.keys(): - if self.handlers[id_] == widget: - widget.disconnect(id_) - del self.handlers[id_] - break - - 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) - self.handlers[id_] = widget - - def _on_style_set_event(self, widget, style, *opts): - """ - Set style of widget from style class *.Frame.Eventbox - opts[0] == True -> set fg color - opts[1] == True -> set bg color - """ - banner_eventbox = self.xml.get_object('banner_eventbox') - self.disconnect_style_event(widget) - context = widget.get_style_context() - if opts[1]: - bg_color = context.get_background_color(Gtk.StateFlags.SELECTED) - banner_eventbox.override_background_color(Gtk.StateType.NORMAL, bg_color) - if opts[0]: - 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): # translate any layout to latin_layout valid, entries = self.keymap.get_entries_for_keyval(event.keyval) @@ -1226,20 +1154,15 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): msg_type == 'sent' and not self.correcting and (not \ history[pos - 1].startswith('/') or history[pos - 1].startswith('/me')): self.correcting = True - context = self.msg_textview.get_style_context() - state = Gtk.StateFlags.NORMAL - self.old_message_tv_color = context.get_background_color(state) - color = Gdk.RGBA() - Gdk.RGBA.parse(color, 'PaleGoldenrod') - self.msg_textview.override_background_color(Gtk.StateType.NORMAL, - color) + gtkgui_helpers.add_css_class( + self.msg_textview, 'msgcorrectingcolor') message = history[pos - 1] msg_buf.set_text(message) return if self.correcting: # We were previously correcting - self.msg_textview.override_background_color(Gtk.StateType.NORMAL, - self.old_message_tv_color) + gtkgui_helpers.remove_css_class( + self.msg_textview, 'msgcorrectingcolor') self.correcting = False pos += -1 if direction == 'up' else +1 if pos == -1: diff --git a/src/common/config.py b/src/common/config.py index b35c44392..f627a4c11 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -468,6 +468,7 @@ class Config: 'bannerbgcolor': [ opt_color, '', '', True ], 'bannerfont': [ opt_str, '', '', True ], 'bannerfontattrs': [ opt_str, 'B', '', True ], + 'msgcorrectingcolor': [opt_color, '#eee8aa'], # http://www.pitt.edu/~nisg/cis/web/cgi/rgb.html 'state_inactive_color': [ opt_color, 'grey62' ], diff --git a/src/config.py b/src/config.py index 226e3e2f2..56f12448a 100644 --- a/src/config.py +++ b/src/config.py @@ -750,6 +750,7 @@ class PreferencesWindow: # begin repainting themed widgets throughout gajim.interface.roster.repaint_themed_widgets() gajim.interface.roster.change_roster_style(None) + gtkgui_helpers.load_css() def update_theme_list(self): theme_combobox = self.xml.get_object('theme_combobox') diff --git a/src/disco.py b/src/disco.py index 69341a186..0832e286e 100644 --- a/src/disco.py +++ b/src/disco.py @@ -561,7 +561,6 @@ _('Without a connection, you can not browse available services')) self.banner_eventbox = self.xml.get_object('banner_agent_eventbox') self.style_event_id = 0 self.banner.realize() - self.paint_banner() self.action_buttonbox = self.xml.get_object('action_buttonbox') # Address combobox @@ -660,63 +659,6 @@ _('Without a connection, you can not browse available services')) (markup, font.to_string(), text_after) self.banner.set_markup(markup) - def paint_banner(self): - """ - Repaint the banner with theme color - """ - theme = gajim.config.get('roster_theme') - bgcolor = gajim.config.get_per('themes', theme, 'bannerbgcolor') - textcolor = gajim.config.get_per('themes', theme, 'bannertextcolor') - self.disconnect_style_event() - if bgcolor: - color = Gdk.RGBA() - Gdk.RGBA.parse(color, bgcolor) - self.banner_eventbox.override_background_color(Gtk.StateType.NORMAL, - color) - default_bg = False - else: - default_bg = True - - if textcolor: - color = Gdk.RGBA() - Gdk.RGBA.parse(color, textcolor) - self.banner.override_color(Gtk.StateType.NORMAL, color) - default_fg = False - else: - default_fg = True - if default_fg or default_bg: - self._on_style_set_event(self.banner, None, default_fg, default_bg) - if self.browser: - self.browser.update_theme() - - def disconnect_style_event(self): - if self.style_event_id: - self.banner.disconnect(self.style_event_id) - self.style_event_id = 0 - - def connect_style_event(self, set_fg = False, set_bg = False): - self.disconnect_style_event() - self.style_event_id = self.banner.connect('style-set', - self._on_style_set_event, set_fg, set_bg) - - def _on_style_set_event(self, widget, style, *opts): - """ - Set style of widget from style class *.Frame.Eventbox - opts[0] == True -> set fg color - opts[1] == True -> set bg color - """ - self.disconnect_style_event() - context = widget.get_style_context() - if opts[1]: - 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 = 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]) - def destroy(self, chain = False): """ Close the browser. This can optionally close its children and propagate diff --git a/src/groupchat_control.py b/src/groupchat_control.py index 6d11d7e82..37c165dae 100644 --- a/src/groupchat_control.py +++ b/src/groupchat_control.py @@ -1996,8 +1996,8 @@ class GroupchatControl(ChatControlBase): self.last_sent_msg = msg if self.correcting: self.correcting = False - self.msg_textview.override_background_color( - Gtk.StateType.NORMAL, self.old_message_tv_color) + gtkgui_helpers.remove_css_class( + self.msg_textview, 'msgcorrectingcolor') if self.correcting and self.last_sent_msg: correction_msg = self.last_sent_msg diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index 5be850781..e9df5d35d 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -1109,7 +1109,13 @@ def load_css(): def convert_config_to_css(): css = '' - themed_widgets = {} + themed_widgets = { + 'ChatControl-BannerEventBox': ('bannerbgcolor', 'background'), + 'ChatControl-BannerNameLabel': ('bannertextcolor', 'color'), + 'ChatControl-BannerLabel': ('bannertextcolor', 'color'), + 'Discovery-BannerEventBox': ('bannerbgcolor', 'background'), + 'Discovery-BannerLabel': ('bannertextcolor', 'color')} + classes = {'state_composing_color': ('', 'color'), 'state_inactive_color': ('', 'color'), 'state_gone_color': ('', 'color'), @@ -1133,3 +1139,14 @@ def convert_config_to_css(): cls=key, node=node, attr=attr, color=value) return css + +def add_css_class(widget, class_name): + style = widget.get_style_context() + for css_cls in style.list_classes(): + if css_cls.startswith('theme_'): + style.remove_class(css_cls) + style.add_class('theme_' + class_name) + +def remove_css_class(widget, class_name): + style = widget.get_style_context() + style.remove_class('theme_' + class_name) diff --git a/src/roster_window.py b/src/roster_window.py index 235f7c8a7..f265252b3 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -4800,8 +4800,6 @@ class RosterWindow: for win in gajim.interface.msg_win_mgr.windows(): win.repaint_themed_widgets() for account in gajim.connections: - for addr in gajim.interface.instances[account]['disco']: - gajim.interface.instances[account]['disco'][addr].paint_banner() for ctrl in list(gajim.interface.minimized_controls[account].values()): ctrl.repaint_themed_widgets()