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 Screens.MessageBox import MessageBox
11 from time import mktime, localtime
12 from datetime import datetime
14 class NimSetup(Screen, ConfigListScreen):
15 def createSimpleSetup(self, list, mode):
17 list.append(getConfigListEntry(_("Satellite"), self.nimConfig.diseqcA))
19 list.append(getConfigListEntry(_("Port A"), self.nimConfig.diseqcA))
21 if mode in ["toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
22 list.append(getConfigListEntry(_("Port B"), self.nimConfig.diseqcB))
23 if mode == "diseqc_a_b_c_d":
24 list.append(getConfigListEntry(_("Port C"), self.nimConfig.diseqcC))
25 list.append(getConfigListEntry(_("Port D"), self.nimConfig.diseqcD))
27 def createPositionerSetup(self, list):
29 list.append(getConfigListEntry(_("Longitude"), nim.longitude))
30 list.append(getConfigListEntry(" ", nim.longitudeOrientation))
31 list.append(getConfigListEntry(_("Latitude"), nim.latitude))
32 list.append(getConfigListEntry(" ", nim.latitudeOrientation))
33 if SystemInfo["CanMeasureFrontendInputPower"]:
34 self.advancedPowerMeasurement = getConfigListEntry(_("Use Power Measurement"), nim.powerMeasurement)
35 list.append(self.advancedPowerMeasurement)
36 if nim.powerMeasurement.value:
37 list.append(getConfigListEntry(_("Power threshold in mA"), nim.powerThreshold))
38 self.turningSpeed = getConfigListEntry(_("Rotor turning speed"), nim.turningSpeed)
39 list.append(self.turningSpeed)
40 if nim.turningSpeed.value == "fast epoch":
41 self.turnFastEpochBegin = getConfigListEntry(_("Begin time"), nim.fastTurningBegin)
42 self.turnFastEpochEnd = getConfigListEntry(_("End time"), nim.fastTurningEnd)
43 list.append(self.turnFastEpochBegin)
44 list.append(self.turnFastEpochEnd)
46 if nim.powerMeasurement.value:
47 nim.powerMeasurement.value = False
48 nim.powerMeasurement.save()
50 def createConfigMode(self):
51 choices = { "nothing": _("nothing connected"),
52 "simple": _("simple"),
53 "advanced": _("advanced")}
54 #if len(nimmanager.getNimListOfType(nimmanager.getNimType(self.slotid), exception = x)) > 0:
55 # choices["equal"] = _("equal to")
56 # choices["satposdepends"] = _("second cable of motorized LNB")
57 if len(nimmanager.canEqualTo(self.slotid)) > 0:
58 choices["equal"] = _("equal to")
59 if len(nimmanager.canDependOn(self.slotid)) > 0:
60 choices["satposdepends"] = _("second cable of motorized LNB")
61 if len(nimmanager.canConnectTo(self.slotid)) > 0:
62 choices["loopthrough"] = _("loopthrough to")
63 self.nimConfig.configMode = updateConfigElement(self.nimConfig.configMode, ConfigSelection(choices = choices, default = "simple"))
65 def createSetup(self):
66 print "Creating setup"
69 self.configMode = None
70 self.diseqcModeEntry = None
71 self.advancedSatsEntry = None
72 self.advancedLnbsEntry = None
73 self.advancedDiseqcMode = None
74 self.advancedUsalsEntry = None
75 self.advancedLof = None
76 self.advancedPowerMeasurement = None
77 self.turningSpeed = None
78 self.turnFastEpochBegin = None
79 self.turnFastEpochEnd = None
80 self.uncommittedDiseqcCommand = None
81 self.cableScanType = None
82 self.have_advanced = False
84 if self.nim.isCompatible("DVB-S"):
85 self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
86 self.list.append(self.configMode)
88 if self.nimConfig.configMode.value == "simple": #simple setup
89 self.diseqcModeEntry = getConfigListEntry(_("DiSEqC Mode"), self.nimConfig.diseqcMode)
90 self.list.append(self.diseqcModeEntry)
91 if self.nimConfig.diseqcMode.value in ["single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
92 self.createSimpleSetup(self.list, self.nimConfig.diseqcMode.value)
93 if self.nimConfig.diseqcMode.value == "positioner":
94 self.createPositionerSetup(self.list)
95 elif self.nimConfig.configMode.value == "equal":
97 nimlist = nimmanager.canEqualTo(self.nim.slot)
99 #choices.append((str(id), str(chr(65 + id))))
100 choices.append((str(id), nimmanager.getNimDescription(id)))
101 self.nimConfig.connectedTo = updateConfigElement(self.nimConfig.connectedTo, ConfigSelection(choices = choices))
102 self.list.append(getConfigListEntry(_("Tuner"), self.nimConfig.connectedTo))
103 elif self.nimConfig.configMode.value == "satposdepends":
105 nimlist = nimmanager.canDependOn(self.nim.slot)
107 #choices.append((str(id), str(chr(65 + id))))
108 choices.append((str(id), nimmanager.getNimDescription(id)))
109 self.nimConfig.connectedTo = updateConfigElement(self.nimConfig.connectedTo, ConfigSelection(choices = choices))
110 self.list.append(getConfigListEntry(_("Tuner"), self.nimConfig.connectedTo))
111 elif self.nimConfig.configMode.value == "loopthrough":
113 print "connectable to:", nimmanager.canConnectTo(self.slotid)
114 connectable = nimmanager.canConnectTo(self.slotid)
115 for id in connectable:
116 choices.append((str(id), nimmanager.getNimDescription(id)))
117 self.nimConfig.connectedTo = updateConfigElement(self.nimConfig.connectedTo, ConfigSelection(choices = choices))
118 self.list.append(getConfigListEntry(_("Connected to"), self.nimConfig.connectedTo))
119 elif self.nimConfig.configMode.value == "nothing":
121 elif self.nimConfig.configMode.value == "advanced": # advanced
123 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
124 self.list.append(self.advancedSatsEntry)
125 cur_orb_pos = self.nimConfig.advanced.sats.orbital_position
126 satlist = self.nimConfig.advanced.sat.keys()
127 if cur_orb_pos is not None:
128 if cur_orb_pos not in satlist:
129 cur_orb_pos = satlist[0]
130 currSat = self.nimConfig.advanced.sat[cur_orb_pos]
131 self.fillListWithAdvancedSatEntrys(currSat)
132 self.have_advanced = True
133 elif self.nim.isCompatible("DVB-C"):
134 self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
135 self.list.append(self.configMode)
136 if self.nimConfig.configMode.value == "enabled":
137 self.cableScanType=getConfigListEntry(_("Used service scan type"), self.nimConfig.cable.scan_type)
138 self.list.append(self.cableScanType)
139 if self.nimConfig.cable.scan_type.value == "provider":
140 self.list.append(getConfigListEntry(_("Provider to scan"), self.nimConfig.cable.scan_provider))
142 if self.nimConfig.cable.scan_type.value == "bands":
143 self.list.append(getConfigListEntry(_("Scan band EU VHF I"), self.nimConfig.cable.scan_band_EU_VHF_I))
144 self.list.append(getConfigListEntry(_("Scan band EU MID"), self.nimConfig.cable.scan_band_EU_MID))
145 self.list.append(getConfigListEntry(_("Scan band EU VHF III"), self.nimConfig.cable.scan_band_EU_VHF_III))
146 self.list.append(getConfigListEntry(_("Scan band EU UHF IV"), self.nimConfig.cable.scan_band_EU_UHF_IV))
147 self.list.append(getConfigListEntry(_("Scan band EU UHF V"), self.nimConfig.cable.scan_band_EU_UHF_V))
148 self.list.append(getConfigListEntry(_("Scan band EU SUPER"), self.nimConfig.cable.scan_band_EU_SUPER))
149 self.list.append(getConfigListEntry(_("Scan band EU HYPER"), self.nimConfig.cable.scan_band_EU_HYPER))
150 self.list.append(getConfigListEntry(_("Scan band US LOW"), self.nimConfig.cable.scan_band_US_LOW))
151 self.list.append(getConfigListEntry(_("Scan band US MID"), self.nimConfig.cable.scan_band_US_MID))
152 self.list.append(getConfigListEntry(_("Scan band US HIGH"), self.nimConfig.cable.scan_band_US_HIGH))
153 self.list.append(getConfigListEntry(_("Scan band US SUPER"), self.nimConfig.cable.scan_band_US_SUPER))
154 self.list.append(getConfigListEntry(_("Scan band US HYPER"), self.nimConfig.cable.scan_band_US_HYPER))
155 elif self.nimConfig.cable.scan_type.value == "steps":
156 self.list.append(getConfigListEntry(_("Frequency scan step size(khz)"), self.nimConfig.cable.scan_frequency_steps))
157 self.list.append(getConfigListEntry(_("Scan QAM16"), self.nimConfig.cable.scan_mod_qam16))
158 self.list.append(getConfigListEntry(_("Scan QAM32"), self.nimConfig.cable.scan_mod_qam32))
159 self.list.append(getConfigListEntry(_("Scan QAM64"), self.nimConfig.cable.scan_mod_qam64))
160 self.list.append(getConfigListEntry(_("Scan QAM128"), self.nimConfig.cable.scan_mod_qam128))
161 self.list.append(getConfigListEntry(_("Scan QAM256"), self.nimConfig.cable.scan_mod_qam256))
162 self.list.append(getConfigListEntry(_("Scan SR6900"), self.nimConfig.cable.scan_sr_6900))
163 self.list.append(getConfigListEntry(_("Scan SR6875"), self.nimConfig.cable.scan_sr_6875))
164 self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext1))
165 self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext2))
166 self.have_advanced = False
167 elif self.nim.isCompatible("DVB-T"):
168 self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
169 self.list.append(self.configMode)
170 self.have_advanced = False
171 if self.nimConfig.configMode.value == "enabled":
172 self.list.append(getConfigListEntry(_("Terrestrial provider"), self.nimConfig.terrestrial))
173 self.list.append(getConfigListEntry(_("Enable 5V for active antenna"), self.nimConfig.terrestrial_5V))
175 self.have_advanced = False
176 self["config"].list = self.list
177 self["config"].l.setList(self.list)
180 checkList = (self.configMode, self.diseqcModeEntry, self.advancedSatsEntry, \
181 self.advancedLnbsEntry, self.advancedDiseqcMode, self.advancedUsalsEntry, \
182 self.advancedLof, self.advancedPowerMeasurement, self.turningSpeed, \
183 self.uncommittedDiseqcCommand, self.cableScanType)
185 if self["config"].getCurrent() == x:
189 if self.have_advanced and self.nim.config_mode == "advanced":
190 self.fillAdvancedList()
192 if x in [self.turnFastEpochBegin, self.turnFastEpochEnd]:
193 # workaround for storing only hour*3600+min*60 value in configfile
194 # not really needed.. just for cosmetics..
195 tm = localtime(x[1].value)
196 dt = datetime(1970, 1, 1, tm.tm_hour, tm.tm_min)
197 x[1].value = int(mktime(dt.timetuple()))
199 nimmanager.sec.update()
201 def fillListWithAdvancedSatEntrys(self, Sat):
202 currLnb = self.nimConfig.advanced.lnb[int(Sat.lnb.value)]
204 if isinstance(currLnb, ConfigNothing):
207 self.list.append(getConfigListEntry(_("Voltage mode"), Sat.voltage))
208 self.list.append(getConfigListEntry(_("Tone mode"), Sat.tonemode))
209 if currLnb and currLnb.diseqcMode.value == "1_2":
210 self.advancedUsalsEntry = getConfigListEntry(_("Use usals for this sat"), Sat.usals)
211 self.list.append(self.advancedUsalsEntry)
212 if not Sat.usals.value:
213 self.list.append(getConfigListEntry(_("Stored position"), Sat.rotorposition))
216 self.advancedLnbsEntry = getConfigListEntry(_("LNB"), Sat.lnb)
217 self.list.append(self.advancedLnbsEntry)
219 self.advancedDiseqcMode = getConfigListEntry(_("DiSEqC mode"), currLnb.diseqcMode)
220 self.list.append(self.advancedDiseqcMode)
221 if currLnb.diseqcMode.value != "none":
222 self.list.append(getConfigListEntry(_("Toneburst"), currLnb.toneburst))
223 self.list.append(getConfigListEntry(_("Committed DiSEqC command"), currLnb.commitedDiseqcCommand))
224 self.list.append(getConfigListEntry(_("Fast DiSEqC"), currLnb.fastDiseqc))
225 self.list.append(getConfigListEntry(_("Sequence repeat"), currLnb.sequenceRepeat))
226 if currLnb.diseqcMode.value == "1_0":
227 self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder1_0))
229 if currLnb.uncommittedDiseqcCommand.index:
230 if currLnb.commandOrder.value == "ct":
231 currLnb.commandOrder.value = "cut"
232 elif currLnb.commandOrder.value == "tc":
233 currLnb.commandOrder.value = "tcu"
235 if currLnb.commandOrder.index & 1:
236 currLnb.commandOrder.value = "tc"
238 currLnb.commandOrder.value = "ct"
239 self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder))
240 self.uncommittedDiseqcCommand = getConfigListEntry(_("Uncommitted DiSEqC command"), currLnb.uncommittedDiseqcCommand)
241 self.list.append(self.uncommittedDiseqcCommand)
242 self.list.append(getConfigListEntry(_("DiSEqC repeats"), currLnb.diseqcRepeats))
243 if currLnb.diseqcMode.value == "1_2":
244 self.list.append(getConfigListEntry(_("Longitude"), currLnb.longitude))
245 self.list.append(getConfigListEntry(" ", currLnb.longitudeOrientation))
246 self.list.append(getConfigListEntry(_("Latitude"), currLnb.latitude))
247 self.list.append(getConfigListEntry(" ", currLnb.latitudeOrientation))
248 if SystemInfo["CanMeasureFrontendInputPower"]:
249 self.advancedPowerMeasurement = getConfigListEntry(_("Use Power Measurement"), currLnb.powerMeasurement)
250 self.list.append(self.advancedPowerMeasurement)
251 if currLnb.powerMeasurement.value:
252 self.list.append(getConfigListEntry(_("Power threshold in mA"), currLnb.powerThreshold))
253 self.turningSpeed = getConfigListEntry(_("Rotor turning speed"), currLnb.turningSpeed)
254 self.list.append(self.turningSpeed)
255 if currLnb.turningSpeed.value == "fast epoch":
256 self.turnFastEpochBegin = getConfigListEntry(_("Begin time"), currLnb.fastTurningBegin)
257 self.turnFastEpochEnd = getConfigListEntry(_("End time"), currLnb.fastTurningEnd)
258 self.list.append(self.turnFastEpochBegin)
259 self.list.append(self.turnFastEpochEnd)
261 if currLnb.powerMeasurement.value:
262 currLnb.powerMeasurement.value = False
263 currLnb.powerMeasurement.save()
264 self.advancedLof = getConfigListEntry(_("LOF"), currLnb.lof)
265 self.list.append(self.advancedLof)
266 if currLnb.lof.value == "user_defined":
267 self.list.append(getConfigListEntry(_("LOF/L"), currLnb.lofl))
268 self.list.append(getConfigListEntry(_("LOF/H"), currLnb.lofh))
269 self.list.append(getConfigListEntry(_("Threshold"), currLnb.threshold))
270 # self.list.append(getConfigListEntry(_("12V Output"), currLnb.output_12v))
271 self.list.append(getConfigListEntry(_("Increased voltage"), currLnb.increased_voltage))
273 def fillAdvancedList(self):
275 self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
276 self.list.append(self.configMode)
277 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
278 self.list.append(self.advancedSatsEntry)
279 for x in nimmanager.satList:
280 Sat = self.nimConfig.advanced.sat[x[0]]
281 self.fillListWithAdvancedSatEntrys(Sat)
282 self["config"].list = self.list
285 old_configured_sats = nimmanager.getConfiguredSats()
287 new_configured_sats = nimmanager.getConfiguredSats()
288 self.unconfed_sats = old_configured_sats - new_configured_sats
289 self.satpos_to_remove = None
290 self.deleteConfirmed(False)
292 def deleteConfirmed(self, confirmed):
294 eDVBDB.getInstance().removeServices(-1, -1, -1, self.satpos_to_remove)
296 if self.satpos_to_remove is not None:
297 self.unconfed_sats.remove(self.satpos_to_remove)
299 self.satpos_to_remove = None
300 for orbpos in self.unconfed_sats:
301 self.satpos_to_remove = orbpos
302 orbpos = self.satpos_to_remove
304 # why we need this cast?
305 sat_name = str(nimmanager.getSatDescription(orbpos))
307 if orbpos > 1800: # west
308 orbpos = 3600 - orbpos
312 sat_name = ("%d.%d" + h) % (orbpos / 10, orbpos % 10)
313 self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Delete no more configured satellite\n%s?") %(sat_name))
315 if not self.satpos_to_remove:
318 def __init__(self, session, slotid):
319 Screen.__init__(self, session)
322 ConfigListScreen.__init__(self, self.list)
324 self["actions"] = ActionMap(["SetupActions"],
327 "cancel": self.keyCancel,
331 self.nim = nimmanager.nim_slots[slotid]
332 self.nimConfig = self.nim.config
333 self.createConfigMode()
335 # safeAll is needed, so that keyCancel works properly
339 ConfigListScreen.keyLeft(self)
343 ConfigListScreen.keyRight(self)
346 class NimSelection(Screen):
347 def __init__(self, session):
348 Screen.__init__(self, session)
351 for x in nimmanager.nim_slots:
352 menu.append((x.friendly_full_description, x))
354 self["nimlist"] = MenuList(menu)
356 self["actions"] = ActionMap(["OkCancelActions"],
358 "ok": self.okbuttonClick ,
362 def okbuttonClick(self):
363 nim = self["nimlist"].getCurrent()
365 if nim is not None and not nim.empty:
366 self.session.open(NimSetup, nim.slot)