get rid of unneede global keywords
[enigma2.git] / lib / python / Screens / Satconfig.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.ConfigList import ConfigList, ConfigListScreen
4 from Components.MenuList import MenuList
5 from Components.NimManager import nimmanager
6 from Components.config import getConfigListEntry, config, ConfigNothing
7
8 class NimSetup(Screen, ConfigListScreen):
9         def createSimpleSetup(self, list, mode):
10                 if mode == "single":
11                         list.append(getConfigListEntry(_("Satellite"), self.nimConfig.diseqcA))
12                 else:
13                         list.append(getConfigListEntry(_("Port A"), self.nimConfig.diseqcA))
14
15                 if mode in ["toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
16                         list.append(getConfigListEntry(_("Port B"), self.nimConfig.diseqcB))
17                         if mode == "diseqc_a_b_c_d":
18                                 list.append(getConfigListEntry(_("Port C"), self.nimConfig.diseqcC))
19                                 list.append(getConfigListEntry(_("Port D"), self.nimConfig.diseqcD))
20
21         def createPositionerSetup(self, list):
22 #               list.append(getConfigListEntry(_("Positioner mode"), self.nimConfig.positionerMode))
23 #               if self.nimConfig.positionerMode.value == "usals": # USALS
24                 list.append(getConfigListEntry(_("Longitude"), self.nimConfig.longitude))
25                 list.append(getConfigListEntry(" ", self.nimConfig.longitudeOrientation))
26                 list.append(getConfigListEntry(_("Latitude"), self.nimConfig.latitude))
27                 list.append(getConfigListEntry(" ", self.nimConfig.latitudeOrientation))
28 #               elif self.nimConfig.positionerMode.value == "manual": # manual
29 #                       pass
30
31         def createSetup(self):
32                 print "Creating setup"
33                 self.list = [ ]
34
35                 self.configMode = None
36                 self.diseqcModeEntry = None
37                 self.advancedSatsEntry = None
38                 self.advancedLnbsEntry = None
39                 self.advancedDiseqcMode = None
40                 self.advancedUsalsEntry = None
41                 self.advancedLof = None
42                 self.advancedPowerMeasurement = None
43                 
44                 self.nim_type = nimmanager.getNimType(self.nim.slotid)
45
46                 if self.nim_type == nimmanager.nimType["DVB-S"]:
47                         self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
48                         self.list.append(self.configMode)
49                         
50                         if self.nimConfig.configMode.value == "simple":                 #simple setup
51                                 self.diseqcModeEntry = getConfigListEntry(_("DiSEqC Mode"), self.nimConfig.diseqcMode)
52                                 self.list.append(self.diseqcModeEntry)
53                                 if self.nimConfig.diseqcMode.value in ["single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
54                                         self.createSimpleSetup(self.list, self.nimConfig.diseqcMode.value)
55                                 if self.nimConfig.diseqcMode.value == "positioner":
56                                         self.createPositionerSetup(self.list)
57                         elif self.nimConfig.configMode.value in ["loopthrough", "satposdepends", "nothing", "equal"]:
58                                 pass
59                         elif self.nimConfig.configMode.value == "advanced": # advanced
60                                 # SATs
61                                 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
62                                 self.list.append(self.advancedSatsEntry)
63                                 currSat = self.nimConfig.advanced.sat[self.nimConfig.advanced.sats.orbital_position]
64                                 self.fillListWithAdvancedSatEntrys(currSat)
65                         self.have_advanced = True
66                 elif self.nim_type == nimmanager.nimType["DVB-C"]:
67                         self.list.append(getConfigListEntry(_("Service scan type needed"), self.nimConfig.cabletype))
68                         self.have_advanced = False
69                 elif self.nim_type == nimmanager.nimType["DVB-T"]:
70                         self.have_advanced = False
71                         self.list.append(getConfigListEntry(_("Terrestrial provider"), self.nimConfig.terrestrial))
72                         self.list.append(getConfigListEntry(_("Enable 5V for active antenna"), self.nimConfig.terrestrial_5V))
73                 else:
74                         self.have_advanced = False
75
76                 self["config"].list = self.list
77                 self["config"].l.setList(self.list)
78
79         def newConfig(self):
80                 checkList = (self.configMode, self.diseqcModeEntry, self.advancedSatsEntry, self.advancedLnbsEntry, self.advancedDiseqcMode, self.advancedUsalsEntry, self.advancedLof, self.advancedPowerMeasurement)
81                 for x in checkList:
82                         if self["config"].getCurrent() == x:
83                                 self.createSetup()
84
85         def run(self):
86                 if self.have_advanced and config.Nims[self.nim.slotid].configMode.value == "advanced":
87                         self.fillAdvancedList()
88                 for x in self["config"].list:
89                         x[1].save()
90                 nimmanager.sec.update()
91
92         def fillListWithAdvancedSatEntrys(self, Sat):
93                 currLnb = self.nimConfig.advanced.lnb[int(Sat.lnb.value)]
94                 
95                 if isinstance(currLnb, ConfigNothing):
96                         currLnb = None
97
98                 self.list.append(getConfigListEntry(_("Voltage mode"), Sat.voltage))
99                 self.list.append(getConfigListEntry(_("Tone mode"), Sat.tonemode))
100                 if currLnb and currLnb.diseqcMode.value == "1_2":
101                         self.advancedUsalsEntry = getConfigListEntry(_("Use usals for this sat"), Sat.usals)
102                         self.list.append(self.advancedUsalsEntry)
103                         if not Sat.usals.value:
104                                 self.list.append(getConfigListEntry(_("Stored position"), Sat.rotorposition))
105
106                 # LNBs
107                 self.advancedLnbsEntry = getConfigListEntry(_("LNB"), Sat.lnb)
108                 self.list.append(self.advancedLnbsEntry)
109                 if currLnb:
110                         self.advancedDiseqcMode = getConfigListEntry(_("DiSEqC mode"), currLnb.diseqcMode)
111                         self.list.append(self.advancedDiseqcMode)
112                         if currLnb.diseqcMode.value != "none":
113                                 self.list.append(getConfigListEntry(_("Toneburst"), currLnb.toneburst))
114                                 self.list.append(getConfigListEntry(_("Committed DiSEqC command"), currLnb.commitedDiseqcCommand))
115                                 self.list.append(getConfigListEntry(_("Fast DiSEqC"), currLnb.fastDiseqc))
116                                 self.list.append(getConfigListEntry(_("Sequence repeat"), currLnb.sequenceRepeat))
117                                 if currLnb.diseqcMode.value == "1_0":
118                                         self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder1_0))
119                                 else:
120                                         self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder))
121                                         self.list.append(getConfigListEntry(_("Uncommitted DiSEqC command"), currLnb.uncommittedDiseqcCommand))
122                                         self.list.append(getConfigListEntry(_("DiSEqC repeats"), currLnb.diseqcRepeats))
123                                 if currLnb.diseqcMode.value == "1_2":
124                                         self.list.append(getConfigListEntry(_("Longitude"), currLnb.longitude))
125                                         self.list.append(getConfigListEntry(" ", currLnb.longitudeOrientation))
126                                         self.list.append(getConfigListEntry(_("Latitude"), currLnb.latitude))
127                                         self.list.append(getConfigListEntry(" ", currLnb.latitudeOrientation))
128                                         self.advancedPowerMeasurement = getConfigListEntry("Use Power Measurement", currLnb.powerMeasurement)
129                                         self.list.append(self.advancedPowerMeasurement)
130                                         if currLnb.powerMeasurement.value == "yes":
131                                                 self.list.append(getConfigListEntry("Power Threshold in mA", currLnb.powerThreshold))
132                         self.advancedLof = getConfigListEntry(_("LOF"), currLnb.lof)
133                         self.list.append(self.advancedLof)
134                         if currLnb.lof.value == "user_defined":
135                                 self.list.append(getConfigListEntry(_("LOF/L"), currLnb.lofl))
136                                 self.list.append(getConfigListEntry(_("LOF/H"), currLnb.lofh))
137                                 self.list.append(getConfigListEntry(_("Threshold"), currLnb.threshold))
138 #                       self.list.append(getConfigListEntry(_("12V Output"), currLnb.output_12v))
139                         self.list.append(getConfigListEntry(_("Increased voltage"), currLnb.increased_voltage))
140
141         def fillAdvancedList(self):
142                 self.list = [ ]
143                 self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
144                 self.list.append(self.configMode)
145                 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
146                 self.list.append(self.advancedSatsEntry)
147                 for x in nimmanager.satList:
148                         Sat = self.nimConfig.advanced.sat[x[0]]
149                         self.fillListWithAdvancedSatEntrys(Sat)
150                 self["config"].list = self.list
151
152         def keySave(self):
153                 self.run()
154                 self.close()
155
156         def __init__(self, session, slotid):
157                 Screen.__init__(self, session)
158                 self.list = [ ]
159
160                 ConfigListScreen.__init__(self, self.list)
161
162                 self["actions"] = ActionMap(["SetupActions"],
163                 {
164                         "ok": self.keySave,
165                         "cancel": self.keyCancel,
166                 }, -2)
167
168                 self.nim = nimmanager.nimList()[slotid][1]
169                 self.nimConfig = config.Nims[self.nim.slotid]
170                 self.createSetup()
171
172         def keyLeft(self):
173                 ConfigListScreen.keyLeft(self)
174                 self.newConfig()
175
176         def keyRight(self):
177                 ConfigListScreen.keyRight(self)
178                 self.newConfig()
179
180 class NimSelection(Screen):
181         def __init__(self, session):
182                 Screen.__init__(self, session)
183
184                 self["nimlist"] = MenuList(nimmanager.nimList())
185
186                 self["actions"] = ActionMap(["OkCancelActions"],
187                 {
188                         "ok": self.okbuttonClick ,
189                         "cancel": self.close
190                 }, -2)
191
192         def okbuttonClick(self):
193                 selection = self["nimlist"].getCurrent()
194                 if selection[1].nimType != -1:  #unknown/empty
195                         self.session.open(NimSetup, selection[1].slotid)