2
# -*- coding: utf-8 -*-
6
__authors__ = ["Jan Jokela <janjokela@gmail.com>"]
7
__licenses__ = ["LICENSE.LGPL"]
8
__description__ = "Glitter theme"
16
from style import Style
20
class Theme(gobject.GObject):
22
A Glitter theme holds the styles for individual widgets in their various
23
states, theme resources and other misc configuration data.
27
def __init__(self, name):
28
""" Initialize theme """
30
super(Theme, self).__init__()
33
self.theme_path = None
35
self.widget_styles = {}
40
def _init_common(self):
41
""" Common initialization procedures """
44
themes_path = os.path.join(
45
os.path.dirname(os.path.abspath(__file__)),
49
for entry in os.listdir(themes_path):
50
if os.path.isdir(os.path.join(themes_path, entry)):
51
theme_names.append(entry)
53
if self.name in theme_names:
54
self.theme_path = os.path.join(
55
os.path.dirname(os.path.abspath(__file__)),
61
raise ValueError("Theme not found.")
63
def _init_styles(self):
64
""" Initialize widget styles """
66
theme_styles_path = os.path.join(
67
os.path.dirname(os.path.abspath(__file__)),
73
# Parse widget styles from our JSON (ECMA 262-3) descriptions
74
for entry in os.listdir(theme_styles_path):
75
if os.path.isfile(os.path.join(theme_styles_path, entry)):
76
json_file = os.path.join(theme_styles_path, entry)
77
widget, ext = os.path.splitext(entry)
79
if not widget in self.widget_styles:
80
self.widget_styles[widget] = {}
81
json_file = open(json_file)
82
style_description = simplejson.load(json_file)
83
for state in style_description:
85
for key in style_description[state]:
86
value = style_description[state][key]
87
if type(value) is list:
89
props[str(key)] = value
91
self.widget_styles[widget][state] = Style(**props)
93
def get_style(self, widget, state):
94
""" Retrieve the style for given widget in given state """
96
widget = widget.lower()
97
widget_styles = self.widget_styles.get(widget)
100
style = widget_styles.get(state)
107
""" Retrieve theme path """
109
return self.theme_path
112
def get_default(cls):
113
""" Retrieve default theme """
115
global _DEFAULT_THEME
117
if not _DEFAULT_THEME:
118
default_theme_name = 'nublo'
119
_DEFAULT_THEME = cls(default_theme_name)
121
return _DEFAULT_THEME
124
def set_default(theme):
125
""" Sets default theme
127
theme -- (glitter.Theme)
130
global _DEFAULT_THEME
132
_DEFAULT_THEME = theme