[RecordTimer] fix repeat timer issue.
[vuplus_dvbapp] / 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 from Tools.HardwareInfo import HardwareInfo
6 import skin
7
8 config.misc.rcused = ConfigInteger(default = 1)
9
10 class Rc:
11         def __init__(self):
12                 self["rc"] = MultiPixmap()
13                 self["arrowdown"] = MovingPixmap()
14                 self["arrowdown2"] = MovingPixmap()
15                 self["arrowup"] = MovingPixmap()
16                 self["arrowup2"] = MovingPixmap()
17
18                 self.initRcused()
19
20                 (rcArrowDownW, rcArrowDownH, rcArrowUpW, rcArrowUpH, rcheight, rcheighthalf) = (18, 70, 18, 0, 500, 250)
21                 if config.misc.rcused == 2:
22                         (rcArrowDownW, rcArrowDownH, rcArrowUpW, rcArrowUpH, rcheight, rcheighthalf) = skin.parameters.get("RcArrow", (18, 70, 18, 0, 500, 250))
23
24                 self.rcheight = rcheight
25                 self.rcheighthalf = rcheighthalf
26                 
27                 self.selectpics = []
28                 self.selectpics.append((self.rcheighthalf, ["arrowdown", "arrowdown2"], (-rcArrowDownW, -rcArrowDownH)))
29                 self.selectpics.append((self.rcheight, ["arrowup", "arrowup2"], (-rcArrowUpW, rcArrowUpH)))
30                 
31                 self.readPositions()
32                 self.clearSelectedKeys()
33                 self.onShown.append(self.initRc)
34
35         def initRcused(self):
36                 if config.misc.firstrun.value:
37                         boxType = HardwareInfo().get_vu_device_name()
38
39                         if boxType in ('bm750', 'uno', 'ultimo', 'solo2', 'duo2', 'solose', 'zero', 'solo4k', 'uno4k', 'ultimo4k'):
40                                 config.misc.rcused.value = 0
41                         elif boxType == 'solo':
42                                 config.misc.rcused.value = 1
43                         else:
44                                 config.misc.rcused.value = 2
45                         config.misc.rcused.save()
46
47         def initRc(self):
48                 self["rc"].setPixmapNum(config.misc.rcused.value)               
49                                 
50         def readPositions(self):
51                 tree = ElementTree(file = resolveFilename(SCOPE_SKIN, "rcpositions.xml"))
52                 rcs = tree.getroot()
53                 self.rcs = {}
54                 for rc in rcs:
55                         id = int(rc.attrib["id"])
56                         self.rcs[id] = {}
57                         for key in rc:
58                                 name = key.attrib["name"]
59                                 pos = key.attrib["pos"].split(",")
60                                 self.rcs[id][name] = (int(pos[0]), int(pos[1]))
61                 
62         def getSelectPic(self, pos):
63                 for selectPic in self.selectpics:
64                         if pos[1] <= selectPic[0]:
65                                 return (selectPic[1], selectPic[2])
66                 return None
67         
68         def hideRc(self):
69                 self["rc"].hide()
70                 self.hideSelectPics()
71                 
72         def showRc(self):
73                 self["rc"].show()
74
75         def selectKey(self, key):
76                 rc = self.rcs[config.misc.rcused.value]
77                 if rc.has_key(key):
78                         rcpos = self["rc"].getPosition()
79                         pos = rc[key]
80                         selectPics = self.getSelectPic(pos)
81                         selectPic = None
82                         for x in selectPics[0]:
83                                 if x not in self.selectedKeys:
84                                         selectPic = x
85                                         break
86                         if selectPic is not None:
87                                 print "selectPic:", selectPic
88                                 self[selectPic].moveTo(rcpos[0] + pos[0] + selectPics[1][0], rcpos[1] + pos[1] + selectPics[1][1], 1)
89                                 self[selectPic].startMoving()
90                                 self[selectPic].show()
91                                 self.selectedKeys.append(selectPic)
92         
93         def clearSelectedKeys(self):
94                 self.showRc()
95                 self.selectedKeys = []
96                 self.hideSelectPics()
97                 
98         def hideSelectPics(self):
99                 for selectPic in self.selectpics:
100                         for pic in selectPic[1]:
101                                 self[pic].hide()