- add listbox
[openblackhole/openblackhole-enigma2.git] / skin.py
1 from enigma import *
2 import xml.dom.minidom
3 from xml.dom import EMPTY_NAMESPACE
4
5 def dump(x, i=0):
6         print " " * i + str(x)
7         try:
8                 for n in x.childNodes:
9                         dump(n, i + 1)
10         except:
11                 None
12
13 dom = xml.dom.minidom.parseString(
14         """
15         <skin>
16                 <screen name="testDialog">
17                         <widget name="okbutton" position="10,120" size="280,40" />
18                         <widget name="title" position="10,10" size="280,20" />
19                         <widget name="menu" position="10,30" size="280,90" />
20                 </screen>
21                 <screen name="clockDisplay" position="300,100" size="300,300">
22                         <widget name="okbutton" position="10,10" size="280,40" />
23                         <widget name="title" position="10,120" size="280,50" />
24                         <widget name="theClock" position="10,60" size="280,50" />
25                 </screen>
26         </skin>
27 """)
28
29
30
31 def parsePosition(str):
32         x, y = str.split(',')
33         return ePoint(int(x), int(y))
34
35 def parseSize(str):
36         x, y = str.split(',')
37         return eSize(int(x), int(y))
38
39 def applyAttributes(guiObject, node):
40         # walk all attributes
41         for p in range(node.attributes.length):
42                 a = node.attributes.item(p)
43                 
44                 # and set attributes
45                 if a.name == 'position':
46                         guiObject.move(parsePosition(a.value))
47                 elif a.name == 'size':
48                         guiObject.resize(parseSize(a.value))
49                 elif a.name != 'name':
50                         print "unsupported attribute " + a.name
51
52 def applyGUIskin(screen, skin, name):
53         
54         myscreen = None
55         
56         # first, find the corresponding screen element
57         skin = dom.getElementsByTagName("skin")[0]
58         screens = skin.getElementsByTagName("screen")
59         del skin
60         for x in screens:
61                 if x.getAttribute('name') == name:
62                         myscreen = x
63         
64         assert myscreen != None, "no skin for screen " + name + " found!"
65         
66         print "ok, found screen.."
67         
68         # now walk all widgets
69         for widget in myscreen.getElementsByTagName("widget"):
70                 name = widget.getAttribute('name')
71                 if name == None:
72                         print "widget has no name!"
73                         continue
74                 
75                 # get corresponding gui object
76                 guiObject = screen.data[name]["instance"]
77                 applyAttributes(guiObject, widget)