Arrêt du synthé comme il faut lorsqu'on quitte la fenêtre de jeu.
[minwii.git] / src / pgu / gui / style.py
1 """
2 """
3
4 import pguglobals
5
6 class Style:
7 """The class used by widget for the widget.style
8
9 <p>This object is used mainly as a dictionary, accessed via <tt>widget.style.attr</tt>, as opposed to
10 <tt>widget.style['attr']</tt>. It automatically grabs information from the theme via <tt>value = theme.get(widget.cls,widget.pcls,attr)</tt>.</p>
11
12 """
13 def __init__(self,o,dict):
14 self.obj = o
15 for k,v in dict.items(): self.__dict__[k]=v
16 self._cache = {}
17
18 def __getattr__(self,k):
19 key = self.obj.cls,self.obj.pcls,k
20 if key not in self._cache:
21 self._cache[key] = Style_get(self.obj.cls,self.obj.pcls,k)
22 v = self._cache[key]
23 if k in (
24 'border_top','border_right','border_bottom','border_left',
25 'padding_top','padding_right','padding_bottom','padding_left',
26 'margin_top','margin_right','margin_bottom','margin_left',
27 'align','valign','width','height',
28 ): self.__dict__[k] = v
29 return v
30
31 def __setattr__(self,k,v):
32 self.__dict__[k] = v
33
34
35 Style_cache = {}
36 def Style_get(cls,pcls,k):
37 key = cls,pcls,k
38 if key not in Style_cache:
39 Style_cache[key] = pguglobals.app.theme.get(cls,pcls,k)
40 return Style_cache[key]
41