remove lib/content
[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         "<screen name=\"clockDialog\" position=\"300,100\" size=\"300,300\"> \
15                 <widget name=\"okbutton\" position=\"10,10\" size=\"280,40\" /> \
16                 <widget name=\"theClock\" position=\"10,60\" size=\"280,50\" /> \
17                 <widget name=\"title\" position=\"10,120\" size=\"280,50\" /> \
18         </screen>")
19
20 def parsePosition(str):
21         x, y = str.split(',')
22         return ePoint(int(x), int(y))
23
24 def parseSize(str):
25         x, y = str.split(',')
26         return eSize(int(x), int(y))
27
28 def applyAttributes(guiObject, node):
29         # walk all attributes
30         for p in range(node.attributes.length):
31                 a = node.attributes.item(p)
32                 
33                 # and set attributes
34                 if a.name == 'position':
35                         guiObject.move(parsePosition(a.value))
36                 elif a.name == 'size':
37                         guiObject.resize(parseSize(a.value))
38                 elif a.name != 'name':
39                         print "unsupported attribute " + a.name
40
41 def applyGUIskin(screen, skin, name):
42         
43         myscreen = None
44         
45         # first, find the corresponding screen element
46         screens = dom.getElementsByTagName("screen")
47         for x in screens:
48                 if x.getAttribute('name') == name:
49                         myscreen = x
50         
51         if myscreen == None:
52                 print "no skin for screen " + name + " found!"
53                 return;
54         
55         # now walk all widgets
56         for widget in myscreen.getElementsByTagName("widget"):
57                 name = widget.getAttribute('name')
58                 if name == None:
59                         print "widget has no name!"
60                         continue
61                 
62                 # get corresponding gui object
63                 guiObject = screen.data[name]["instance"]
64                 applyAttributes(guiObject, widget)