[core] Add "merged" pango support
With this commit, it is possible to add pango directives inside every piece that supports direct output (e.g. defaults/prefix or <module name>/prefix) and those will be merged - i.e. it is possible to specify defaults inside "defaults" and override/specify in the particular modules.
This commit is contained in:
parent
e653624f5a
commit
23215303ca
2 changed files with 19 additions and 5 deletions
|
@ -52,7 +52,6 @@ class block(object):
|
|||
text = attr.get('full_text', '')
|
||||
if 'full_text' in attr:
|
||||
del attr['full_text']
|
||||
|
||||
result = '<span '
|
||||
for key, value in attr.items():
|
||||
result = '{} {}="{}"'.format(result, key, value)
|
||||
|
|
|
@ -2,6 +2,7 @@ import os
|
|||
import io
|
||||
import json
|
||||
import logging
|
||||
import copy
|
||||
|
||||
import core.event
|
||||
import util.algorithm
|
||||
|
@ -15,6 +16,17 @@ PATHS=[
|
|||
os.path.expanduser('~/.config/bumblebee-status/themes'),
|
||||
]
|
||||
|
||||
def merge_replace(value, new_value, key):
|
||||
if not isinstance(value, dict):
|
||||
return new_value
|
||||
if isinstance(new_value, dict):
|
||||
util.algorithm.merge(value, new_value)
|
||||
return value
|
||||
# right now, merging needs explicit pango support :(
|
||||
if 'pango' in value:
|
||||
value['pango']['full_text'] = new_value
|
||||
return value
|
||||
|
||||
class Theme(object):
|
||||
def __init__(self, name='default', iconset='auto', raw_data=None):
|
||||
self.name = name
|
||||
|
@ -106,17 +118,20 @@ class Theme(object):
|
|||
tmp = self.__data[option]
|
||||
if isinstance(tmp, list):
|
||||
tmp = tmp[self.__widget_count % len(tmp)]
|
||||
value = tmp.get(key, value)
|
||||
value = merge_replace(value, tmp.get(key, value), key)
|
||||
|
||||
value = self.__data.get(key, value)
|
||||
if isinstance(value, dict):
|
||||
value = copy.deepcopy(value)
|
||||
|
||||
value = merge_replace(value, self.__data.get(key, value), key)
|
||||
|
||||
if widget.module():
|
||||
value = self.__get(None, widget.module().name(), {}).get(key, value)
|
||||
value = merge_replace(value, self.__get(None, widget.module().name(), {}).get(key, value), key)
|
||||
|
||||
if not key in widget.state():
|
||||
for state in widget.state():
|
||||
theme = self.__get(widget, state, {})
|
||||
value = theme.get(key, value)
|
||||
value = merge_replace(value, theme.get(key, value), key)
|
||||
|
||||
if not type(value) in (list, dict):
|
||||
value = self.__keywords.get(value, value)
|
||||
|
|
Loading…
Reference in a new issue