Commit 2c2c058e authored by Philipp Hörist's avatar Philipp Hörist
Browse files

CSSConfig: Generate dynamic classes

CSSConfig now generates classes for account colors at start so
we can use them later easily
parent 39acfc20
......@@ -85,6 +85,16 @@ def __init__(self):
# User Theme CSS Provider
self._provider = Gtk.CssProvider()
# Used for dynamic classes like account colors
self._dynamic_provider = Gtk.CssProvider()
self._dynamic_dict = {}
self.refresh()
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
self._dynamic_provider,
CSSPriority.APPLICATION)
# Cache of recently requested values
self._cache = {}
......@@ -97,6 +107,7 @@ def __init__(self):
self._load_default()
self._load_selected()
self._activate_theme()
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
self._provider,
......@@ -520,3 +531,17 @@ def _get_from_cache(self, selector, attr):
def _invalidate_cache(self):
self._cache = {}
def refresh(self):
css = ''
accounts = app.get_accounts_sorted()
for index, account in enumerate(accounts):
color = app.config.get_per('accounts', account, 'account_color')
css_class = 'gajim_class_%s' % index
css += '.%s { color: %s }\n' % (css_class, color)
self._dynamic_dict[account] = css_class
self._dynamic_provider.load_from_data(css.encode())
def get_dynamic_class(self, name):
return self._dynamic_dict[name]
......@@ -362,6 +362,7 @@ def __init__(self, *args):
def on_color_set(self, button):
rgba = button.get_rgba()
self.set_value(rgba.to_string())
app.css_config.refresh()
def on_row_activated(self):
self.color_button.grab_focus()
......
......@@ -1695,6 +1695,7 @@ def create_account(account,
for opt in config:
app.config.set_per('accounts', account, opt, config[opt])
app.css_config.refresh()
# refresh accounts window
# Action must be added before account window is updated
app.app.add_account_actions(account)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment