Components/Lcd.py: use 1 instead of 0 for Oled standby default value (with new driver...
[enigma2.git] / lib / python / Components / GUISkin.py
1 from GUIComponent import GUIComponent
2 from skin import applyAllAttributes
3 from Tools.CList import CList
4 from Sources.StaticText import StaticText
5
6 class GUISkin:
7         __module__ = __name__
8
9         def __init__(self):
10                 self["Title"] = StaticText()
11                 self.onLayoutFinish = [ ]
12                 self.summaries = CList()
13                 self.instance = None
14                 self.desktop = None
15
16         def createGUIScreen(self, parent, desktop, updateonly = False):
17                 for val in self.renderer:
18                         if isinstance(val, GUIComponent):
19                                 if not updateonly:
20                                         val.GUIcreate(parent)
21                                 if not val.applySkin(desktop, self):
22                                         print "warning, skin is missing renderer", val, "in", self
23
24                 for key in self:
25                         val = self[key]
26                         if isinstance(val, GUIComponent):
27                                 if not updateonly:
28                                         val.GUIcreate(parent)
29                                 depr = val.deprecationInfo
30                                 if val.applySkin(desktop, self):
31                                         if depr:
32                                                 print "WARNING: OBSOLETE COMPONENT '%s' USED IN SKIN. USE '%s' INSTEAD!" % (key, depr[0])
33                                                 print "OBSOLETE COMPONENT WILL BE REMOVED %s, PLEASE UPDATE!" % (depr[1])
34                                 elif not depr:
35                                         print "warning, skin is missing element", key, "in", self
36
37                 for w in self.additionalWidgets:
38                         if not updateonly:
39                                 w.instance = w.widget(parent)
40                                 # w.instance.thisown = 0
41                         applyAllAttributes(w.instance, desktop, w.skinAttributes, self.scale)
42
43                 for f in self.onLayoutFinish:
44                         if type(f) is not type(self.close): # is this the best way to do this?
45                                 exec(f) in globals(), locals()
46                         else:
47                                 f()
48
49         def deleteGUIScreen(self):
50                 for (name, val) in self.items():
51                         if isinstance(val, GUIComponent):
52                                 val.GUIdelete()
53
54         def close(self):
55                 self.deleteGUIScreen()
56
57         def createSummary(self):
58                 return None
59
60         def addSummary(self, summary):
61                 self.summaries.append(summary)
62
63         def removeSummary(self, summary):
64                 self.summaries.remove(summary)
65
66         def setTitle(self, title):
67                 if self.instance:
68                         self.instance.setTitle(title)
69                 self["Title"].text = title
70                 self.summaries.setTitle(title)
71
72         def getTitle(self):
73                 return self["Title"].text
74
75         title = property(getTitle, setTitle)
76
77         def setDesktop(self, desktop):
78                 self.desktop = desktop
79
80         def applySkin(self):
81                 z = 0
82                 baseres = (720, 576) # FIXME: a skin might have set another resolution, which should be the base res
83                 idx = 0
84                 skin_title_idx = -1
85                 title = self.title
86                 for (key, value) in self.skinAttributes:
87                         if key == "zPosition":
88                                 z = int(value)
89                         elif key == "title":
90                                 skin_title_idx = idx
91                                 if title:
92                                         self.skinAttributes[skin_title_idx] = ("title", title)
93                                 else:
94                                         self["Title"].text = value
95                                         self.summaries.setTitle(value)
96                         elif key == "baseResolution":
97                                 baseres = tuple([int(x) for x in value.split(',')])
98                         idx += 1
99                 self.scale = ((baseres[0], baseres[0]), (baseres[1], baseres[1]))
100
101                 if not self.instance:
102                         from enigma import eWindow
103                         self.instance = eWindow(self.desktop, z)
104
105                 if skin_title_idx == -1 and title:
106                         self.skinAttributes.append(("title", title))
107
108                 # we need to make sure that certain attributes come last
109                 self.skinAttributes.sort(key=lambda a: {"position": 1}.get(a[0], 0))
110
111                 applyAllAttributes(self.instance, self.desktop, self.skinAttributes, self.scale)
112                 self.createGUIScreen(self.instance, self.desktop)