add support for up to 128 LNBs
[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                 config.misc.rcused = ConfigInteger(default = 1)
17                 
18                 self.rcheight = 500
19                 self.rcheighthalf = 250
20                 
21                 self.selectpics = []
22                 self.selectpics.append((self.rcheighthalf, ["arrowdown", "arrowdown2"], (-18,-70)))
23                 self.selectpics.append((self.rcheight, ["arrowup", "arrowup2"], (-18,0)))
24                 
25                 self.readPositions()
26                 self.clearSelectedKeys()
27                 self.onShown.append(self.initRc)
28
29         def initRc(self):
30                 self["rc"].setPixmapNum(config.misc.rcused.value)               
31                                 
32         def readPositions(self):
33                 tree = ElementTree(file = resolveFilename(SCOPE_SKIN, "rcpositions.xml"))
34                 rcs = tree.getroot()
35                 self.rcs = {}
36                 for rc in rcs:
37                         id = int(rc.attrib["id"])
38                         self.rcs[id] = {}
39                         for key in rc:
40                                 name = key.attrib["name"]
41                                 pos = key.attrib["pos"].split(",")
42                                 self.rcs[id][name] = (int(pos[0]), int(pos[1]))
43                 
44         def getSelectPic(self, pos):
45                 for selectPic in self.selectpics:
46                         if pos[1] <= selectPic[0]:
47                                 return (selectPic[1], selectPic[2])
48                 return None
49         
50         def hideRc(self):
51                 self["rc"].hide()
52                 self.hideSelectPics()
53                 
54         def showRc(self):
55                 self["rc"].show()
56
57         def selectKey(self, key):
58                 rc = self.rcs[config.misc.rcused.value]
59                 if rc.has_key(key):
60                         rcpos = self["rc"].getPosition()
61                         pos = rc[key]
62                         selectPics = self.getSelectPic(pos)
63                         selectPic = None
64                         for x in selectPics[0]:
65                                 if x not in self.selectedKeys:
66                                         selectPic = x
67                                         break
68                         if selectPic is not None:
69                                 print "selectPic:", selectPic
70                                 self[selectPic].moveTo(rcpos[0] + pos[0] + selectPics[1][0], rcpos[1] + pos[1] + selectPics[1][1], 1)
71                                 self[selectPic].startMoving()
72                                 self[selectPic].show()
73                                 self.selectedKeys.append(selectPic)
74         
75         def clearSelectedKeys(self):
76                 self.showRc()
77                 self.selectedKeys = []
78                 self.hideSelectPics()
79                 
80         def hideSelectPics(self):
81                 for selectPic in self.selectpics:
82                         for pic in selectPic[1]:
83                                 self[pic].hide()
84