sync spaces & CR
[enigma2.git] / lib / python / Screens / Satconfig.py
1 from Screen import Screen
2 from Components.ActionMap import NumberActionMap
3 from Components.ActionMap import ActionMap
4 from Components.ConfigList import ConfigList
5 from Components.config import *
6 from Components.MenuList import MenuList
7 from Components.NimManager import nimmanager
8 from Components.config import getConfigListEntry
9
10 class NimSetup(Screen):
11         def createSimpleSetup(self, nim, list, mode):
12                 if mode == 0:                   #single Sat
13                         list.append(getConfigListEntry("Satellite", config.Nims[nim.slotid].diseqcA))
14                 else:                                                   # > 1 Sats
15                         list.append(getConfigListEntry("Port A", config.Nims[nim.slotid].diseqcA))
16
17                 if mode >= 1:                   # > 1 Sats
18                         list.append(getConfigListEntry("Port B", config.Nims[nim.slotid].diseqcB))
19                         if mode >= 3:           # > 2 Sats
20                                 list.append(getConfigListEntry("Port C", config.Nims[nim.slotid].diseqcC))
21                                 list.append(getConfigListEntry("Port D", config.Nims[nim.slotid].diseqcD))
22         def createPositionerSetup(self, nim, list):
23                 list.append(getConfigListEntry("Longitude", config.Nims[nim.slotid].longitude))
24                 list.append(getConfigListEntry("Latitude", config.Nims[nim.slotid].latitude))
25                 pass
26         
27         def createSetup(self):
28                 self.list = [ ]
29                 
30                 self.list.append(getConfigListEntry("Configmode", config.Nims[self.nim.slotid].configMode))
31                 
32                 if config.Nims[self.nim.slotid].configMode.value == 0:                  #simple setup
33                         self.list.append(getConfigListEntry("Diseqcmode", config.Nims[self.nim.slotid].diseqcMode))
34                 
35                         if (0 <= config.Nims[self.nim.slotid].diseqcMode.value < 4):
36                                 self.createSimpleSetup(self.nim, self.list, config.Nims[self.nim.slotid].diseqcMode.value)
37                         if (config.Nims[self.nim.slotid].diseqcMode.value == 4):
38                                 self.createPositionerSetup(self.nim, self.list)
39                 else:   
40                         print "FIXME: implement advanced mode"
41
42                 self["config"].list = self.list
43                 self["config"].l.setList(self.list)
44                 
45         def newConfig(self):    
46                 if self["config"].getCurrent()[0] == "Diseqcmode":
47                         self.createSetup()
48                 if self["config"].getCurrent()[0] == "Configmode":
49                         self.createSetup()
50                 
51         def keyLeft(self):
52                 self["config"].handleKey(config.key["prevElement"])
53                 self.newConfig()
54
55         def keyRight(self):
56                 #forbid to enable advanced mode until its ready
57                 if self["config"].getCurrent()[0] != "Configmode":
58                         self["config"].handleKey(config.key["nextElement"])
59                 self.newConfig()
60
61         def keyNumberGlobal(self, number):
62                 print "You pressed number " + str(number)
63                 if (self["config"].getCurrent()[1].parent.enabled == True):
64                         self["config"].handleKey(config.key[str(number)])
65
66         def keySave(self):
67                 for x in self["config"].list:
68                         x[1].save()
69                 nimmanager.sec.update() 
70                 self.close()
71
72         def keyCancel(self):
73                 for x in self["config"].list:
74                         x[1].cancel()
75                 self.close()
76
77         def __init__(self, session, nim):
78                 Screen.__init__(self, session)
79                 self.nim = nim
80                 
81                 self["actions"] = NumberActionMap(["SetupActions"],
82                 {
83                         "ok": self.keySave,
84                         "cancel": self.keyCancel,
85                         "left": self.keyLeft,
86                         "right": self.keyRight,
87                         "1": self.keyNumberGlobal,
88                         "2": self.keyNumberGlobal,
89                         "3": self.keyNumberGlobal,
90                         "4": self.keyNumberGlobal,
91                         "5": self.keyNumberGlobal,
92                         "6": self.keyNumberGlobal,
93                         "7": self.keyNumberGlobal,
94                         "8": self.keyNumberGlobal,
95                         "9": self.keyNumberGlobal,
96                         "0": self.keyNumberGlobal
97                 }, -1)
98
99                 self.list = [ ]
100                 self["config"] = ConfigList(self.list)
101                 
102                 self.createSetup()
103
104 class NimSelection(Screen):
105         def __init__(self, session):
106                 Screen.__init__(self, session)
107
108                 self["nimlist"] = MenuList(nimmanager.nimList())
109
110                 self["actions"] = ActionMap(["OkCancelActions"],
111                 {
112                         "ok": self.okbuttonClick ,
113                         "cancel": self.close
114                 }, -1)
115
116         def okbuttonClick(self):
117                 selection = self["nimlist"].getCurrent()
118                 if selection[1].nimType != -1:  #unknown/empty
119                         self.session.open(NimSetup, selection[1])
120