dont use os.system when not needed,
[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                         for key in rc:
39                                 name = key.attrib["name"]
40                                 pos = key.attrib["pos"].split(",")
41                                 self.rcs[id][name] = (int(pos[0]), int(pos[1]))
42                 
43         def getSelectPic(self, pos):
44                 for selectPic in self.selectpics:
45                         if pos[1] <= selectPic[0]:
46                                 return (selectPic[1], selectPic[2])
47                 return None
48         
49         def hideRc(self):
50                 self["rc"].hide()
51                 self.hideSelectPics()
52                 
53         def showRc(self):
54                 self["rc"].show()
55
56         def selectKey(self, key):
57                 rc = self.rcs[config.misc.rcused.value]
58                 if rc.has_key(key):
59                         rcpos = self["rc"].getPosition()
60                         pos = rc[key]
61                         selectPics = self.getSelectPic(pos)
62                         selectPic = None
63                         for x in selectPics[0]:
64                                 if x not in self.selectedKeys:
65                                         selectPic = x
66                                         break
67                         if selectPic is not None:
68                                 print "selectPic:", selectPic
69                                 self[selectPic].show()
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.selectedKeys.append(selectPic)
73         
74         def clearSelectedKeys(self):
75                 self.showRc()
76                 self.selectedKeys = []
77                 self.hideSelectPics()
78                 
79         def hideSelectPics(self):
80                 for selectPic in self.selectpics:
81                         for pic in selectPic[1]:
82                                 self[pic].hide()
83