[core/themes] Add theme loading
Load a theme from a JSON file.
This commit is contained in:
parent
c44744fa50
commit
2399cf9af1
4 changed files with 52 additions and 2 deletions
|
@ -8,4 +8,8 @@ class ModuleLoadError(BaseError):
|
|||
"""Raised whenever loading a module fails"""
|
||||
pass
|
||||
|
||||
class ThemeLoadError(BaseError):
|
||||
"""Raised whenever loading a theme fails"""
|
||||
pass
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
|
@ -1,7 +1,30 @@
|
|||
"""Theme support"""
|
||||
|
||||
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__))))
|
||||
|
||||
class Theme(object):
|
||||
"""Represents a collection of icons and colors"""
|
||||
pass
|
||||
def __init__(self, name):
|
||||
self._theme = self.load(name)
|
||||
|
||||
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))
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue