diff --git a/data/style/gajim.css b/data/style/gajim.css new file mode 100644 index 000000000..e69de29bb diff --git a/src/gajim.py b/src/gajim.py index 6a5a9ebd5..6eaffd47f 100644 --- a/src/gajim.py +++ b/src/gajim.py @@ -242,7 +242,9 @@ class GajimApplication(Gtk.Application): def do_activate(self): Gtk.Application.do_activate(self) from gui_interface import Interface + import gtkgui_helpers self.interface = Interface() + gtkgui_helpers.load_css() self.interface.run(self) self.add_actions() import gui_menu_builder diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index 28e4075a9..5be850781 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -48,6 +48,7 @@ log = logging.getLogger('gajim.gtkgui_helpers') from common import i18n from common import gajim from common import pep +from common import configpaths gtk_icon_theme = Gtk.IconTheme.get_default() gtk_icon_theme.append_search_path(gajim.ICONS_DIR) @@ -1088,3 +1089,47 @@ def __label_size_allocate(widget, allocation): def get_action(action): return gajim.app.lookup_action(action) + +def load_css(): + path = os.path.join(configpaths.get('DATA'), 'style', 'gajim.css') + try: + with open(path, "r") as f: + css = f.read() + except Exception as exc: + print('Error loading css: %s', exc) + return + + provider = Gtk.CssProvider() + css = "\n".join((css, convert_config_to_css())) + provider.load_from_data(bytes(css.encode())) + Gtk.StyleContext.add_provider_for_screen( + Gdk.Screen.get_default(), + provider, + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) + +def convert_config_to_css(): + css = '' + themed_widgets = {} + classes = {'state_composing_color': ('', 'color'), + 'state_inactive_color': ('', 'color'), + 'state_gone_color': ('', 'color'), + 'state_paused_color': ('', 'color'), + 'msgcorrectingcolor': ('text', 'background')} + + theme = gajim.config.get('roster_theme') + for key, values in themed_widgets.items(): + config, attr = values + css += '#{} {{'.format(key) + value = gajim.config.get_per('themes', theme, config) + if value: + css += '{attr}: {color};\n'.format(attr=attr, color=value) + css += '}\n' + + for key, values in classes.items(): + node, attr = values + value = gajim.config.get_per('themes', theme, key) + if value: + css += '.theme_{cls} {node} {{ {attr}: {color}; }}\n'.format( + cls=key, node=node, attr=attr, color=value) + + return css