properly use rcused config element
[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 class Rc:
7         def __init__(self):
8                 self["rc"] = MultiPixmap()
9                 self["arrowdown"] = MovingPixmap()
10                 self["arrowdown2"] = MovingPixmap()
11                 self["arrowup"] = MovingPixmap()
12                 self["arrowup2"] = MovingPixmap()
13                 
14                 config.misc.rcused = ConfigInteger(default = 1)
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         def readPositions(self):
31                 tree = ElementTree(file = resolveFilename(SCOPE_SKIN, "rcpositions.xml"))
32                 rcs = tree.getroot()
33                 self.rcs = {}
34                 for rc in rcs:
35                         id = int(rc.attrib["id"])
36                         self.rcs[id] = {}
37                         for key in rc:
38                                 name = key.attrib["name"]
39                                 pos = key.attrib["pos"].split(",")
40                                 self.rcs[id][name] = (int(pos[0]), int(pos[1]))
41                 
42         def getSelectPic(self, pos):
43                 for selectPic in self.selectpics:
44                         if pos[1] <= selectPic[0]:
45                                 return (selectPic[1], selectPic[2])
46                 return None
47         
48         def hideRc(self):
49                 self["rc"].hide()
50                 self.hideSelectPics()
51                 
52         def showRc(self):
53                 self["rc"].show()
54
55         def selectKey(self, key):
56                 rc = self.rcs[config.misc.rcused.value]
57                 if rc.has_key(key):
58                         rcpos = self["rc"].getPosition()
59                         pos = rc[key]
60                         selectPics = self.getSelectPic(pos)
61                         selectPic = None
62                         for x in selectPics[0]:
63                                 if x not in self.selectedKeys:
64                                         selectPic = x
65                                         break
66                         if selectPic is not None:
67                                 print "selectPic:", selectPic
68                                 self[selectPic].moveTo(rcpos[0] + pos[0] + selectPics[1][0], rcpos[1] + pos[1] + selectPics[1][1], 1)
69                                 self[selectPic].startMoving()
70                                 self[selectPic].show()
71                                 self.selectedKeys.append(selectPic)
72         
73         def clearSelectedKeys(self):
74                 self.showRc()
75                 self.selectedKeys = []
76                 self.hideSelectPics()
77                 
78         def hideSelectPics(self):
79                 for selectPic in self.selectpics:
80                         for pic in selectPic[1]:
81                                 self[pic].hide()
82