[formatting] reformat using "black -t py34"
getting rid of thinking about consistent formatting...
This commit is contained in:
parent
fa98bcbdd1
commit
30c1f712a6
119 changed files with 3961 additions and 3495 deletions
|
@ -10,24 +10,26 @@ import util.algorithm
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
THEME_BASE_DIR=os.path.dirname(os.path.realpath(__file__))
|
||||
PATHS=[
|
||||
'.',
|
||||
os.path.join(THEME_BASE_DIR, '../themes'),
|
||||
os.path.expanduser('~/.config/bumblebee-status/themes'),
|
||||
THEME_BASE_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||
PATHS = [
|
||||
".",
|
||||
os.path.join(THEME_BASE_DIR, "../themes"),
|
||||
os.path.expanduser("~/.config/bumblebee-status/themes"),
|
||||
]
|
||||
|
||||
|
||||
def themes():
|
||||
themes_dict = {}
|
||||
|
||||
for path in PATHS:
|
||||
for filename in glob.iglob('{}/*.json'.format(path)):
|
||||
if 'test' not in filename:
|
||||
themes_dict[os.path.basename(filename).replace('.json', '')] = 1
|
||||
for filename in glob.iglob("{}/*.json".format(path)):
|
||||
if "test" not in filename:
|
||||
themes_dict[os.path.basename(filename).replace(".json", "")] = 1
|
||||
result = list(themes_dict.keys())
|
||||
result.sort()
|
||||
return result
|
||||
|
||||
|
||||
def merge_replace(value, new_value, key):
|
||||
if not isinstance(value, dict):
|
||||
return new_value
|
||||
|
@ -35,12 +37,13 @@ def merge_replace(value, new_value, key):
|
|||
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
|
||||
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):
|
||||
def __init__(self, name="default", iconset="auto", raw_data=None):
|
||||
self.name = name
|
||||
self.__widget_count = 0
|
||||
self.__previous = {}
|
||||
|
@ -48,15 +51,15 @@ class Theme(object):
|
|||
self.__keywords = {}
|
||||
self.__value_idx = {}
|
||||
self.__data = raw_data if raw_data else self.load(name)
|
||||
for icons in self.__data.get('icons', []):
|
||||
util.algorithm.merge(self.__data, self.load(icons, 'icons'))
|
||||
if iconset != 'auto':
|
||||
util.algorithm.merge(self.__data, self.load(iconset, 'icons'))
|
||||
for colors in self.__data.get('colors', []):
|
||||
for icons in self.__data.get("icons", []):
|
||||
util.algorithm.merge(self.__data, self.load(icons, "icons"))
|
||||
if iconset != "auto":
|
||||
util.algorithm.merge(self.__data, self.load(iconset, "icons"))
|
||||
for colors in self.__data.get("colors", []):
|
||||
util.algorithm.merge(self.__keywords, self.load_keywords(colors))
|
||||
|
||||
core.event.register('draw', self.__start)
|
||||
core.event.register('next-widget', self.__next_widget)
|
||||
core.event.register("draw", self.__start)
|
||||
core.event.register("next-widget", self.__next_widget)
|
||||
|
||||
def keywords(self):
|
||||
return self.__keywords
|
||||
|
@ -64,17 +67,20 @@ class Theme(object):
|
|||
def color(self, name, default=None):
|
||||
return self.keywords().get(name, default)
|
||||
|
||||
def load(self, name, subdir=''):
|
||||
if isinstance(name, dict): return name # support plain data
|
||||
def load(self, name, subdir=""):
|
||||
if isinstance(name, dict):
|
||||
return name # support plain data
|
||||
for path in PATHS:
|
||||
theme_file = os.path.join(path, subdir, '{}.json'.format(name))
|
||||
theme_file = os.path.join(path, subdir, "{}.json".format(name))
|
||||
result = self.__load_json(theme_file)
|
||||
if result != {}: return result
|
||||
raise RuntimeError('unable to find theme {}'.format(name))
|
||||
if result != {}:
|
||||
return result
|
||||
raise RuntimeError("unable to find theme {}".format(name))
|
||||
|
||||
def __load_json(self, filename):
|
||||
filename = os.path.expanduser(filename)
|
||||
if not os.path.isfile(filename): return {}
|
||||
if not os.path.isfile(filename):
|
||||
return {}
|
||||
with io.open(filename) as data:
|
||||
return json.load(data)
|
||||
|
||||
|
@ -82,15 +88,15 @@ class Theme(object):
|
|||
try:
|
||||
if isinstance(name, dict):
|
||||
return name
|
||||
if name.lower() == 'wal':
|
||||
wal = self.__load_json('~/.cache/wal/colors.json')
|
||||
if name.lower() == "wal":
|
||||
wal = self.__load_json("~/.cache/wal/colors.json")
|
||||
result = {}
|
||||
for field in ['special', 'colors']:
|
||||
for field in ["special", "colors"]:
|
||||
for key in wal.get(field, {}):
|
||||
result[key] = wal[field][key]
|
||||
return result
|
||||
except Exception as e:
|
||||
log.error('failed to load colors: {}', e)
|
||||
log.error("failed to load colors: {}", e)
|
||||
|
||||
def __start(self):
|
||||
self.__widget_count = 0
|
||||
|
@ -107,14 +113,14 @@ class Theme(object):
|
|||
|
||||
def get(self, key, widget=None, default=None):
|
||||
if not widget:
|
||||
widget = core.widget.Widget('')
|
||||
widget = core.widget.Widget("")
|
||||
# special handling
|
||||
if widget == 'previous':
|
||||
if widget == "previous":
|
||||
return self.__previous.get(key, None)
|
||||
|
||||
value = default
|
||||
|
||||
for option in ['defaults', 'cycle']:
|
||||
for option in ["defaults", "cycle"]:
|
||||
if option in self.__data:
|
||||
tmp = self.__data[option]
|
||||
if isinstance(tmp, list):
|
||||
|
@ -127,7 +133,9 @@ class Theme(object):
|
|||
value = merge_replace(value, self.__data.get(key, value), key)
|
||||
|
||||
if widget.module:
|
||||
value = merge_replace(value, self.get(widget.module.name, None, {}).get(key, value), key)
|
||||
value = merge_replace(
|
||||
value, self.get(widget.module.name, None, {}).get(key, value), key
|
||||
)
|
||||
|
||||
if not key in widget.state():
|
||||
for state in widget.state():
|
||||
|
@ -138,11 +146,12 @@ class Theme(object):
|
|||
value = self.__keywords.get(value, value)
|
||||
|
||||
if isinstance(value, list):
|
||||
idx = self.__value_idx.get('{}::{}'.format(widget.id, key), 0) % len(value)
|
||||
self.__value_idx['{}::{}'.format(widget.id, key)] = idx
|
||||
idx = self.__value_idx.get("{}::{}".format(widget.id, key), 0) % len(value)
|
||||
self.__value_idx["{}::{}".format(widget.id, key)] = idx
|
||||
widget.set(key, idx)
|
||||
value = value[idx]
|
||||
self.__current[key] = value
|
||||
return value
|
||||
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue