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.config import getConfigListEntry, config, ConfigNothing, ConfigSelection, updateConfigElement
9 from Components.Sources.List import List
10 from Screens.MessageBox import MessageBox
12 from time import mktime, localtime
13 from datetime import datetime
15 class NimSetup(Screen, ConfigListScreen):
16 def createSimpleSetup(self, list, mode):
18 list.append(getConfigListEntry(_("Satellite"), self.nimConfig.diseqcA))
20 list.append(getConfigListEntry(_("Port A"), self.nimConfig.diseqcA))
22 if mode in ["toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
23 list.append(getConfigListEntry(_("Port B"), self.nimConfig.diseqcB))
24 if mode == "diseqc_a_b_c_d":
25 list.append(getConfigListEntry(_("Port C"), self.nimConfig.diseqcC))
26 list.append(getConfigListEntry(_("Port D"), self.nimConfig.diseqcD))
28 def createPositionerSetup(self, list):
30 list.append(getConfigListEntry(_("Longitude"), nim.longitude))
31 list.append(getConfigListEntry(" ", nim.longitudeOrientation))
32 list.append(getConfigListEntry(_("Latitude"), nim.latitude))
33 list.append(getConfigListEntry(" ", nim.latitudeOrientation))
34 if SystemInfo["CanMeasureFrontendInputPower"]:
35 self.advancedPowerMeasurement = getConfigListEntry(_("Use Power Measurement"), nim.powerMeasurement)
36 list.append(self.advancedPowerMeasurement)
37 if nim.powerMeasurement.value:
38 list.append(getConfigListEntry(_("Power threshold in mA"), nim.powerThreshold))
39 self.turningSpeed = getConfigListEntry(_("Rotor turning speed"), nim.turningSpeed)
40 list.append(self.turningSpeed)
41 if nim.turningSpeed.value == "fast epoch":
42 self.turnFastEpochBegin = getConfigListEntry(_("Begin time"), nim.fastTurningBegin)
43 self.turnFastEpochEnd = getConfigListEntry(_("End time"), nim.fastTurningEnd)
44 list.append(self.turnFastEpochBegin)
45 list.append(self.turnFastEpochEnd)
47 if nim.powerMeasurement.value:
48 nim.powerMeasurement.value = False
49 nim.powerMeasurement.save()
51 def createConfigMode(self):
52 if self.nim.isCompatible("DVB-S"):
53 choices = { "nothing": _("nothing connected"),
54 "simple": _("simple"),
55 "advanced": _("advanced")}
56 #if len(nimmanager.getNimListOfType(nimmanager.getNimType(self.slotid), exception = x)) > 0:
57 # choices["equal"] = _("equal to")
58 # choices["satposdepends"] = _("second cable of motorized LNB")
59 if len(nimmanager.canEqualTo(self.slotid)) > 0:
60 choices["equal"] = _("equal to")
61 if len(nimmanager.canDependOn(self.slotid)) > 0:
62 choices["satposdepends"] = _("second cable of motorized LNB")
63 if len(nimmanager.canConnectTo(self.slotid)) > 0:
64 choices["loopthrough"] = _("loopthrough to")
65 self.nimConfig.configMode.setChoices(choices)
67 def createSetup(self):
68 print "Creating setup"
71 self.configMode = None
72 self.diseqcModeEntry = None
73 self.advancedSatsEntry = None
74 self.advancedLnbsEntry = None
75 self.advancedDiseqcMode = None
76 self.advancedUsalsEntry = None
77 self.advancedLof = None
78 self.advancedPowerMeasurement = None
79 self.turningSpeed = None
80 self.turnFastEpochBegin = None
81 self.turnFastEpochEnd = None
82 self.uncommittedDiseqcCommand = None
83 self.cableScanType = None
84 self.have_advanced = False
86 if self.nim.isCompatible("DVB-S"):
87 self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
88 self.list.append(self.configMode)
90 if self.nimConfig.configMode.value == "simple": #simple setup
91 self.diseqcModeEntry = getConfigListEntry(_("DiSEqC Mode"), self.nimConfig.diseqcMode)
92 self.list.append(self.diseqcModeEntry)
93 if self.nimConfig.diseqcMode.value in ["single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
94 self.createSimpleSetup(self.list, self.nimConfig.diseqcMode.value)
95 if self.nimConfig.diseqcMode.value == "positioner":
96 self.createPositionerSetup(self.list)
97 elif self.nimConfig.configMode.value == "equal":
99 nimlist = nimmanager.canEqualTo(self.nim.slot)
101 #choices.append((str(id), str(chr(65 + id))))
102 choices.append((str(id), nimmanager.getNimDescription(id)))
103 self.nimConfig.connectedTo.setChoices(choices)
104 #self.nimConfig.connectedTo = updateConfigElement(self.nimConfig.connectedTo, ConfigSelection(choices = choices))
105 self.list.append(getConfigListEntry(_("Tuner"), self.nimConfig.connectedTo))
106 elif self.nimConfig.configMode.value == "satposdepends":
108 nimlist = nimmanager.canDependOn(self.nim.slot)
110 #choices.append((str(id), str(chr(65 + id))))
111 choices.append((str(id), nimmanager.getNimDescription(id)))
112 self.nimConfig.connectedTo.setChoices(choices)
113 #self.nimConfig.connectedTo = updateConfigElement(self.nimConfig.connectedTo, ConfigSelection(choices = choices))
114 self.list.append(getConfigListEntry(_("Tuner"), self.nimConfig.connectedTo))
115 elif self.nimConfig.configMode.value == "loopthrough":
117 print "connectable to:", nimmanager.canConnectTo(self.slotid)
118 connectable = nimmanager.canConnectTo(self.slotid)
119 for id in connectable:
120 choices.append((str(id), nimmanager.getNimDescription(id)))
121 self.nimConfig.connectedTo.setChoices(choices)
122 #self.nimConfig.connectedTo = updateConfigElement(self.nimConfig.connectedTo, ConfigSelection(choices = choices))
123 self.list.append(getConfigListEntry(_("Connected to"), self.nimConfig.connectedTo))
124 elif self.nimConfig.configMode.value == "nothing":
126 elif self.nimConfig.configMode.value == "advanced": # advanced
128 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
129 self.list.append(self.advancedSatsEntry)
130 cur_orb_pos = self.nimConfig.advanced.sats.orbital_position
131 satlist = self.nimConfig.advanced.sat.keys()
132 if cur_orb_pos is not None:
133 if cur_orb_pos not in satlist:
134 cur_orb_pos = satlist[0]
135 currSat = self.nimConfig.advanced.sat[cur_orb_pos]
136 self.fillListWithAdvancedSatEntrys(currSat)
137 self.have_advanced = True
138 elif self.nim.isCompatible("DVB-C"):
139 self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
140 self.list.append(self.configMode)
141 if self.nimConfig.configMode.value == "enabled":
142 self.cableScanType=getConfigListEntry(_("Used service scan type"), self.nimConfig.cable.scan_type)
143 self.list.append(self.cableScanType)
144 if self.nimConfig.cable.scan_type.value == "provider":
145 self.list.append(getConfigListEntry(_("Provider to scan"), self.nimConfig.cable.scan_provider))
147 if self.nimConfig.cable.scan_type.value == "bands":
148 self.list.append(getConfigListEntry(_("Scan band EU VHF I"), self.nimConfig.cable.scan_band_EU_VHF_I))
149 self.list.append(getConfigListEntry(_("Scan band EU MID"), self.nimConfig.cable.scan_band_EU_MID))
150 self.list.append(getConfigListEntry(_("Scan band EU VHF III"), self.nimConfig.cable.scan_band_EU_VHF_III))
151 self.list.append(getConfigListEntry(_("Scan band EU UHF IV"), self.nimConfig.cable.scan_band_EU_UHF_IV))
152 self.list.append(getConfigListEntry(_("Scan band EU UHF V"), self.nimConfig.cable.scan_band_EU_UHF_V))
153 self.list.append(getConfigListEntry(_("Scan band EU SUPER"), self.nimConfig.cable.scan_band_EU_SUPER))
154 self.list.append(getConfigListEntry(_("Scan band EU HYPER"), self.nimConfig.cable.scan_band_EU_HYPER))
155 self.list.append(getConfigListEntry(_("Scan band US LOW"), self.nimConfig.cable.scan_band_US_LOW))
156 self.list.append(getConfigListEntry(_("Scan band US MID"), self.nimConfig.cable.scan_band_US_MID))
157 self.list.append(getConfigListEntry(_("Scan band US HIGH"), self.nimConfig.cable.scan_band_US_HIGH))
158 self.list.append(getConfigListEntry(_("Scan band US SUPER"), self.nimConfig.cable.scan_band_US_SUPER))
159 self.list.append(getConfigListEntry(_("Scan band US HYPER"), self.nimConfig.cable.scan_band_US_HYPER))
160 elif self.nimConfig.cable.scan_type.value == "steps":
161 self.list.append(getConfigListEntry(_("Frequency scan step size(khz)"), self.nimConfig.cable.scan_frequency_steps))
162 self.list.append(getConfigListEntry(_("Scan QAM16"), self.nimConfig.cable.scan_mod_qam16))
163 self.list.append(getConfigListEntry(_("Scan QAM32"), self.nimConfig.cable.scan_mod_qam32))
164 self.list.append(getConfigListEntry(_("Scan QAM64"), self.nimConfig.cable.scan_mod_qam64))
165 self.list.append(getConfigListEntry(_("Scan QAM128"), self.nimConfig.cable.scan_mod_qam128))
166 self.list.append(getConfigListEntry(_("Scan QAM256"), self.nimConfig.cable.scan_mod_qam256))
167 self.list.append(getConfigListEntry(_("Scan SR6900"), self.nimConfig.cable.scan_sr_6900))
168 self.list.append(getConfigListEntry(_("Scan SR6875"), self.nimConfig.cable.scan_sr_6875))
169 self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext1))
170 self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext2))
171 self.have_advanced = False
172 elif self.nim.isCompatible("DVB-T"):
173 self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
174 self.list.append(self.configMode)
175 self.have_advanced = False
176 if self.nimConfig.configMode.value == "enabled":
177 self.list.append(getConfigListEntry(_("Terrestrial provider"), self.nimConfig.terrestrial))
178 self.list.append(getConfigListEntry(_("Enable 5V for active antenna"), self.nimConfig.terrestrial_5V))
180 self.have_advanced = False
181 self["config"].list = self.list
182 self["config"].l.setList(self.list)
185 checkList = (self.configMode, self.diseqcModeEntry, self.advancedSatsEntry, \
186 self.advancedLnbsEntry, self.advancedDiseqcMode, self.advancedUsalsEntry, \
187 self.advancedLof, self.advancedPowerMeasurement, self.turningSpeed, \
188 self.uncommittedDiseqcCommand, self.cableScanType)
190 if self["config"].getCurrent() == x:
194 if self.have_advanced and self.nim.config_mode == "advanced":
195 self.fillAdvancedList()
197 if x in [self.turnFastEpochBegin, self.turnFastEpochEnd]:
198 # workaround for storing only hour*3600+min*60 value in configfile
199 # not really needed.. just for cosmetics..
200 tm = localtime(x[1].value)
201 dt = datetime(1970, 1, 1, tm.tm_hour, tm.tm_min)
202 x[1].value = int(mktime(dt.timetuple()))
204 nimmanager.sec.update()
207 def fillListWithAdvancedSatEntrys(self, Sat):
208 currLnb = self.nimConfig.advanced.lnb[int(Sat.lnb.value)]
210 if isinstance(currLnb, ConfigNothing):
213 self.list.append(getConfigListEntry(_("Voltage mode"), Sat.voltage))
214 self.list.append(getConfigListEntry(_("Tone mode"), Sat.tonemode))
215 if currLnb and currLnb.diseqcMode.value == "1_2":
216 self.advancedUsalsEntry = getConfigListEntry(_("Use usals for this sat"), Sat.usals)
217 self.list.append(self.advancedUsalsEntry)
218 if not Sat.usals.value:
219 self.list.append(getConfigListEntry(_("Stored position"), Sat.rotorposition))
222 self.advancedLnbsEntry = getConfigListEntry(_("LNB"), Sat.lnb)
223 self.list.append(self.advancedLnbsEntry)
225 self.advancedDiseqcMode = getConfigListEntry(_("DiSEqC mode"), currLnb.diseqcMode)
226 self.list.append(self.advancedDiseqcMode)
227 if currLnb.diseqcMode.value != "none":
228 self.list.append(getConfigListEntry(_("Toneburst"), currLnb.toneburst))
229 self.list.append(getConfigListEntry(_("Committed DiSEqC command"), currLnb.commitedDiseqcCommand))
230 self.list.append(getConfigListEntry(_("Fast DiSEqC"), currLnb.fastDiseqc))
231 self.list.append(getConfigListEntry(_("Sequence repeat"), currLnb.sequenceRepeat))
232 if currLnb.diseqcMode.value == "1_0":
233 self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder1_0))
235 if currLnb.uncommittedDiseqcCommand.index:
236 if currLnb.commandOrder.value == "ct":
237 currLnb.commandOrder.value = "cut"
238 elif currLnb.commandOrder.value == "tc":
239 currLnb.commandOrder.value = "tcu"
241 if currLnb.commandOrder.index & 1:
242 currLnb.commandOrder.value = "tc"
244 currLnb.commandOrder.value = "ct"
245 self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder))
246 self.uncommittedDiseqcCommand = getConfigListEntry(_("Uncommitted DiSEqC command"), currLnb.uncommittedDiseqcCommand)
247 self.list.append(self.uncommittedDiseqcCommand)
248 self.list.append(getConfigListEntry(_("DiSEqC repeats"), currLnb.diseqcRepeats))
249 if currLnb.diseqcMode.value == "1_2":
250 self.list.append(getConfigListEntry(_("Longitude"), currLnb.longitude))
251 self.list.append(getConfigListEntry(" ", currLnb.longitudeOrientation))
252 self.list.append(getConfigListEntry(_("Latitude"), currLnb.latitude))
253 self.list.append(getConfigListEntry(" ", currLnb.latitudeOrientation))
254 if SystemInfo["CanMeasureFrontendInputPower"]:
255 self.advancedPowerMeasurement = getConfigListEntry(_("Use Power Measurement"), currLnb.powerMeasurement)
256 self.list.append(self.advancedPowerMeasurement)
257 if currLnb.powerMeasurement.value:
258 self.list.append(getConfigListEntry(_("Power threshold in mA"), currLnb.powerThreshold))
259 self.turningSpeed = getConfigListEntry(_("Rotor turning speed"), currLnb.turningSpeed)
260 self.list.append(self.turningSpeed)
261 if currLnb.turningSpeed.value == "fast epoch":
262 self.turnFastEpochBegin = getConfigListEntry(_("Begin time"), currLnb.fastTurningBegin)
263 self.turnFastEpochEnd = getConfigListEntry(_("End time"), currLnb.fastTurningEnd)
264 self.list.append(self.turnFastEpochBegin)
265 self.list.append(self.turnFastEpochEnd)
267 if currLnb.powerMeasurement.value:
268 currLnb.powerMeasurement.value = False
269 currLnb.powerMeasurement.save()
270 self.advancedLof = getConfigListEntry(_("LOF"), currLnb.lof)
271 self.list.append(self.advancedLof)
272 if currLnb.lof.value == "user_defined":
273 self.list.append(getConfigListEntry(_("LOF/L"), currLnb.lofl))
274 self.list.append(getConfigListEntry(_("LOF/H"), currLnb.lofh))
275 self.list.append(getConfigListEntry(_("Threshold"), currLnb.threshold))
276 # self.list.append(getConfigListEntry(_("12V Output"), currLnb.output_12v))
277 self.list.append(getConfigListEntry(_("Increased voltage"), currLnb.increased_voltage))
279 def fillAdvancedList(self):
281 self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
282 self.list.append(self.configMode)
283 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
284 self.list.append(self.advancedSatsEntry)
285 for x in nimmanager.satList:
286 Sat = self.nimConfig.advanced.sat[x[0]]
287 self.fillListWithAdvancedSatEntrys(Sat)
288 self["config"].list = self.list
291 old_configured_sats = nimmanager.getConfiguredSats()
293 new_configured_sats = nimmanager.getConfiguredSats()
294 self.unconfed_sats = old_configured_sats - new_configured_sats
295 self.satpos_to_remove = None
296 self.deleteConfirmed(False)
298 def deleteConfirmed(self, confirmed):
300 eDVBDB.getInstance().removeServices(-1, -1, -1, self.satpos_to_remove)
302 if self.satpos_to_remove is not None:
303 self.unconfed_sats.remove(self.satpos_to_remove)
305 self.satpos_to_remove = None
306 for orbpos in self.unconfed_sats:
307 self.satpos_to_remove = orbpos
308 orbpos = self.satpos_to_remove
310 # why we need this cast?
311 sat_name = str(nimmanager.getSatDescription(orbpos))
313 if orbpos > 1800: # west
314 orbpos = 3600 - orbpos
318 sat_name = ("%d.%d" + h) % (orbpos / 10, orbpos % 10)
319 self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Delete no more configured satellite\n%s?") %(sat_name))
321 if not self.satpos_to_remove:
324 def __init__(self, session, slotid):
325 Screen.__init__(self, session)
328 ConfigListScreen.__init__(self, self.list)
330 self["actions"] = ActionMap(["SetupActions"],
333 "cancel": self.keyCancel,
337 self.nim = nimmanager.nim_slots[slotid]
338 self.nimConfig = self.nim.config
339 self.createConfigMode()
343 ConfigListScreen.keyLeft(self)
347 ConfigListScreen.keyRight(self)
351 if self.nim.isCompatible("DVB-S"):
352 # reset connectedTo to all choices to properly store the default value
354 nimlist = nimmanager.getNimListOfType("DVB-S", self.slotid)
356 choices.append((str(id), nimmanager.getNimDescription(id)))
357 self.nimConfig.connectedTo.setChoices(choices)
358 for x in self["config"].list:
361 def cancelConfirm(self, result):
365 for x in self["config"].list:
367 # we need to call saveAll to reset the connectedTo choices
371 class NimSelection(Screen):
372 def __init__(self, session):
373 Screen.__init__(self, session)
375 self.list = [None] * nimmanager.getSlotCount()
376 self["nimlist"] = List(self.list)
379 self["actions"] = ActionMap(["OkCancelActions"],
381 "ok": self.okbuttonClick ,
385 def okbuttonClick(self):
386 nim = self["nimlist"].getCurrent()
388 if nim is not None and not nim.empty:
389 self.session.openWithCallback(self.updateList, NimSetup, nim.slot)
391 def updateList(self):
393 for x in nimmanager.nim_slots:
395 nimConfig = nimmanager.getNimConfig(x.slot)
396 text = nimConfig.configMode.value
397 if x.isCompatible("DVB-S"):
398 if nimConfig.configMode.value in ["loopthrough", "equal", "satposdepends"]:
399 text = { "loopthrough": _("loopthrough to"),
400 "equal": _("equal to"),
401 "satposdepends": _("second cable of motorized LNB") } [nimConfig.configMode.value]
402 text += + " " + _("Tuner") + " " + ["A", "B", "C", "D"][int(nimConfig.connectedTo.value)]
403 elif nimConfig.configMode.value == "nothing":
404 text = _("nothing connected")
405 elif nimConfig.configMode.value == "simple":
406 if nimConfig.diseqcMode.value in ["single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
407 text = _("Sats") + ": " + nimmanager.getSatName(int(nimConfig.diseqcA.value))
408 if nimConfig.diseqcMode.value in ["toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
409 text += "," + nimmanager.getSatName(int(nimConfig.diseqcB.value))
410 if nimConfig.diseqcMode.value == "diseqc_a_b_c_d":
411 text += "," + nimmanager.getSatName(int(nimConfig.diseqcC.value))
412 text += "," + nimmanager.getSatName(int(nimConfig.diseqcD.value))
413 elif nimConfig.diseqcMode.value == "positioner":
414 text = _("Positioner") + ":"
415 if nimConfig.positionerMode.value == "usals":
417 elif nimConfig.positionerMode.value == "manual":
421 elif nimConfig.configMode.value == "advanced":
423 elif x.isCompatible("DVB-T") or x.isCompatible("DVB-C"):
424 if nimConfig.configMode.value == "nothing":
425 text = _("nothing connected")
426 elif nimConfig.configMode.value == "enabled":
429 self.list.append((slotid, x.friendly_full_description, text, x))
430 self["nimlist"].updateList(self.list)