49ee1d753baec92625a876de5206097110a7901d
[enigma2.git] / lib / python / Screens / Rc.py
1 from Components.Pixmap import MovingPixmap, MultiPixmap
2 from Tools.Directories import resolveFilename, SCOPE_SKIN
3 from xml.etree.ElementTree import ElementTree
4 from Components.config import config, ConfigInteger
5
6 config.misc.rcused = ConfigInteger(default = 1)
7
8 class Rc:
9         def __init__(self):
10                 self["rc"] = MultiPixmap()
11                 self["arrowdown"] = MovingPixmap()
12                 self["arrowdown2"] = MovingPixmap()
13                 self["arrowup"] = MovingPixmap()
14                 self["arrowup2"] = MovingPixmap()
15                 
16                 self.rcheight = 500
17                 self.rcheighthalf = 250
18                 
19                 self.selectpics = []
20                 self.selectpics.append((self.rcheighthalf, ["arrowdown", "arrowdown2"], (-18,-70)))
21                 self.selectpics.append((self.rcheight, ["arrowup", "arrowup2"], (-18,0)))
22                 
23                 self.readPositions()
24                 self.clearSelectedKeys()
25                 self.onShown.append(self.initRc)
26
27         def initRc(self):
28                 self["rc"].setPixmapNum(config.misc.rcused.value)
29                 
30                                 
31         def readPositions(self):
32                 tree = ElementTree(file = resolveFilename(SCOPE_SKIN, "rcpositions.xml"))
33                 rcs = tree.getroot()
34                 self.rcs = {}
35                 for rc in rcs:
36                         id = int(rc.attrib["id"])
37                         self.rcs[id] = {}
38                         print "id:", id
39                         for key in rc:
40                                 name = key.attrib["name"]
41                                 pos = key.attrib["pos"].split(",")
42                                 print "name:", name
43                                 print "pos:", pos
44                                 self.rcs[id][name] = (int(pos[0]), int(pos[1]))
45                 
46         def getSelectPic(self, pos):
47                 for selectPic in self.selectpics:
48                         if pos[1] <= selectPic[0]:
49                                 print "pos[1]:", pos[1]
50                                 print "selectPic[0]:", selectPic[0]
51                                 return (selectPic[1], selectPic[2])
52                 return None
53         
54         def hideRc(self):
55                 self["rc"].hide()
56                 self.hideSelectPics()
57                 
58         def showRc(self):
59                 self["rc"].show()
60
61         def selectKey(self, key):
62                 rc = self.rcs[config.misc.rcused.value]
63                 if rc.has_key(key):
64                         rcpos = self["rc"].getPosition()
65                         pos = rc[key]
66                         selectPics = self.getSelectPic(pos)
67                         selectPic = None
68                         for x in selectPics[0]:
69                                 if x not in self.selectedKeys:
70                                         selectPic = x
71                                         break
72                         if selectPic is not None:
73                                 print "selectPic:", selectPic
74                                 self[selectPic].show()
75                                 self[selectPic].moveTo(rcpos[0] + pos[0] + selectPics[1][0], rcpos[1] + pos[1] + selectPics[1][1], 1)
76                                 self[selectPic].startMoving()
77                                 self.selectedKeys.append(selectPic)
78         
79         def clearSelectedKeys(self):
80                 self.showRc()
81                 self.selectedKeys = []
82                 self.hideSelectPics()
83                 
84         def hideSelectPics(self):
85                 for selectPic in self.selectpics:
86                         for pic in selectPic[1]:
87                                 self[pic].hide()
88