4 from . import pguglobals
5 from .errors import StyleError
8 """The class used by widget for the widget.style
10 This object is used mainly as a dictionary, accessed via widget.style.attr,
11 as opposed to widget.style['attr']. It automatically grabs information
12 from the theme via value = theme.get(widget.cls,widget.pcls,attr)
15 def __init__(self, obj, dict):
17 for k,v in dict.items(): self.__dict__[k]=v
19 # Verify that the given style is defined, otherwise raises an StyleError exception. This
20 # is used by various widgets to check that they have all required style information.
21 def check(self, attr):
22 if (not self.exists(attr)):
24 if (self.obj.pcls): desc += "."+self.obj.pcls
25 raise StyleError("Cannot find the style attribute '%s' for '%s'" % (attr, desc))
27 # Checks if the given style attribute exists
28 def exists(self, attr):
30 value = pguglobals.app.theme.getstyle(self.obj.cls, self.obj.pcls, attr)
35 def __getattr__(self, attr):
36 # Lookup the attribute
38 value = pguglobals.app.theme.getstyle(self.obj.cls, self.obj.pcls, attr)
43 'border_top','border_right','border_bottom','border_left',
44 'padding_top','padding_right','padding_bottom','padding_left',
45 'margin_top','margin_right','margin_bottom','margin_left',
46 'align','valign','width','height',
47 ): self.__dict__[attr] = value
50 def __setattr__(self, attr, value):
51 self.__dict__[attr] = value