PEP8: Fix whitespace
[openblackhole/openblackhole-enigma2.git] / lib / python / Screens / Satconfig.py
1 from enigma import eDVBDB
2 from Screen import Screen
3 from Components.SystemInfo import SystemInfo
4 from Components.ActionMap import ActionMap
5 from Components.ConfigList import ConfigListScreen
6 from Components.MenuList import MenuList
7 from Components.NimManager import nimmanager
8 from Components.Button import Button
9 from Components.Label import Label
10 from Components.SelectionList import SelectionList, SelectionEntryComponent
11 from Components.config import getConfigListEntry, config, ConfigNothing, ConfigSelection, updateConfigElement, ConfigSatlist, ConfigYesNo, configfile
12 from Components.Sources.List import List
13 from Screens.MessageBox import MessageBox
14 from Screens.ChoiceBox import ChoiceBox
15 from Screens.ServiceStopScreen import ServiceStopScreen
16 from Screens.AutoDiseqc import AutoDiseqc
17 from Tools.BoundFunction import boundFunction
18
19 from time import mktime, localtime
20 from datetime import datetime
21
22 class NimSetup(Screen, ConfigListScreen, ServiceStopScreen):
23         def createSimpleSetup(self, list, mode):
24                 nim = self.nimConfig
25
26                 if mode == "single":
27                         self.singleSatEntry = getConfigListEntry(_("Satellite"), nim.diseqcA)
28                         list.append(self.singleSatEntry)
29                         if nim.diseqcA.value in ("360", "560"):
30                                 list.append(getConfigListEntry(_("Use circular LNB"), nim.simpleDiSEqCSetCircularLNB))
31                         list.append(getConfigListEntry(_("Send DiSEqC"), nim.simpleSingleSendDiSEqC))
32                 else:
33                         list.append(getConfigListEntry(_("Port A"), nim.diseqcA))
34
35                 if mode in ("toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"):
36                         list.append(getConfigListEntry(_("Port B"), nim.diseqcB))
37                         if mode == "diseqc_a_b_c_d":
38                                 list.append(getConfigListEntry(_("Port C"), nim.diseqcC))
39                                 list.append(getConfigListEntry(_("Port D"), nim.diseqcD))
40                         if mode != "toneburst_a_b":
41                                 list.append(getConfigListEntry(_("Set voltage and 22KHz"), nim.simpleDiSEqCSetVoltageTone))
42                                 list.append(getConfigListEntry(_("Send DiSEqC only on satellite change"), nim.simpleDiSEqCOnlyOnSatChange))
43
44         def createPositionerSetup(self, list):
45                 nim = self.nimConfig
46                 if nim.diseqcMode.value == "positioner_select":
47                         self.selectSatsEntry = getConfigListEntry(_("Press OK to select satellites"), self.nimConfig.pressOKtoList)
48                         list.append(self.selectSatsEntry)
49                 list.append(getConfigListEntry(_("Longitude"), nim.longitude))
50                 list.append(getConfigListEntry(" ", nim.longitudeOrientation))
51                 list.append(getConfigListEntry(_("Latitude"), nim.latitude))
52                 list.append(getConfigListEntry(" ", nim.latitudeOrientation))
53                 if SystemInfo["CanMeasureFrontendInputPower"]:
54                         self.advancedPowerMeasurement = getConfigListEntry(_("Use power measurement"), nim.powerMeasurement)
55                         list.append(self.advancedPowerMeasurement)
56                         if nim.powerMeasurement.value:
57                                 list.append(getConfigListEntry(_("Power threshold in mA"), nim.powerThreshold))
58                                 self.turningSpeed = getConfigListEntry(_("Rotor turning speed"), nim.turningSpeed)
59                                 list.append(self.turningSpeed)
60                                 if nim.turningSpeed.value == "fast epoch":
61                                         self.turnFastEpochBegin = getConfigListEntry(_("Begin time"), nim.fastTurningBegin)
62                                         self.turnFastEpochEnd = getConfigListEntry(_("End time"), nim.fastTurningEnd)
63                                         list.append(self.turnFastEpochBegin)
64                                         list.append(self.turnFastEpochEnd)
65                 else:
66                         if nim.powerMeasurement.value:
67                                 nim.powerMeasurement.value = False
68                                 nim.powerMeasurement.save()
69                 if not hasattr(self, 'additionalMotorOptions'):
70                         self.additionalMotorOptions = ConfigYesNo(False)
71                 self.showAdditionalMotorOptions = getConfigListEntry(_("Extra motor options"), self.additionalMotorOptions)
72                 self.list.append(self.showAdditionalMotorOptions)
73                 if self.additionalMotorOptions.value:
74                         self.list.append(getConfigListEntry("   " + _("Horizontal turning speed") + " [" + chr(176) + "/sec]", nim.turningspeedH))
75                         self.list.append(getConfigListEntry("   " + _("Vertical turning speed") + " [" + chr(176) + "/sec]", nim.turningspeedV))
76                         self.list.append(getConfigListEntry("   " + _("Turning step size") + " [" + chr(176) + "]", nim.tuningstepsize))
77                         self.list.append(getConfigListEntry("   " + _("Max memory positions"), nim.rotorPositions))
78
79         def createConfigMode(self):
80                 if self.nim.isCompatible("DVB-S"):
81                         choices = {"nothing": _("Not configured"),
82                                                 "simple": _("Simple"),
83                                                 "advanced": _("Advanced")}
84                         if len(nimmanager.canEqualTo(self.slotid)) > 0:
85                                 choices["equal"] = _("Equal to")
86                         if len(nimmanager.canDependOn(self.slotid)) > 0:
87                                 choices["satposdepends"] = _("Second cable of motorized LNB")
88                         if len(nimmanager.canConnectTo(self.slotid)) > 0:
89                                 choices["loopthrough"] = _("Loop through to")
90                         self.nimConfig.configMode.setChoices(choices, default = "simple")
91
92         def createSetup(self):
93                 print "Creating setup"
94                 self.list = [ ]
95
96                 self.multiType = None
97                 self.configMode = None
98                 self.diseqcModeEntry = None
99                 self.advancedSatsEntry = None
100                 self.advancedLnbsEntry = None
101                 self.advancedDiseqcMode = None
102                 self.advancedUsalsEntry = None
103                 self.advancedLof = None
104                 self.advancedPowerMeasurement = None
105                 self.turningSpeed = None
106                 self.turnFastEpochBegin = None
107                 self.turnFastEpochEnd = None
108                 self.toneburst = None
109                 self.committedDiseqcCommand = None
110                 self.uncommittedDiseqcCommand = None
111                 self.commandOrder = None
112                 self.cableScanType = None
113                 self.have_advanced = False
114                 self.advancedUnicable = None
115                 self.advancedType = None
116                 self.advancedManufacturer = None
117                 self.advancedSCR = None
118                 self.advancedConnected = None
119                 self.showAdditionalMotorOptions = None
120                 self.selectSatsEntry = None
121                 self.advancedSelectSatsEntry = None
122                 self.singleSatEntry = None
123
124                 if self.nim.isMultiType():
125                         multiType = self.nimConfig.multiType
126                         self.multiType = getConfigListEntry(_("Tuner type"), multiType)
127                         self.list.append(self.multiType)
128
129                 if self.nim.isCompatible("DVB-S"):
130                         self.configMode = getConfigListEntry(_("Configuration mode"), self.nimConfig.configMode)
131                         self.list.append(self.configMode)
132
133                         if self.nimConfig.configMode.value == "simple":                 #simple setup
134                                 self.diseqcModeEntry = getConfigListEntry(pgettext("Satellite configuration mode", "Mode"), self.nimConfig.diseqcMode)
135                                 self.list.append(self.diseqcModeEntry)
136                                 if self.nimConfig.diseqcMode.value in ("single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"):
137                                         self.createSimpleSetup(self.list, self.nimConfig.diseqcMode.value)
138                                 if self.nimConfig.diseqcMode.value in ("positioner", "positioner_select"):
139                                         self.createPositionerSetup(self.list)
140                         elif self.nimConfig.configMode.value == "equal":
141                                 choices = []
142                                 nimlist = nimmanager.canEqualTo(self.nim.slot)
143                                 for id in nimlist:
144                                         choices.append((str(id), nimmanager.getNimDescription(id)))
145                                 self.nimConfig.connectedTo.setChoices(choices)
146                                 self.list.append(getConfigListEntry(_("Tuner"), self.nimConfig.connectedTo))
147                         elif self.nimConfig.configMode.value == "satposdepends":
148                                 choices = []
149                                 nimlist = nimmanager.canDependOn(self.nim.slot)
150                                 for id in nimlist:
151                                         choices.append((str(id), nimmanager.getNimDescription(id)))
152                                 self.nimConfig.connectedTo.setChoices(choices)
153                                 self.list.append(getConfigListEntry(_("Tuner"), self.nimConfig.connectedTo))
154                         elif self.nimConfig.configMode.value == "loopthrough":
155                                 choices = []
156                                 print "connectable to:", nimmanager.canConnectTo(self.slotid)
157                                 connectable = nimmanager.canConnectTo(self.slotid)
158                                 for id in connectable:
159                                         choices.append((str(id), nimmanager.getNimDescription(id)))
160                                 self.nimConfig.connectedTo.setChoices(choices)
161                                 self.list.append(getConfigListEntry(_("Connected to"), self.nimConfig.connectedTo))
162                         elif self.nimConfig.configMode.value == "nothing":
163                                 pass
164                         elif self.nimConfig.configMode.value == "advanced": # advanced
165                                 # SATs
166                                 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
167                                 self.list.append(self.advancedSatsEntry)
168                                 current_config_sats = self.nimConfig.advanced.sats.value
169                                 if current_config_sats in ("3605", "3606"):
170                                         self.advancedSelectSatsEntry = getConfigListEntry(_("Press OK to select satellites"), self.nimConfig.pressOKtoList)
171                                         self.list.append(self.advancedSelectSatsEntry)
172                                         self.fillListWithAdvancedSatEntrys(self.nimConfig.advanced.sat[int(current_config_sats)])
173                                 else:
174                                         cur_orb_pos = self.nimConfig.advanced.sats.orbital_position
175                                         satlist = self.nimConfig.advanced.sat.keys()
176                                         if cur_orb_pos is not None:
177                                                 if cur_orb_pos not in satlist:
178                                                         cur_orb_pos = satlist[0]
179                                                 self.fillListWithAdvancedSatEntrys(self.nimConfig.advanced.sat[cur_orb_pos])
180                                 self.have_advanced = True
181                         if self.nim.description == "Alps BSBE2" and config.usage.setup_level.index >= 2: # expert
182                                 self.list.append(getConfigListEntry(_("Tone amplitude"), self.nimConfig.toneAmplitude))
183                 elif self.nim.isCompatible("DVB-C"):
184                         self.configMode = getConfigListEntry(_("Configuration mode"), self.nimConfig.configMode)
185                         self.list.append(self.configMode)
186                         if self.nimConfig.configMode.value == "enabled":
187                                 self.list.append(getConfigListEntry(_("Network ID"), self.nimConfig.cable.scan_networkid))
188                                 self.cableScanType=getConfigListEntry(_("Used service scan type"), self.nimConfig.cable.scan_type)
189                                 self.list.append(self.cableScanType)
190                                 if self.nimConfig.cable.scan_type.value == "provider":
191                                         self.list.append(getConfigListEntry(_("Provider to scan"), self.nimConfig.cable.scan_provider))
192                                 else:
193                                         if self.nimConfig.cable.scan_type.value == "bands":
194                                                 # TRANSLATORS: option name, indicating which type of (DVB-C) band should be scanned. The name of the band is printed in '%s'. E.g.: 'Scan EU MID band'
195                                                 self.list.append(getConfigListEntry(_("Scan %s band") % ("EU VHF I"), self.nimConfig.cable.scan_band_EU_VHF_I))
196                                                 self.list.append(getConfigListEntry(_("Scan %s band") % ("EU MID"), self.nimConfig.cable.scan_band_EU_MID))
197                                                 self.list.append(getConfigListEntry(_("Scan %s band") % ("EU VHF III"), self.nimConfig.cable.scan_band_EU_VHF_III))
198                                                 self.list.append(getConfigListEntry(_("Scan %s band") % ("EU UHF IV"), self.nimConfig.cable.scan_band_EU_UHF_IV))
199                                                 self.list.append(getConfigListEntry(_("Scan %s band") % ("EU UHF V"), self.nimConfig.cable.scan_band_EU_UHF_V))
200                                                 self.list.append(getConfigListEntry(_("Scan %s band") % ("EU SUPER"), self.nimConfig.cable.scan_band_EU_SUPER))
201                                                 self.list.append(getConfigListEntry(_("Scan %s band") % ("EU HYPER"), self.nimConfig.cable.scan_band_EU_HYPER))
202                                                 self.list.append(getConfigListEntry(_("Scan %s band") % ("US LOW"), self.nimConfig.cable.scan_band_US_LOW))
203                                                 self.list.append(getConfigListEntry(_("Scan %s band") % ("US MID"), self.nimConfig.cable.scan_band_US_MID))
204                                                 self.list.append(getConfigListEntry(_("Scan %s band") % ("US HIGH"), self.nimConfig.cable.scan_band_US_HIGH))
205                                                 self.list.append(getConfigListEntry(_("Scan %s band") % ("US SUPER"), self.nimConfig.cable.scan_band_US_SUPER))
206                                                 self.list.append(getConfigListEntry(_("Scan %s band") % ("US HYPER"), self.nimConfig.cable.scan_band_US_HYPER))
207                                         elif self.nimConfig.cable.scan_type.value == "steps":
208                                                 self.list.append(getConfigListEntry(_("Frequency scan step size(khz)"), self.nimConfig.cable.scan_frequency_steps))
209                                         # TRANSLATORS: option name, indicating which type of (DVB-C) modulation should be scanned. The modulation type is printed in '%s'. E.g.: 'Scan QAM16'
210                                         self.list.append(getConfigListEntry(_("Scan %s") % ("QAM16"), self.nimConfig.cable.scan_mod_qam16))
211                                         self.list.append(getConfigListEntry(_("Scan %s") % ("QAM32"), self.nimConfig.cable.scan_mod_qam32))
212                                         self.list.append(getConfigListEntry(_("Scan %s") % ("QAM64"), self.nimConfig.cable.scan_mod_qam64))
213                                         self.list.append(getConfigListEntry(_("Scan %s") % ("QAM128"), self.nimConfig.cable.scan_mod_qam128))
214                                         self.list.append(getConfigListEntry(_("Scan %s") % ("QAM256"), self.nimConfig.cable.scan_mod_qam256))
215                                         self.list.append(getConfigListEntry(_("Scan %s") % ("SR6900"), self.nimConfig.cable.scan_sr_6900))
216                                         self.list.append(getConfigListEntry(_("Scan %s") % ("SR6875"), self.nimConfig.cable.scan_sr_6875))
217                                         self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext1))
218                                         self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext2))
219                         self.have_advanced = False
220                 elif self.nim.isCompatible("DVB-T"):
221                         self.configMode = getConfigListEntry(_("Configuration mode"), self.nimConfig.configMode)
222                         self.list.append(self.configMode)
223                         self.have_advanced = False
224                         if self.nimConfig.configMode.value == "enabled":
225                                 self.list.append(getConfigListEntry(_("Terrestrial provider"), self.nimConfig.terrestrial))
226                                 self.list.append(getConfigListEntry(_("Enable 5V for active antenna"), self.nimConfig.terrestrial_5V))
227                 else:
228                         self.have_advanced = False
229                 self["config"].list = self.list
230                 self["config"].l.setList(self.list)
231
232         def newConfig(self):
233                 self.setTextKeyBlue()
234                 checkList = (self.configMode, self.diseqcModeEntry, self.advancedSatsEntry, \
235                         self.advancedLnbsEntry, self.advancedDiseqcMode, self.advancedUsalsEntry, \
236                         self.advancedLof, self.advancedPowerMeasurement, self.turningSpeed, \
237                         self.advancedType, self.advancedSCR, self.advancedManufacturer, self.advancedUnicable, self.advancedConnected, \
238                         self.toneburst, self.committedDiseqcCommand, self.uncommittedDiseqcCommand, self.singleSatEntry, \
239                         self.commandOrder, self.showAdditionalMotorOptions, self.cableScanType, self.multiType)
240                 if self["config"].getCurrent() == self.multiType:
241                         from Components.NimManager import InitNimManager
242                         InitNimManager(nimmanager)
243                         self.nim = nimmanager.nim_slots[self.slotid]
244                         self.nimConfig = self.nim.config
245
246                 for x in checkList:
247                         if self["config"].getCurrent() == x:
248                                 self.createSetup()
249                                 break
250
251         def run(self):
252                 if self.nimConfig.configMode.value == "simple":
253                         autodiseqc_ports = 0
254                         if self.nimConfig.diseqcMode.value == "single":
255                                 if self.nimConfig.diseqcA.orbital_position == 3600:
256                                         autodiseqc_ports = 1
257                         elif self.nimConfig.diseqcMode.value == "diseqc_a_b":
258                                 if self.nimConfig.diseqcA.orbital_position == 3600 or self.nimConfig.diseqcB.orbital_position == 3600:
259                                         autodiseqc_ports = 2
260                         elif self.nimConfig.diseqcMode.value == "diseqc_a_b_c_d":
261                                 if self.nimConfig.diseqcA.orbital_position == 3600 or self.nimConfig.diseqcB.orbital_position == 3600 or self.nimConfig.diseqcC.orbital_position == 3600 or self.nimConfig.diseqcD.orbital_position == 3600:
262                                         autodiseqc_ports = 4
263                         if autodiseqc_ports:
264                                 self.autoDiseqcRun(autodiseqc_ports)
265                                 return False
266                 if self.have_advanced and self.nim.config_mode == "advanced":
267                         self.fillAdvancedList()
268                 for x in self.list:
269                         if x in (self.turnFastEpochBegin, self.turnFastEpochEnd):
270                                 # workaround for storing only hour*3600+min*60 value in configfile
271                                 # not really needed.. just for cosmetics..
272                                 tm = localtime(x[1].value)
273                                 dt = datetime(1970, 1, 1, tm.tm_hour, tm.tm_min)
274                                 x[1].value = int(mktime(dt.timetuple()))
275                         x[1].save()
276                 nimmanager.sec.update()
277                 self.saveAll()
278                 return True
279
280         def autoDiseqcRun(self, ports):
281                 self.session.openWithCallback(self.autoDiseqcCallback, AutoDiseqc, self.slotid, ports, self.nimConfig.simpleDiSEqCSetVoltageTone, self.nimConfig.simpleDiSEqCOnlyOnSatChange)
282
283         def autoDiseqcCallback(self, result):
284                 from Screens.Wizard import Wizard
285                 if Wizard.instance is not None:
286                         Wizard.instance.back()
287                 else:
288                         self.createSetup()
289
290         def fillListWithAdvancedSatEntrys(self, Sat):
291                 lnbnum = int(Sat.lnb.value)
292                 currLnb = self.nimConfig.advanced.lnb[lnbnum]
293
294                 if isinstance(currLnb, ConfigNothing):
295                         currLnb = None
296
297                 # LNBs
298                 self.advancedLnbsEntry = getConfigListEntry(_("LNB"), Sat.lnb)
299                 self.list.append(self.advancedLnbsEntry)
300
301                 if currLnb:
302                         self.list.append(getConfigListEntry(_("Priority"), currLnb.prio))
303                         self.advancedLof = getConfigListEntry("LOF", currLnb.lof)
304                         self.list.append(self.advancedLof)
305                         if currLnb.lof.value == "user_defined":
306                                 self.list.append(getConfigListEntry("LOF/L", currLnb.lofl))
307                                 self.list.append(getConfigListEntry("LOF/H", currLnb.lofh))
308                                 self.list.append(getConfigListEntry(_("Threshold"), currLnb.threshold))
309
310                         if currLnb.lof.value == "unicable":
311                                 self.advancedUnicable = getConfigListEntry("Unicable "+_("Configuration mode"), currLnb.unicable)
312                                 self.list.append(self.advancedUnicable)
313                                 if currLnb.unicable.value == "unicable_user":
314                                         self.advancedSCR = getConfigListEntry(_("Channel"), currLnb.satcruser)
315                                         self.list.append(self.advancedSCR)
316                                         self.list.append(getConfigListEntry(_("Frequency"), currLnb.satcrvcouser[currLnb.satcruser.index]))
317                                         self.list.append(getConfigListEntry("LOF/L", currLnb.lofl))
318                                         self.list.append(getConfigListEntry("LOF/H", currLnb.lofh))
319                                         self.list.append(getConfigListEntry(_("Threshold"), currLnb.threshold))
320                                 elif currLnb.unicable.value == "unicable_matrix":
321                                         manufacturer_name = currLnb.unicableMatrixManufacturer.value
322                                         manufacturer = currLnb.unicableMatrix[manufacturer_name]
323                                         product_name = manufacturer.product.value
324                                         self.advancedManufacturer = getConfigListEntry(_("Manufacturer"), currLnb.unicableMatrixManufacturer)
325                                         self.advancedType = getConfigListEntry(_("Type"), manufacturer.product)
326                                         self.advancedSCR = getConfigListEntry(_("Channel"), manufacturer.scr[product_name])
327                                         self.list.append(self.advancedManufacturer)
328                                         self.list.append(self.advancedType)
329                                         self.list.append(self.advancedSCR)
330                                         self.list.append(getConfigListEntry(_("Frequency"), manufacturer.vco[product_name][manufacturer.scr[product_name].index]))
331                                 elif currLnb.unicable.value == "unicable_lnb":
332                                         manufacturer_name = currLnb.unicableLnbManufacturer.value
333                                         manufacturer = currLnb.unicableLnb[manufacturer_name]
334                                         product_name = manufacturer.product.value
335                                         self.advancedManufacturer = getConfigListEntry(_("Manufacturer"), currLnb.unicableLnbManufacturer)
336                                         self.advancedType = getConfigListEntry(_("Type"), manufacturer.product)
337                                         self.advancedSCR = getConfigListEntry(_("Channel"), manufacturer.scr[product_name])
338                                         self.list.append(self.advancedManufacturer)
339                                         self.list.append(self.advancedType)
340                                         self.list.append(self.advancedSCR)
341                                         self.list.append(getConfigListEntry(_("Frequency"), manufacturer.vco[product_name][manufacturer.scr[product_name].index]))
342
343                                 choices = []
344                                 connectable = nimmanager.canConnectTo(self.slotid)
345                                 for id in connectable:
346                                         choices.append((str(id), nimmanager.getNimDescription(id)))
347                                 if len(choices):
348                                         self.advancedConnected = getConfigListEntry(_("connected"), self.nimConfig.advanced.unicableconnected)
349                                         self.list.append(self.advancedConnected)
350                                         if self.nimConfig.advanced.unicableconnected.value == True:
351                                                 self.nimConfig.advanced.unicableconnectedTo.setChoices(choices)
352                                                 self.list.append(getConfigListEntry(_("Connected to"),self.nimConfig.advanced.unicableconnectedTo))
353
354                         else:   #kein Unicable
355                                 self.list.append(getConfigListEntry(_("Voltage mode"), Sat.voltage))
356                                 self.list.append(getConfigListEntry(_("Increased voltage"), currLnb.increased_voltage))
357                                 self.list.append(getConfigListEntry(_("Tone mode"), Sat.tonemode))
358
359                         if lnbnum < 65:
360                                 self.advancedDiseqcMode = getConfigListEntry(_("DiSEqC mode"), currLnb.diseqcMode)
361                                 self.list.append(self.advancedDiseqcMode)
362                         if currLnb.diseqcMode.value != "none":
363                                 self.list.append(getConfigListEntry(_("Fast DiSEqC"), currLnb.fastDiseqc))
364                                 self.toneburst = getConfigListEntry(_("Toneburst"), currLnb.toneburst)
365                                 self.list.append(self.toneburst)
366                                 self.committedDiseqcCommand = getConfigListEntry(_("DiSEqC 1.0 command"), currLnb.commitedDiseqcCommand)
367                                 self.list.append(self.committedDiseqcCommand)
368                                 if currLnb.diseqcMode.value == "1_0":
369                                         if currLnb.toneburst.index and currLnb.commitedDiseqcCommand.index:
370                                                 self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder1_0))
371                                 else:
372                                         self.uncommittedDiseqcCommand = getConfigListEntry(_("DiSEqC 1.1 command"), currLnb.uncommittedDiseqcCommand)
373                                         self.list.append(self.uncommittedDiseqcCommand)
374                                         if currLnb.uncommittedDiseqcCommand.index:
375                                                 if currLnb.commandOrder.value == "ct":
376                                                         currLnb.commandOrder.value = "cut"
377                                                 elif currLnb.commandOrder.value == "tc":
378                                                         currLnb.commandOrder.value = "tcu"
379                                         else:
380                                                 if currLnb.commandOrder.index & 1:
381                                                         currLnb.commandOrder.value = "tc"
382                                                 else:
383                                                         currLnb.commandOrder.value = "ct"
384                                         self.commandOrder = getConfigListEntry(_("Command order"), currLnb.commandOrder)
385                                         if 1 < ((1 if currLnb.uncommittedDiseqcCommand.index else 0) + (1 if currLnb.commitedDiseqcCommand.index else 0) + (1 if currLnb.toneburst.index else 0)):
386                                                 self.list.append(self.commandOrder)
387                                         if currLnb.uncommittedDiseqcCommand.index:
388                                                 self.list.append(getConfigListEntry(_("DiSEqC 1.1 repeats"), currLnb.diseqcRepeats))
389                                 self.list.append(getConfigListEntry(_("Sequence repeat"), currLnb.sequenceRepeat))
390                                 if currLnb.diseqcMode.value == "1_2":
391                                         if SystemInfo["CanMeasureFrontendInputPower"]:
392                                                 self.advancedPowerMeasurement = getConfigListEntry(_("Use power measurement"), currLnb.powerMeasurement)
393                                                 self.list.append(self.advancedPowerMeasurement)
394                                                 if currLnb.powerMeasurement.value:
395                                                         self.list.append(getConfigListEntry(_("Power threshold in mA"), currLnb.powerThreshold))
396                                                         self.turningSpeed = getConfigListEntry(_("Rotor turning speed"), currLnb.turningSpeed)
397                                                         self.list.append(self.turningSpeed)
398                                                         if currLnb.turningSpeed.value == "fast epoch":
399                                                                 self.turnFastEpochBegin = getConfigListEntry(_("Begin time"), currLnb.fastTurningBegin)
400                                                                 self.turnFastEpochEnd = getConfigListEntry(_("End time"), currLnb.fastTurningEnd)
401                                                                 self.list.append(self.turnFastEpochBegin)
402                                                                 self.list.append(self.turnFastEpochEnd)
403                                         else:
404                                                 if currLnb.powerMeasurement.value:
405                                                         currLnb.powerMeasurement.value = False
406                                                         currLnb.powerMeasurement.save()
407                                         self.advancedUsalsEntry = getConfigListEntry(_("Use USALS for this sat"), Sat.usals)
408                                         if lnbnum < 65:
409                                                 self.list.append(self.advancedUsalsEntry)
410                                         if Sat.usals.value:
411                                                 self.list.append(getConfigListEntry(_("Longitude"), currLnb.longitude))
412                                                 self.list.append(getConfigListEntry(" ", currLnb.longitudeOrientation))
413                                                 self.list.append(getConfigListEntry(_("Latitude"), currLnb.latitude))
414                                                 self.list.append(getConfigListEntry(" ", currLnb.latitudeOrientation))
415                                         else:
416                                                 self.list.append(getConfigListEntry(_("Stored position"), Sat.rotorposition))
417                                         if not hasattr(self, 'additionalMotorOptions'):
418                                                 self.additionalMotorOptions = ConfigYesNo(False)
419                                         self.showAdditionalMotorOptions = getConfigListEntry(_("Extra motor options"), self.additionalMotorOptions)
420                                         self.list.append(self.showAdditionalMotorOptions)
421                                         if self.additionalMotorOptions.value:
422                                                 self.list.append(getConfigListEntry("   " + _("Horizontal turning speed") + " [" + chr(176) + "/sec]", currLnb.turningspeedH))
423                                                 self.list.append(getConfigListEntry("   " + _("Vertical turning speed") + " [" + chr(176) + "/sec]", currLnb.turningspeedV))
424                                                 self.list.append(getConfigListEntry("   " + _("Turning step size") + " [" + chr(176) + "]", currLnb.tuningstepsize))
425                                                 self.list.append(getConfigListEntry("   " + _("Max memory positions"), currLnb.rotorPositions))
426
427         def fillAdvancedList(self):
428                 self.list = [ ]
429                 self.configMode = getConfigListEntry(_("Configuration mode"), self.nimConfig.configMode)
430                 self.list.append(self.configMode)
431                 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
432                 self.list.append(self.advancedSatsEntry)
433                 for x in self.nimConfig.advanced.sat.keys():
434                         Sat = self.nimConfig.advanced.sat[x]
435                         self.fillListWithAdvancedSatEntrys(Sat)
436                 self["config"].list = self.list
437
438         def keyOk(self):
439                 if self["config"].getCurrent() == self.advancedSelectSatsEntry:
440                         conf = self.nimConfig.advanced.sat[int(self.nimConfig.advanced.sats.value)].userSatellitesList
441                         self.session.openWithCallback(boundFunction(self.updateConfUserSatellitesList, conf), SelectSatsEntryScreen, userSatlist=conf.value)
442                 elif self["config"].getCurrent() == self.selectSatsEntry:
443                         conf = self.nimConfig.userSatellitesList
444                         self.session.openWithCallback(boundFunction(self.updateConfUserSatellitesList, conf), SelectSatsEntryScreen, userSatlist=conf.value)
445                 else:
446                         self.keySave()
447
448         def updateConfUserSatellitesList(self, conf, val=None):
449                 if val is not None:
450                         conf.value = val
451                         conf.save()
452
453         def keySave(self):
454                 old_configured_sats = nimmanager.getConfiguredSats()
455                 if not self.run():
456                         return
457                 new_configured_sats = nimmanager.getConfiguredSats()
458                 self.unconfed_sats = old_configured_sats - new_configured_sats
459                 self.satpos_to_remove = None
460                 self.deleteConfirmed((None, "no"))
461
462         def deleteConfirmed(self, confirmed):
463                 if confirmed is None:
464                         confirmed = (None, "no")
465
466                 if confirmed[1] == "yes" or confirmed[1] == "yestoall":
467                         eDVBDB.getInstance().removeServices(-1, -1, -1, self.satpos_to_remove)
468
469                 if self.satpos_to_remove is not None:
470                         self.unconfed_sats.remove(self.satpos_to_remove)
471
472                 self.satpos_to_remove = None
473                 for orbpos in self.unconfed_sats:
474                         self.satpos_to_remove = orbpos
475                         orbpos = self.satpos_to_remove
476                         try:
477                                 # why we need this cast?
478                                 sat_name = str(nimmanager.getSatDescription(orbpos))
479                         except:
480                                 if orbpos > 1800: # west
481                                         orbpos = 3600 - orbpos
482                                         h = _("W")
483                                 else:
484                                         h = _("E")
485                                 sat_name = ("%d.%d" + h) % (orbpos / 10, orbpos % 10)
486
487                         if confirmed[1] == "yes" or confirmed[1] == "no":
488                                 # TRANSLATORS: The satellite with name '%s' is no longer used after a configuration change. The user is asked whether or not the satellite should be deleted.
489                                 self.session.openWithCallback(self.deleteConfirmed, ChoiceBox, _("%s is no longer used. Should it be deleted?") % sat_name, [(_("Yes"), "yes"), (_("No"), "no"), (_("Yes to all"), "yestoall"), (_("No to all"), "notoall")], None, 1)
490                         if confirmed[1] == "yestoall" or confirmed[1] == "notoall":
491                                 self.deleteConfirmed(confirmed)
492                         break
493                 else:
494                         self.restoreService(_("Zap back to service before tuner setup?"))
495
496         def __init__(self, session, slotid):
497                 Screen.__init__(self, session)
498                 self.list = [ ]
499                 ServiceStopScreen.__init__(self)
500                 self.stopService()
501                 ConfigListScreen.__init__(self, self.list)
502
503                 self["key_red"] = Label(_("Cancel"))
504                 self["key_green"] = Label(_("Save"))
505                 self["key_yellow"] = Label(_("Configuration mode"))
506                 self["key_blue"] = Label()
507                 self["actions"] = ActionMap(["SetupActions", "SatlistShortcutAction"],
508                 {
509                         "ok": self.keyOk,
510                         "save": self.keySave,
511                         "cancel": self.keyCancel,
512                         "changetype": self.changeConfigurationMode,
513                         "nothingconnected": self.nothingConnectedShortcut
514                 }, -2)
515
516                 self.slotid = slotid
517                 self.nim = nimmanager.nim_slots[slotid]
518                 self.nimConfig = self.nim.config
519                 self.createConfigMode()
520                 self.createSetup()
521                 self.onLayoutFinish.append(self.layoutFinished)
522
523         def layoutFinished(self):
524                 self.setTitle(_("Reception Settings"))
525
526         def keyLeft(self):
527                 ConfigListScreen.keyLeft(self)
528                 if self["config"].getCurrent() in (self.advancedSelectSatsEntry, self.selectSatsEntry):
529                         self.keyOk()
530                 else:
531                         self.newConfig()
532
533         def setTextKeyBlue(self):
534                 self["key_blue"].setText("")
535                 if self["config"].isChanged():
536                         self["key_blue"].setText(_("Set default"))
537
538         def keyRight(self):
539                 ConfigListScreen.keyRight(self)
540                 if self["config"].getCurrent() in (self.advancedSelectSatsEntry, self.selectSatsEntry):
541                         self.keyOk()
542                 else:
543                         self.newConfig()
544
545         def handleKeyFileCallback(self, answer):
546                 ConfigListScreen.handleKeyFileCallback(self, answer)
547                 self.newConfig()
548
549         def keyCancel(self):
550                 if self["config"].isChanged():
551                         self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
552                 else:
553                         self.restoreService(_("Zap back to service before tuner setup?"))
554
555         def saveAll(self):
556                 if self.nim.isCompatible("DVB-S"):
557                         # reset connectedTo to all choices to properly store the default value
558                         choices = []
559                         nimlist = nimmanager.getNimListOfType("DVB-S", self.slotid)
560                         for id in nimlist:
561                                 choices.append((str(id), nimmanager.getNimDescription(id)))
562                         self.nimConfig.connectedTo.setChoices(choices)
563                         # sanity check for empty sat list
564                         if self.nimConfig.configMode.value != "satposdepends" and len(nimmanager.getSatListForNim(self.slotid)) < 1:
565                                 self.nimConfig.configMode.value = "nothing"
566                 if self["config"].isChanged():
567                         for x in self["config"].list:
568                                 x[1].save()
569                         configfile.save()
570
571         def cancelConfirm(self, result):
572                 if not result:
573                         return
574                 for x in self["config"].list:
575                         x[1].cancel()
576                 # we need to call saveAll to reset the connectedTo choices
577                 self.saveAll()
578                 self.restoreService(_("Zap back to service before tuner setup?"))
579
580         def changeConfigurationMode(self):
581                 if self.configMode:
582                         self.nimConfig.configMode.selectNext()
583                         self["config"].invalidate(self.configMode)
584                         self.setTextKeyBlue()
585                         self.createSetup()
586
587         def nothingConnectedShortcut(self):
588                 if self["config"].isChanged():
589                         for x in self["config"].list:
590                                 x[1].cancel()
591                         self.setTextKeyBlue()
592                         self.createSetup()
593
594 class NimSelection(Screen):
595         def __init__(self, session):
596                 Screen.__init__(self, session)
597
598                 self.list = [None] * nimmanager.getSlotCount()
599                 self["nimlist"] = List(self.list)
600                 self.updateList()
601
602                 self.setResultClass()
603
604                 self["actions"] = ActionMap(["OkCancelActions", "MenuActions"],
605                 {
606                         "ok": self.okbuttonClick,
607                         "cancel": self.close,
608                         "menu": self.exit,
609                 }, -2)
610                 self.setTitle(_("Choose Tuner"))
611
612         def exit(self):
613                 self.close(True)
614
615         def setResultClass(self):
616                 self.resultclass = NimSetup
617
618         def okbuttonClick(self):
619                 nim = self["nimlist"].getCurrent()
620                 nim = nim and nim[3]
621                 if nim is not None and not nim.empty and nim.isSupported():
622                         self.session.openWithCallback(boundFunction(self.updateList, self["nimlist"].getIndex()), self.resultclass, nim.slot)
623
624         def showNim(self, nim):
625                 return True
626
627         def updateList(self, index=None):
628                 self.list = [ ]
629                 for x in nimmanager.nim_slots:
630                         slotid = x.slot
631                         nimConfig = nimmanager.getNimConfig(x.slot)
632                         text = nimConfig.configMode.value
633                         if self.showNim(x):
634                                 if x.isCompatible("DVB-S"):
635                                         if nimConfig.configMode.value in ("loopthrough", "equal", "satposdepends"):
636                                                 text = { "loopthrough": _("Loop through to"),
637                                                                  "equal": _("Equal to"),
638                                                                  "satposdepends": _("Second cable of motorized LNB") } [nimConfig.configMode.value]
639                                                 text += " " + nimmanager.getNim(int(nimConfig.connectedTo.value)).slot_name
640                                         elif nimConfig.configMode.value == "nothing":
641                                                 text = _("not configured")
642                                         elif nimConfig.configMode.value == "simple":
643                                                 if nimConfig.diseqcMode.value in ("single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"):
644                                                         text = {"single": _("Single"), "toneburst_a_b": _("Toneburst A/B"), "diseqc_a_b": _("DiSEqC A/B"), "diseqc_a_b_c_d": _("DiSEqC A/B/C/D")}[nimConfig.diseqcMode.value] + "\n"
645                                                         text += _("Sats") + ": "
646                                                         satnames = []
647                                                         if nimConfig.diseqcA.orbital_position < 3600:
648                                                                 satnames.append(nimmanager.getSatName(int(nimConfig.diseqcA.value)))
649                                                         if nimConfig.diseqcMode.value in ("toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"):
650                                                                 if nimConfig.diseqcB.orbital_position < 3600:
651                                                                         satnames.append(nimmanager.getSatName(int(nimConfig.diseqcB.value)))
652                                                         if nimConfig.diseqcMode.value == "diseqc_a_b_c_d":
653                                                                 if nimConfig.diseqcC.orbital_position < 3600:
654                                                                         satnames.append(nimmanager.getSatName(int(nimConfig.diseqcC.value)))
655                                                                 if nimConfig.diseqcD.orbital_position < 3600:
656                                                                         satnames.append(nimmanager.getSatName(int(nimConfig.diseqcD.value)))
657                                                         if len(satnames) <= 2:
658                                                                 text += ", ".join(satnames)
659                                                         elif len(satnames) > 2:
660                                                                 # we need a newline here, since multi content lists don't support automtic line wrapping
661                                                                 text += ", ".join(satnames[:2]) + ",\n"
662                                                                 text += "         " + ", ".join(satnames[2:])
663                                                 elif nimConfig.diseqcMode.value in ("positioner", "positioner_select"):
664                                                         text = {"positioner": _("Positioner"), "positioner_select": _("Positioner (selecting satellites)")}[nimConfig.diseqcMode.value]
665                                                         text += ":"
666                                                         if nimConfig.positionerMode.value == "usals":
667                                                                 text += "USALS"
668                                                         elif nimConfig.positionerMode.value == "manual":
669                                                                 text += _("Manual")
670                                                 else:
671                                                         text = _("Simple")
672                                         elif nimConfig.configMode.value == "advanced":
673                                                 text = _("Advanced")
674                                 elif x.isCompatible("DVB-T") or x.isCompatible("DVB-C"):
675                                         if nimConfig.configMode.value == "nothing":
676                                                 text = _("Nothing connected")
677                                         elif nimConfig.configMode.value == "enabled":
678                                                 text = _("Enabled")
679                                 if x.isMultiType():
680                                         text = _("Switchable tuner types:") + "(" + ','.join(x.getMultiTypeList().values()) + ")" + "\n" + text
681                                 if not x.isSupported():
682                                         text = _("Tuner is not supported")
683
684                                 self.list.append((slotid, x.friendly_full_description, text, x))
685                 self["nimlist"].setList(self.list)
686                 self["nimlist"].updateList(self.list)
687                 if index is not None:
688                         self["nimlist"].setIndex(index)
689
690 class SelectSatsEntryScreen(Screen):
691         skin = """
692                 <screen name="SelectSatsEntryScreen" position="center,center" size="560,410" title="Select Sats Entry" >
693                         <ePixmap name="red" position="0,0"   zPosition="2" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
694                         <ePixmap name="green" position="140,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
695                         <ePixmap name="yellow" position="280,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
696                         <ePixmap name="blue" position="420,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
697                         <widget name="key_red" position="0,0" size="140,40" valign="center" halign="center" zPosition="4"  foregroundColor="white" font="Regular;17" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
698                         <widget name="key_green" position="140,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;17" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
699                         <widget name="key_yellow" position="280,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;17" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
700                         <widget name="key_blue" position="420,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;17" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
701                         <widget name="list" position="10,40" size="540,330" scrollbarMode="showNever" />
702                         <ePixmap pixmap="skin_default/div-h.png" position="0,375" zPosition="1" size="540,2" transparent="1" alphatest="on" />
703                         <widget name="hint" position="10,380" size="540,25" font="Regular;19" halign="center" transparent="1" />
704                 </screen>"""
705         def __init__(self, session, userSatlist=""):
706                 Screen.__init__(self, session)
707                 self["key_red"] = Button(_("Cancel"))
708                 self["key_green"] = Button(_("Save"))
709                 self["key_yellow"] = Button(_("Sort by"))
710                 self["key_blue"] = Button(_("Select all"))
711                 self["hint"] = Label(_("Press OK to toggle the selection"))
712                 SatList = []
713                 if not isinstance(userSatlist, str):
714                         userSatlist = ""
715                 else:
716                         userSatlist = userSatlist.replace("]", "").replace("[", "")
717                 for sat in nimmanager.getSatList():
718                         selected = False
719                         sat_str = str(sat[0])
720                         if userSatlist and ("," not in userSatlist and sat_str == userSatlist) or ((', ' + sat_str + ',' in userSatlist) or (userSatlist.startswith(sat_str + ',')) or (userSatlist.endswith(', ' + sat_str))):
721                                 selected = True
722                         SatList.append((sat[0], sat[1], sat[2], selected))
723                 sat_list = [SelectionEntryComponent(x[1], x[0], x[2], x[3]) for x in SatList]
724                 self["list"] = SelectionList(sat_list, enableWrapAround=True)
725                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
726                 {
727                         "red": self.cancel,
728                         "green": self.save,
729                         "yellow": self.sortBy,
730                         "blue": self["list"].toggleAllSelection,
731                         "save": self.save,
732                         "cancel": self.cancel,
733                         "ok": self["list"].toggleSelection,
734                 }, -2)
735                 self.setTitle(_("Select satellites"))
736
737         def save(self):
738                 val = [x[0][1] for x in self["list"].list if x[0][3]]
739                 self.close(str(val))
740
741         def cancel(self):
742                 self.close(None)
743
744         def sortBy(self):
745                 lst = self["list"].list
746                 if len(lst) > 1:
747                         menu = [(_("Reverse list"), "2"), (_("Standart list"), "1")]
748                         connected_sat = [x[0][1] for x in lst if x[0][3]]
749                         if len(connected_sat) > 0:
750                                 menu.insert(0,(_("Connected satellites"), "3"))
751                         def sortAction(choice):
752                                 if choice:
753                                         reverse_flag = False
754                                         sort_type = int(choice[1])
755                                         if choice[1] == "2":
756                                                 sort_type = reverse_flag = 1
757                                         elif choice[1] == "3":
758                                                 reverse_flag = not reverse_flag
759                                         self["list"].sort(sortType=sort_type, flag=reverse_flag)
760                                         self["list"].moveToIndex(0)
761                         self.session.openWithCallback(sortAction, ChoiceBox, title= _("Select sort method:"), list=menu)