2016-12-04 18:10:04 +01:00
|
|
|
"""Theme support"""
|
|
|
|
|
2016-12-08 09:44:05 +01:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
|
|
|
|
import bumblebee.error
|
|
|
|
|
|
|
|
def theme_path():
|
|
|
|
"""Return the path of the theme directory"""
|
|
|
|
return os.path.dirname("{}/../themes/".format(os.path.dirname(os.path.realpath(__file__))))
|
|
|
|
|
2016-12-04 18:10:04 +01:00
|
|
|
class Theme(object):
|
2016-12-08 08:44:54 +01:00
|
|
|
"""Represents a collection of icons and colors"""
|
2016-12-08 09:44:05 +01:00
|
|
|
def __init__(self, name):
|
|
|
|
self._theme = self.load(name)
|
|
|
|
|
2016-12-08 11:31:20 +01:00
|
|
|
def prefix(self):
|
|
|
|
"""Return the theme prefix for a widget's full text"""
|
|
|
|
return None
|
|
|
|
|
|
|
|
def suffix(self):
|
|
|
|
"""Return the theme suffix for a widget's full text"""
|
|
|
|
return None
|
|
|
|
|
2016-12-08 09:44:05 +01:00
|
|
|
def load(self, name):
|
|
|
|
"""Load and parse a theme file"""
|
|
|
|
path = theme_path()
|
|
|
|
themefile = "{}/{}.json".format(path, name)
|
|
|
|
if os.path.isfile(themefile):
|
|
|
|
try:
|
|
|
|
with open(themefile) as data:
|
|
|
|
return json.load(data)
|
|
|
|
except ValueError as exception:
|
|
|
|
raise bumblebee.error.ThemeLoadError("JSON error: {}".format(exception))
|
|
|
|
else:
|
|
|
|
raise bumblebee.error.ThemeLoadError("no such theme: {}".format(name))
|
2016-12-04 18:10:04 +01:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|