Commit before breaking everything
[matches/honours.git] / research / transmission_spectroscopy / simulator / pgu-0.18 / build / lib / pgu / gui / style.py
1 """
2 """
3
4 from . import pguglobals
5 from .errors import StyleError
6
7 class Style:
8     """The class used by widget for the widget.style
9     
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)
13
14     """
15     def __init__(self, obj, dict):
16         self.obj = obj
17         for k,v in dict.items(): self.__dict__[k]=v
18
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)):
23             desc = self.obj.cls
24             if (self.obj.pcls): desc += "."+self.obj.pcls
25             raise StyleError("Cannot find the style attribute '%s' for '%s'" % (attr, desc))
26
27     # Checks if the given style attribute exists
28     def exists(self, attr):
29         try:
30             value = pguglobals.app.theme.getstyle(self.obj.cls, self.obj.pcls, attr)
31             return True
32         except StyleError:
33             return False
34
35     def __getattr__(self, attr):
36         # Lookup the attribute
37         try:
38             value = pguglobals.app.theme.getstyle(self.obj.cls, self.obj.pcls, attr)
39         except StyleError:
40             value = 0
41
42         if attr in (
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
48         return value
49
50     def __setattr__(self, attr, value):
51         self.__dict__[attr] = value
52

UCC git Repository :: git.ucc.asn.au