def __init__(self): assert not HdmiCec.instance, "only one HdmiCec instance is allowed!" HdmiCec.instance = self self.wait = eTimer() self.wait.timeout.get().append(self.sendCmd) self.waitKeyEvent = eTimer() self.waitKeyEvent.timeout.get().append(self.sendKeyEvent) self.queueKeyEvent = [] self.repeat = eTimer() self.repeat.timeout.get().append(self.wakeupMessages) self.queue = [] self.delay = eTimer() self.delay.timeout.get().append(self.sendStandbyMessages) self.useStandby = True eHdmiCEC.getInstance().messageReceived.get().append(self.messageReceived) config.misc.standbyCounter.addNotifier(self.onEnterStandby, initial_call = False) config.misc.DeepStandby.addNotifier(self.onEnterDeepStandby, initial_call = False) self.setFixedPhysicalAddress(config.hdmicec.fixed_physical_address.value) self.volumeForwardingEnabled = False self.volumeForwardingDestination = 0 self.wakeup_from_tv = False eActionMap.getInstance().bindAction('', -maxint - 1, self.keyEvent) config.hdmicec.volume_forwarding.addNotifier(self.configVolumeForwarding) config.hdmicec.enabled.addNotifier(self.configVolumeForwarding) if config.hdmicec.enabled.value: if config.hdmicec.report_active_menu.value: if config.hdmicec.report_active_source.value and NavigationInstance.instance and not NavigationInstance.instance.isRestartUI(): self.sendMessage(0, "sourceinactive") self.sendMessage(0, "menuactive") if config.hdmicec.handle_deepstandby_events.value and (not getFPWasTimerWakeup() or (config.usage.startup_to_standby.value == "no" and config.misc.prev_wakeup_time_type.value == 3)): self.onLeaveStandby()
def screensaverTimeout(self): if self.execing and not Screens.Standby.inStandby and not Screens.Standby.inTryQuitMainloop: self.hide() if hasattr(self, "pvrStateDialog"): self.pvrStateDialog.hide() self.screensaver.show() eActionMap.getInstance().bindAction('', -maxint - 1, self.keypressScreenSaver)
def __init__(self, session, list): Screen.__init__(self, session) Rc.__init__(self) self.onSelChanged = [] self["list"] = HelpMenuList(list, self.close, rcPos=self.getRcPositions()) self["longshift_key0"] = Label("") self["longshift_key1"] = Label("") self["actions"] = ActionMap(["WizardActions"], { "ok": self["list"].ok, "back": self.close, }, -1) # Wildcard binding with slightly higher priority than # the wildcard bindings in # InfoBarGenerics.InfoBarUnhandledKey, but with a gap # so that other wildcards can be interposed if needed. self.onClose.append(self.doOnClose) eActionMap.getInstance().bindAction('', maxint - 100, self["list"].handleButton) # Ignore keypress breaks for the keys in the # ListboxActions context. self["listboxFilterActions"] = ActionMap(["ListboxHelpMenuActions"], { "ignore": lambda: 1, }, 1) self["helpActions"] = ActionMap(["HelpActions"], { "displayHelp": self.showHelp, }) self.onLayoutFinish.append(self.doOnLayoutFinish)
def __init__(self): eActionMap.getInstance().bindAction('', -maxint -1, self.DimUpEvent) self.autoDimDownLCDTimer = eTimer() self.autoDimDownLCDTimer.callback.append(self.autoDimDownLCD) self.autoDimUpLCDTimer = eTimer() self.autoDimUpLCDTimer.callback.append(self.autoDimUpLCD) self.currBrightness = self.dimBrightness = self.Brightness = None self.dimDelay = 0 config.misc.standbyCounter.addNotifier(self.standbyCounterChanged, initial_call = False)
def __init__(self, session, text, key1, key2, type): MessageBox.__init__(self, session, text=text, type=type, enable_input=False) self.skinName = "MessageBox" self["actions"] = ActionMap( ["OkCancelActions", "ColorActions"], {"ok": self.cancel, "cancel": self.cancel, key1: self.firstAction, key2: self.secondAction}, -1, ) self.firstKey = False eActionMap.getInstance().bindAction("", 0x7FFFFFFF, self.action)
def autostart(reason, **kwargs): global session if kwargs.has_key("session") and reason == 0: session = kwargs["session"] print "[AutoShutDown] start...." config.misc.standbyCounter.addNotifier(standbyCounterChanged, initial_call = False) ## from InfoBarGenerics.py eActionMap.getInstance().bindAction('', -0x7FFFFFFF, keyPressed) ## shutdownactions.startKeyTimer()
def autostart(reason, **kwargs): global session if kwargs.has_key("session") and reason == 0: if config.hdmicec.enabled.value: session = kwargs["session"] if config.hdmicec.avvolumecontrol.value: ## from InfoBarGenerics.py eActionMap.getInstance().bindAction('', -0x7FFFFFFF, volumekeyPressed) ## eHdmiCEC.getInstance().messageReceived.get().append(messageReceived) eHdmiCEC.getInstance().messageReceivedKey.get().append(messageReceivedKey)
def __init__(self): if config.hdmicec.enabled.value: assert not HdmiCec.instance, "only one HdmiCec instance is allowed!" HdmiCec.instance = self self.wait = eTimer() self.wait.timeout.get().append(self.sendCmd) self.queue = [] self.messages = [] self.handleTimer = eTimer() self.stateTimer = eTimer() self.stateTimer.callback.append(self.stateTimeout) self.repeatTimer = eTimer() self.repeatTimer.callback.append(self.repeatMessages) self.repeatCounter = 0 self.what = '' self.tv_lastrequest = '' self.tv_powerstate = 'unknown' self.tv_skip_messages = False self.activesource = False self.firstrun = True self.standbytime = 0 self.sethdmipreemphasis() self.checkifPowerupWithoutWakingTv() # initially write 'False' to file, see below eHdmiCEC.getInstance().messageReceived.get().append(self.messageReceived) config.misc.standbyCounter.addNotifier(self.onEnterStandby, initial_call = False) config.misc.DeepStandby.addNotifier(self.onEnterDeepStandby, initial_call = False) self.setFixedPhysicalAddress(config.hdmicec.fixed_physical_address.value) self.volumeForwardingEnabled = False self.volumeForwardingDestination = 0 eActionMap.getInstance().bindAction('', -maxint - 1, self.keyEvent) config.hdmicec.volume_forwarding.addNotifier(self.configVolumeForwarding, initial_call = False) config.hdmicec.enabled.addNotifier(self.configVolumeForwarding) #workaround for needless messages after cancel settings self.old_configReportActiveMenu = config.hdmicec.report_active_menu.value self.old_configTVstate = config.hdmicec.check_tv_state.value or (config.hdmicec.tv_standby_notinputactive.value and config.hdmicec.control_tv_standby.value) # config.hdmicec.report_active_menu.addNotifier(self.configReportActiveMenu, initial_call = False) config.hdmicec.check_tv_state.addNotifier(self.configTVstate, initial_call = False) config.hdmicec.tv_standby_notinputactive.addNotifier(self.configTVstate, initial_call = False) config.hdmicec.control_tv_standby.addNotifier(self.configTVstate, initial_call = False) self.checkTVstate('firstrun')
def setBindings(self): actionMap = eActionMap.getInstance() actionMap.unbindNativeKey("ListboxActions", eListbox.moveUp) actionMap.unbindNativeKey("ListboxActions", eListbox.moveDown) actionMap.bindKey("keymap.xml", "generic", KEYIDS["KEY_UP"], 5, "ListboxActions", "pageUp") actionMap.bindKey("keymap.xml", "generic", KEYIDS["KEY_DOWN"], 5, "ListboxActions", "pageDown") self.onClose.append(self.restoreBindings)
def remoteControl(key, type="", rcu=""): # TODO: do something better here if rcu == "standard": remotetype = "dreambox remote control (native)" elif rcu == "advanced": remotetype = "dreambox advanced remote control (native)" elif rcu == "keyboard": remotetype = "dreambox ir keyboard" else: if config.misc.rcused.value == 0: remotetype = "dreambox advanced remote control (native)" else: remotetype = "dreambox remote control (native)" try: from Tools.HardwareInfo import HardwareInfo if HardwareInfo().get_device_model() in ("xp1000", "formuler1", "formuler3", "et9000", "et9200", "hd1100", "hd1200"): remotetype = "dreambox advanced remote control (native)" except: # noqa: E722 print "[OpenWebIf] wrong hw detection" amap = eActionMap.getInstance() if type == "long": amap.keyPressed(remotetype, key, 0) amap.keyPressed(remotetype, key, 3) elif type == "ascii": amap.keyPressed(remotetype, key, 4) else: amap.keyPressed(remotetype, key, 0) amap.keyPressed(remotetype, key, 1) return { "result": True, "message": "RC command '%s' has been issued" % str(key) }
def remoteControl(key, type = "", rcu = ""): # TODO: do something better here if rcu == "standard": remotetype = "dreambox remote control (native)" elif rcu == "advanced": remotetype = "dreambox advanced remote control (native)" elif rcu == "keyboard": remotetype = "dreambox ir keyboard" else: if config.misc.rcused.value == 0: remotetype = "dreambox advanced remote control (native)" else: remotetype = "dreambox remote control (native)" amap = eActionMap.getInstance() if type == "long": amap.keyPressed(remotetype, key, 0) amap.keyPressed(remotetype, key, 3) elif type == "ascii": amap.keyPressed(remotetype, key, 4) else: amap.keyPressed(remotetype, key, 0) amap.keyPressed(remotetype, key, 1) return { "result": True, "message": "RC command '%s' has been issued" % str(key) }
def __init__(self, session): Screen.__init__(self, session) self["actions"] = ActionMap(["OkCancelActions"], { "ok": self._onOk, "cancel": self.close}, - 2) self.highPrioActionSlot = eActionMap.getInstance().bindAction('', -0x7FFFFFFF, self._onKeypress) #highest prio self._pixmap = MyPixmap() self["wallpaper"] = self._pixmap self._setupAnimation() #picload setup size = getDesktop(0).size() width, height = size.width(), size.height() self._picload = ePicLoad() self.__picload_conn = self._picload.PictureData.connect(self._onPixmapReady) self._picload.setPara((width, height, width, height, False, 1, '#ff000000')) self._nextPixmap = None self._timer = eTimer() self.__timer_conn = self._timer.timeout.connect(self._onTimeout) self._inactivityTimer = eTimer() self.__inactivityTimer_conn = self._inactivityTimer.timeout.connect(self._onInactivityTimeout) self._immediateShow = True self._isEnabled = False self._isInitial = True self.onShow.append(self._onShow) self.onClose.append(self._onClose) config.plugins.screensaver.photo.speed.addNotifier(self._setupAnimation, initial_call = False)
def __init__(self, keys = []): self.keyaction = eActionMap.getInstance() self.rcdevicename = iInputDevices.getDeviceName('event0') self.keyTimer = eTimer() self.keyTimer.callback.append(self.cleanKeyList) self.keys = keys self.index = -1
def __init__(self, contexts=[], actions={}, prio=0): self.contexts = contexts self.actions = actions self.prio = prio self.p = eActionMap.getInstance() self.bound = False self.exec_active = False self.enabled = True
def __init__(self, session): self.session = session self.sign = 0 self.updatetime = 10000 self.blink = False self.channelnrdelay = 15 self.begin = int(time()) self.endkeypress = True eActionMap.getInstance().bindAction("", -0x7FFFFFFF, self.keyPressed) self.zaPrik = eTimer() self.zaPrik.timeout.get().append(self.vrime) self.zaPrik.start(1000, 1) self.onClose = [] self.__event_tracker = ServiceEventTracker( screen=self, eventmap={iPlayableService.evUpdatedEventInfo: self.__eventInfoChanged} )
def timeChanged(self, timer): timer.timeChanged() if timer.state == TimerEntry.StateEnded: self.processed_timers.remove(timer) else: try: self.timer_list.remove(timer) except: print "[timer] Failed to remove, not in list" return # give the timer a chance to re-enqueue if timer.state == TimerEntry.StateEnded: timer.state = TimerEntry.StateWaiting elif "PowerTimerEntry" in `timer` and (timer.timerType == 3 or timer.timerType == 4): if timer.state > 0: eActionMap.getInstance().unbindAction('', timer.keyPressed) timer.state = TimerEntry.StateWaiting
def __init__(self, contexts=None, actions=None, prio=0): if not actions: actions = {} if not contexts: contexts = [] self.actions = actions self.contexts = contexts self.prio = prio self.p = eActionMap.getInstance() self.bound = False self.exec_active = False self.enabled = True
def __init__(self): if config.hdmicec.enabled.value: HdmiCec.instance = self self.wait = eTimer() self.wait.timeout.get().append(self.sendCmd) self.queue = [] eHdmiCEC.getInstance().messageReceived.get().append(self.messageReceived) config.misc.standbyCounter.addNotifier(self.onEnterStandby, initial_call=False) config.misc.DeepStandby.addNotifier(self.onEnterDeepStandby, initial_call=False) self.setFixedPhysicalAddress(config.hdmicec.fixed_physical_address.value) self.volumeForwardingEnabled = False self.volumeForwardingDestination = 0 eActionMap.getInstance().bindAction('', -maxint - 1, self.keyEvent) config.hdmicec.volume_forwarding.addNotifier(self.configVolumeForwarding) config.hdmicec.enabled.addNotifier(self.configVolumeForwarding) if config.hdmicec.handle_deepstandby_events.value: if not getFPWasTimerWakeup(): self.wakeupMessages() dummy = self.checkifPowerupWithoutWakingTv()
def getAutoSleepWindow(self): now = time() if self.autosleepwindow == 'yes': if now < self.autosleepbegin and now < self.autosleepend: self.begin = self.autosleepbegin self.end = self.autosleepend elif now > self.autosleepbegin and now > self.autosleepend: while self.autosleepend < now: self.autosleepend += 86400 while self.autosleepbegin + 86400 < self.autosleepend: self.autosleepbegin += 86400 self.begin = self.autosleepbegin self.end = self.autosleepend if not (now > self.autosleepbegin - self.prepare_time - 3 and now < self.autosleepend): eActionMap.getInstance().unbindAction('', self.keyPressed) self.state = 0 self.timeChanged() return False return True
def start(self, session): if self._started: return self.session = session config.misc.standbyCounter.addNotifier(self._onStandby, initial_call = False) self.cec_recvStandby_conn = hdmi_cec.instance.receivedStandby.connect(self.__receivedStandby) self.cec_isNowActive_conn = hdmi_cec.instance.isNowActive.connect(self.__receivedNowActive) self.actionSlot = eActionMap.getInstance().bindAction('', -0x7FFFFFFF, self._onKeyPress) #highest prio self._remoteHandler = CecRemoteHandler() #the handler registeres all cec stuff itself, so no need to do anything else here self._started = True
def __init__(self, session): self.session = session self.sign = 0 self.updatetime = 15000 self.blink = False self.channelnrdelay = config.plugins.SEG.showCHnumber.value self.dvb_service = "" self.begin = int(time()) self.endkeypress = True eActionMap.getInstance().bindAction('', -0x7FFFFFFF, self.keyPressed) self.TimerText = eTimer() self.TimerText.timeout.get().append(self.showclock) self.TimerText.start(1000, True) self.onClose = [ ] self.__event_tracker = ServiceEventTracker(screen=self,eventmap= { iPlayableService.evStart: self.__evStart, })
def __init__(self, contexts=None, actions=None, prio=0): contexts = contexts or [] actions = actions or {} self.contexts = contexts self.actions = actions self.prio = prio self.p = eActionMap.getInstance() self.bound = False self.exec_active = False self.enabled = True
def __init__(self): assert not HdmiCec.instance, "only one HdmiCec instance is allowed!" HdmiCec.instance = self self.wait = eTimer() self.wait.timeout.get().append(self.sendCmd) self.queue = [] eHdmiCEC.getInstance().messageReceived.get().append(self.messageReceived) config.misc.standbyCounter.addNotifier(self.onEnterStandby, initial_call = False) config.misc.DeepStandby.addNotifier(self.onEnterDeepStandby, initial_call = False) self.setFixedPhysicalAddress(config.hdmicec.fixed_physical_address.getValue()) self.volumeForwardingEnabled = False self.volumeForwardingDestination = 0 eActionMap.getInstance().bindAction('', -0x7FFFFFF, self.keyEvent) config.hdmicec.volume_forwarding.addNotifier(self.configVolumeForwarding) config.hdmicec.enabled.addNotifier(self.configVolumeForwarding) if config.hdmicec.handle_deepstandby_events.getValue(): if not getFPWasTimerWakeup(): self.wakeupMessages()
def __init__(self, session, infobar): self.session = session self.infobar = infobar self.msgbox = None self.defaultMode = None if config.plugins.VCS.default.value in range(len(config.plugins.VCS.profiles)) and \ config.plugins.VCS.profiles[config.plugins.VCS.default.value].enabled.value: self.currentMode = x = config.plugins.VCS.default.value while x > 0: x -= 1 if not config.plugins.VCS.profiles[x].enabled.value: self.currentMode -= 1 else: self.currentMode = 0 self.switchMode(0) self.lastKey = None self.hotkeys = { } for x in VcsInfoBarKeys: self.hotkeys[x[0]] = [KEYIDS[key] for key in x[2]] eActionMap.getInstance().bindAction('', -10, self.keyPressed)
def restoreBindings(self): # After setBindings(), both KEY_UP and KEY_LEFT are bound to # pageUp, and KEY_DOWN, KEY_RIGHT are bound to pageDown, # so all four are unbound by the unbindNativeKey()s here # and all must be rebound to their defaults actionMap = eActionMap.getInstance() actionMap.unbindNativeKey("ListboxActions", eListbox.pageUp) actionMap.unbindNativeKey("ListboxActions", eListbox.pageDown) actionMap.bindKey("keymap.xml", "generic", KEYIDS["KEY_UP"], 5, "ListboxActions", "moveUp") actionMap.bindKey("keymap.xml", "generic", KEYIDS["KEY_DOWN"], 5, "ListboxActions", "moveDown") actionMap.bindKey("keymap.xml", "generic", KEYIDS["KEY_LEFT"], 5, "ListboxActions", "pageUp") actionMap.bindKey("keymap.xml", "generic", KEYIDS["KEY_RIGHT"], 5, "ListboxActions", "pageDown")
def _receivedKeyPress(self, sender, code): if not config.cec.receive_remotekeys.value: return mcode = self.KEY_MAP_RECEIVE.get(code, None) Log.i("code mapped: %s => %s" % (code, mcode)) if mcode is not None: am = eActionMap.getInstance() if isinstance(mcode, tuple): for c in mcode: am.keyPressed(self.REMOTE_TYPE_ADVANCED, c, self.FLAG_MAKE) am.keyPressed(self.REMOTE_TYPE_ADVANCED, c, self.FLAG_BREAK) else: am.keyPressed(self.REMOTE_TYPE_ADVANCED, mcode, self.FLAG_MAKE) am.keyPressed(self.REMOTE_TYPE_ADVANCED, mcode, self.FLAG_BREAK)
def __init__(self): assert not HdmiCec.instance, "only one HdmiCec instance is allowed!" HdmiCec.instance = self self.wait = eTimer() self.wait.timeout.get().append(self.sendCmd) self.queue = [] eHdmiCEC.getInstance().messageReceived.get().append(self.messageReceived) config.misc.standbyCounter.addNotifier(self.onEnterStandby, initial_call = False) config.misc.DeepStandby.addNotifier(self.onEnterDeepStandby, initial_call = False) self.setFixedPhysicalAddress(config.hdmicec.fixed_physical_address.value) self.logicaladdress = eHdmiCEC.getInstance().getLogicalAddress() self.volumeForwardingEnabled = False self.volumeForwardingDestination = 0 eActionMap.getInstance().bindAction('', -0x7FFFFFF, self.keyEvent) config.hdmicec.volume_forwarding.addNotifier(self.configVolumeForwarding) config.hdmicec.enabled.addNotifier(self.configVolumeForwarding) if config.hdmicec.handle_deepstandby_events.value and float(open("/proc/uptime", "r").read().split()[0]) < 120: filename = Directories.resolveFilename(Directories.SCOPE_CONFIG, "timers.xml") try: doc = xml.etree.cElementTree.parse(filename) except: doc = None if doc: root = doc.getroot() for timer in root.findall("timer"): begin = int(timer.get("begin")) disabled = long(timer.get("disabled") or "0") justplay = long(timer.get("justplay") or "0") if begin > time() and begin < time() + 360 and not disabled and not justplay: if Standby.inStandby is None: Notifications.AddNotification(Standby.Standby) return self.wakeupMessages()
def __init__(self, session): self.cmd = None self.session = session Source.__init__(self) self.res = ( False, _("Missing or wrong argument" )) self.eam = eActionMap.getInstance() #Advanced remote or standard? if config.misc.rcused.value == 0: self.remotetype = self.TYPE_ADVANCED else: self.remotetype = self.TYPE_STANDARD print "[RemoteControl.__init__] Configured RCU-Type is '%s'" %(self.remotetype)
def menutoggle3d(session, **kwargs): mode = getmode() znorm = getznorm() toggle = config.plugins.OSD3DSetup.toggle.value if toggle is None: toggle = val_sidebyside if mode != toggle: #val_auto val_off or other not expected... setmode(toggle) else: setmode(val_auto) if znorm < 0 or znorm > 100: setznorm(0) #if there is a toggle command in menu it would be nice to hide the menu - simulation of menu key pressing - to replace by direct menu hide command try: eam = eActionMap.getInstance() #press the key with the desired flag eam.keyPressed(TYPE_STANDARD, 139, FLAG_MAKE) #menu #Release the key eam.keyPressed(TYPE_STANDARD, 139, FLAG_BREAK) #menu except Exception, e: print "[OSD3D Setup] toggle3d exception:\n" + str(e)
def activate(self): next_state = self.state + 1 self.log(5, "activating state %d" % next_state) if next_state == self.StatePrepared: if not self.justplay and not self.freespace(): Notifications.AddPopup( text=_("Write error while recording. Disk full?\n%s") % self.name, type=MessageBox.TYPE_ERROR, timeout=5, id="DiskFullMessage") self.failed = True self.next_activation = time() self.end = time() + 5 self.backoff = 0 return True if self.always_zap: if Screens.Standby.inStandby: self.wasInStandby = True eActionMap.getInstance().bindAction( '', -maxint - 1, self.keypress) #set service to zap after standby Screens.Standby.inStandby.prev_running_service = self.service_ref.ref Screens.Standby.inStandby.paused_service = None #wakeup standby Screens.Standby.inStandby.Power() self.log(5, "wakeup and zap to recording service") else: cur_zap_ref = NavigationInstance.instance.getCurrentlyPlayingServiceReference( ) if cur_zap_ref and not cur_zap_ref.getPath( ): # we do not zap away if it is no live service Notifications.AddNotification( MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n" ), type=MessageBox.TYPE_INFO, timeout=20) self.failureCB(True) self.log(5, "zap to recording service") if self.tryPrepare(): self.log(6, "prepare ok, waiting for begin") # create file to "reserve" the filename # because another recording at the same time on another service can try to record the same event # i.e. cable / sat.. then the second recording needs an own extension... when we create the file # here than calculateFilename is happy if not self.justplay: open(self.Filename + ".ts", "w").close() # Give the Trashcan a chance to clean up try: Trashcan.instance.cleanIfIdle() except Exception, e: print "[TIMER] Failed to call Trashcan.instance.cleanIfIdle()" print "[TIMER] Error:", e # fine. it worked, resources are allocated. self.next_activation = self.begin self.backoff = 0 return True self.log(7, "prepare failed") if self.first_try_prepare: self.first_try_prepare = False cur_ref = NavigationInstance.instance.getCurrentlyPlayingServiceReference( ) if cur_ref and not cur_ref.getPath(): if not config.recording.asktozap.getValue(): self.log(8, "asking user to zap away") Notifications.AddNotificationWithCallback( self.failureCB, MessageBox, _("A timer failed to record!\nDisable TV and try again?\n" ), timeout=20) else: # zap without asking self.log(9, "zap without asking") Notifications.AddNotification( MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n" ), type=MessageBox.TYPE_INFO, timeout=20) self.failureCB(True) elif cur_ref: self.log( 8, "currently running service is not a live service.. so stop it makes no sense" ) else: self.log( 8, "currently no service running... so we dont need to stop it" ) return False
class RecordTimerEntry(timer.TimerEntry, object): def __init__(self, serviceref, begin, end, name, description, eit, disabled=False, justplay=False, afterEvent=AFTEREVENT.AUTO, checkOldTimers=False, dirname=None, tags=None, descramble='notset', record_ecm='notset', isAutoTimer=False, always_zap=False): timer.TimerEntry.__init__(self, int(begin), int(end)) if checkOldTimers: if self.begin < time() - 1209600: self.begin = int(time()) if self.end < self.begin: self.end = self.begin assert isinstance(serviceref, ServiceReference) if serviceref and serviceref.isRecordable(): self.service_ref = serviceref else: self.service_ref = ServiceReference(None) self.eit = eit self.dontSave = False self.name = name self.description = description self.disabled = disabled self.timer = None self.__record_service = None self.start_prepare = 0 self.justplay = justplay self.always_zap = always_zap self.afterEvent = afterEvent self.dirname = dirname self.dirnameHadToFallback = False self.autoincrease = False self.autoincreasetime = 3600 * 24 # 1 day self.tags = tags or [] if descramble == 'notset' and record_ecm == 'notset': if config.recording.ecm_data.getValue() == 'descrambled+ecm': self.descramble = True self.record_ecm = True elif config.recording.ecm_data.getValue() == 'scrambled+ecm': self.descramble = False self.record_ecm = True elif config.recording.ecm_data.getValue() == 'normal': self.descramble = True self.record_ecm = False else: self.descramble = descramble self.record_ecm = record_ecm self.isAutoTimer = isAutoTimer self.wasInStandby = False self.log_entries = [] self.resetState() def __repr__(self): if not self.disabled: return "RecordTimerEntry(name=%s, begin=%s, serviceref=%s, justplay=%s, isAutoTimer=%s)" % ( self.name, ctime(self.begin), self.service_ref, self.justplay, self.isAutoTimer) else: return "RecordTimerEntry(name=%s, begin=%s, serviceref=%s, justplay=%s, isAutoTimer=%s, Disabled)" % ( self.name, ctime(self.begin), self.service_ref, self.justplay, self.isAutoTimer) def log(self, code, msg): self.log_entries.append((int(time()), code, msg)) print "[TIMER]", msg def freespace(self): self.MountPath = None if not self.dirname: dirname = findSafeRecordPath(defaultMoviePath()) else: dirname = findSafeRecordPath(self.dirname) if dirname is None: dirname = findSafeRecordPath(defaultMoviePath()) self.dirnameHadToFallback = True if not dirname: return False self.MountPath = dirname mountwriteable = os.access(dirname, os.W_OK) if not mountwriteable: self.log(0, ("Mount '%s' is not writeable." % dirname)) return False s = os.statvfs(dirname) if (s.f_bavail * s.f_bsize) / 1000000 < 1024: self.log(0, "Not enough free space to record") return False else: self.log(0, "Found enough free space to record") return True def calculateFilename(self): service_name = self.service_ref.getServiceName() begin_date = strftime("%Y%m%d %H%M", localtime(self.begin)) # print "begin_date: ", begin_date # print "service_name: ", service_name # print "name:", self.name # print "description: ", self.description # filename = begin_date + " - " + service_name if self.name: if config.recording.filename_composition.getValue() == "short": filename = strftime("%Y%m%d", localtime( self.begin)) + " - " + self.name elif config.recording.filename_composition.getValue() == "long": filename += " - " + self.name + " - " + self.description else: filename += " - " + self.name # standard if config.recording.ascii_filenames.getValue(): filename = ASCIItranslit.legacyEncode(filename) self.Filename = Directories.getRecordingFilename( filename, self.MountPath) self.log(0, "Filename calculated as: '%s'" % self.Filename) return self.Filename def tryPrepare(self): if self.justplay: return True else: if not self.calculateFilename(): self.do_backoff() self.start_prepare = time() + self.backoff return False rec_ref = self.service_ref and self.service_ref.ref if rec_ref and rec_ref.flags & eServiceReference.isGroup: rec_ref = getBestPlayableServiceReference( rec_ref, eServiceReference()) if not rec_ref: self.log( 1, "'get best playable service for group... record' failed" ) return False self.record_service = rec_ref and NavigationInstance.instance.recordService( rec_ref) if not self.record_service: self.log(1, "'record service' failed") return False if self.repeated: epgcache = eEPGCache.getInstance() queryTime = self.begin + (self.end - self.begin) / 2 evt = epgcache.lookupEventTime(rec_ref, queryTime) if evt: self.description = evt.getShortDescription() if self.description == "": self.description = evt.getExtendedDescription() event_id = evt.getEventId() else: event_id = -1 else: event_id = self.eit if event_id is None: event_id = -1 prep_res = self.record_service.prepare( self.Filename + ".ts", self.begin, self.end, event_id, self.name.replace("\n", ""), self.description.replace("\n", ""), ' '.join(self.tags), bool(self.descramble), bool(self.record_ecm)) if prep_res: if prep_res == -255: self.log(4, "failed to write meta information") else: self.log(2, "'prepare' failed: error %d" % prep_res) # we must calc nur start time before stopRecordService call because in Screens/Standby.py TryQuitMainloop tries to get # the next start time in evEnd event handler... self.do_backoff() self.start_prepare = time() + self.backoff NavigationInstance.instance.stopRecordService( self.record_service) self.record_service = None return False return True def do_backoff(self): if self.backoff == 0: self.backoff = 5 else: self.backoff *= 2 if self.backoff > 100: self.backoff = 100 self.log(10, "backoff: retry in %d seconds" % self.backoff) def activate(self): next_state = self.state + 1 self.log(5, "activating state %d" % next_state) if next_state == self.StatePrepared: if not self.justplay and not self.freespace(): Notifications.AddPopup( text=_("Write error while recording. Disk full?\n%s") % self.name, type=MessageBox.TYPE_ERROR, timeout=5, id="DiskFullMessage") self.failed = True self.next_activation = time() self.end = time() + 5 self.backoff = 0 return True if self.always_zap: if Screens.Standby.inStandby: self.wasInStandby = True eActionMap.getInstance().bindAction( '', -maxint - 1, self.keypress) #set service to zap after standby Screens.Standby.inStandby.prev_running_service = self.service_ref.ref Screens.Standby.inStandby.paused_service = None #wakeup standby Screens.Standby.inStandby.Power() self.log(5, "wakeup and zap to recording service") else: cur_zap_ref = NavigationInstance.instance.getCurrentlyPlayingServiceReference( ) if cur_zap_ref and not cur_zap_ref.getPath( ): # we do not zap away if it is no live service Notifications.AddNotification( MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n" ), type=MessageBox.TYPE_INFO, timeout=20) self.failureCB(True) self.log(5, "zap to recording service") if self.tryPrepare(): self.log(6, "prepare ok, waiting for begin") # create file to "reserve" the filename # because another recording at the same time on another service can try to record the same event # i.e. cable / sat.. then the second recording needs an own extension... when we create the file # here than calculateFilename is happy if not self.justplay: open(self.Filename + ".ts", "w").close() # Give the Trashcan a chance to clean up try: Trashcan.instance.cleanIfIdle() except Exception, e: print "[TIMER] Failed to call Trashcan.instance.cleanIfIdle()" print "[TIMER] Error:", e # fine. it worked, resources are allocated. self.next_activation = self.begin self.backoff = 0 return True self.log(7, "prepare failed") if self.first_try_prepare: self.first_try_prepare = False cur_ref = NavigationInstance.instance.getCurrentlyPlayingServiceReference( ) if cur_ref and not cur_ref.getPath(): if not config.recording.asktozap.getValue(): self.log(8, "asking user to zap away") Notifications.AddNotificationWithCallback( self.failureCB, MessageBox, _("A timer failed to record!\nDisable TV and try again?\n" ), timeout=20) else: # zap without asking self.log(9, "zap without asking") Notifications.AddNotification( MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n" ), type=MessageBox.TYPE_INFO, timeout=20) self.failureCB(True) elif cur_ref: self.log( 8, "currently running service is not a live service.. so stop it makes no sense" ) else: self.log( 8, "currently no service running... so we dont need to stop it" ) return False elif next_state == self.StateRunning: global wasRecTimerWakeup if os.path.exists( "/tmp/was_rectimer_wakeup") and not wasRecTimerWakeup: wasRecTimerWakeup = int( open("/tmp/was_rectimer_wakeup", "r").read()) and True or False os.remove("/tmp/was_rectimer_wakeup") self.autostate = Screens.Standby.inStandby # if this timer has been cancelled, just go to "end" state. if self.cancelled: return True if self.failed: return True if self.justplay: if Screens.Standby.inStandby: self.wasInStandby = True eActionMap.getInstance().bindAction( '', -maxint - 1, self.keypress) self.log(11, "wakeup and zap") #set service to zap after standby Screens.Standby.inStandby.prev_running_service = self.service_ref.ref Screens.Standby.inStandby.paused_service = None #wakeup standby Screens.Standby.inStandby.Power() else: self.log(11, "zapping") NavigationInstance.instance.isMovieplayerActive() from Screens.ChannelSelection import ChannelSelection ChannelSelectionInstance = ChannelSelection.instance self.service_types = service_types_tv if ChannelSelectionInstance: if config.usage.multibouquet.getValue(): bqrootstr = '1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "bouquets.tv" ORDER BY bouquet' else: bqrootstr = '%s FROM BOUQUET "userbouquet.favourites.tv" ORDER BY bouquet' % self.service_types rootstr = '' serviceHandler = eServiceCenter.getInstance() rootbouquet = eServiceReference(bqrootstr) bouquet = eServiceReference(bqrootstr) bouquetlist = serviceHandler.list(bouquet) if not bouquetlist is None: while True: bouquet = bouquetlist.getNext() if bouquet.flags & eServiceReference.isDirectory: ChannelSelectionInstance.clearPath() ChannelSelectionInstance.setRoot(bouquet) servicelist = serviceHandler.list(bouquet) if not servicelist is None: serviceIterator = servicelist.getNext() while serviceIterator.valid(): if self.service_ref.ref == serviceIterator: break serviceIterator = servicelist.getNext( ) if self.service_ref.ref == serviceIterator: break ChannelSelectionInstance.enterPath(rootbouquet) ChannelSelectionInstance.enterPath(bouquet) ChannelSelectionInstance.saveRoot() ChannelSelectionInstance.saveChannel( self.service_ref.ref) ChannelSelectionInstance.addToHistory( self.service_ref.ref) NavigationInstance.instance.playService( self.service_ref.ref) return True else: self.log(11, "start recording") record_res = self.record_service.start() if record_res: self.log(13, "start record returned %d" % record_res) self.do_backoff() # retry self.begin = time() + self.backoff return False return True
def removeKeymap(filename): actionMapInstance = eActionMap.getInstance() actionMapInstance.unbindKeyDomain(filename)
def activate(self): next_state = self.state + 1 self.log(5, "activating state %d" % next_state) if next_state == self.StatePrepared and ( self.timerType == TIMERTYPE.AUTOSTANDBY or self.timerType == TIMERTYPE.AUTODEEPSTANDBY): eActionMap.getInstance().bindAction('', -0x7FFFFFFF, self.keyPressed) self.begin = time() + int(self.autosleepdelay) * 60 if self.end <= self.begin: self.end = self.begin if next_state == self.StatePrepared: self.log(6, "prepare ok, waiting for begin") self.next_activation = self.begin self.backoff = 0 return True elif next_state == self.StateRunning: self.wasPowerTimerWakeup = False if os.path.exists("/tmp/was_powertimer_wakeup"): self.wasPowerTimerWakeup = int( open("/tmp/was_powertimer_wakeup", "r").read()) and True or False os.remove("/tmp/was_powertimer_wakeup") if self.cancelled: return True if self.failed: return True if self.timerType == TIMERTYPE.WAKEUP: if Screens.Standby.inStandby: Screens.Standby.inStandby.Power() return True elif self.timerType == TIMERTYPE.WAKEUPTOSTANDBY: return True elif self.timerType == TIMERTYPE.STANDBY: if not Screens.Standby.inStandby: Notifications.AddNotificationWithUniqueIDCallback( self.sendStandbyNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to set your receiver to standby. Do that now?" ), timeout=180) return True elif self.timerType == TIMERTYPE.AUTOSTANDBY: if NavigationInstance.instance.getCurrentlyPlayingServiceReference( ) and ('0:0:0:0:0:0:0:0:0' in NavigationInstance.instance. getCurrentlyPlayingServiceReference().toString() or '4097:' in NavigationInstance.instance. getCurrentlyPlayingServiceReference().toString()): self.do_backoff() return False if not Screens.Standby.inStandby: Notifications.AddNotificationWithUniqueIDCallback( self.sendStandbyNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to set your receiver to standby. Do that now?" ), timeout=180) if self.autosleeprepeat == "once": eActionMap.getInstance().unbindAction( '', self.keyPressed) return True else: self.begin = time() + int(self.autosleepdelay) * 60 if self.end <= self.begin: self.end = self.begin else: self.begin = time() + int(self.autosleepdelay) * 60 if self.end <= self.begin: self.end = self.begin elif self.timerType == TIMERTYPE.AUTODEEPSTANDBY: from Components.Converter.ClientsStreaming import ClientsStreaming if ((not Screens.Standby.inStandby and NavigationInstance. instance.getCurrentlyPlayingServiceReference() and ('0:0:0:0:0:0:0:0:0' in NavigationInstance.instance. getCurrentlyPlayingServiceReference().toString() or '4097:' in NavigationInstance.instance. getCurrentlyPlayingServiceReference().toString()) or (int(ClientsStreaming("NUMBER").getText()) > 0)) or (NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer. getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer. getNextZapTime() - time()) <= 900) or (self.autosleepinstandbyonly == 'yes' and not Screens.Standby.inStandby) or (self.autosleepinstandbyonly == 'yes' and Screens.Standby.inStandby and internalHDDNotSleeping())): self.do_backoff() return False if not Screens.Standby.inTryQuitMainloop: if Screens.Standby.inStandby: quitMainloop(1) return True else: Notifications.AddNotificationWithUniqueIDCallback( self.sendTryQuitMainloopNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to shutdown your receiver. Do that now?" ), timeout=180) if self.autosleeprepeat == "once": eActionMap.getInstance().unbindAction( '', self.keyPressed) return True else: self.begin = time() + int(self.autosleepdelay) * 60 if self.end <= self.begin: self.end = self.begin elif self.timerType == TIMERTYPE.DEEPSTANDBY and self.wasPowerTimerWakeup: return True elif self.timerType == TIMERTYPE.DEEPSTANDBY and not self.wasPowerTimerWakeup: if NavigationInstance.instance.RecordTimer.isRecording( ) or abs(NavigationInstance.instance.RecordTimer. getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance. RecordTimer.getNextZapTime() - time()) <= 900: self.do_backoff() return False if not Screens.Standby.inTryQuitMainloop: if Screens.Standby.inStandby: quitMainloop(1) else: Notifications.AddNotificationWithUniqueIDCallback( self.sendTryQuitMainloopNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to shutdown your receiver. Do that now?" ), timeout=180) return True elif self.timerType == TIMERTYPE.REBOOT: if NavigationInstance.instance.RecordTimer.isRecording( ) or abs(NavigationInstance.instance.RecordTimer. getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance. RecordTimer.getNextZapTime() - time()) <= 900: self.do_backoff() return False if not Screens.Standby.inTryQuitMainloop: if Screens.Standby.inStandby: quitMainloop(2) else: Notifications.AddNotificationWithUniqueIDCallback( self.sendTryToRebootNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to reboot your receiver. Do that now?" ), timeout=180) return True elif self.timerType == TIMERTYPE.RESTART: if NavigationInstance.instance.RecordTimer.isRecording( ) or abs(NavigationInstance.instance.RecordTimer. getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance. RecordTimer.getNextZapTime() - time()) <= 900: self.do_backoff() return False if not Screens.Standby.inTryQuitMainloop: if Screens.Standby.inStandby: quitMainloop(3) else: Notifications.AddNotificationWithUniqueIDCallback( self.sendTryToRestartNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to restart the user interface.\nDo that now?" ), timeout=180) return True elif next_state == self.StateEnded: old_end = self.end NavigationInstance.instance.PowerTimer.saveTimer() if self.afterEvent == AFTEREVENT.STANDBY: if not Screens.Standby.inStandby: Notifications.AddNotificationWithUniqueIDCallback( self.sendStandbyNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to set your receiver to standby. Do that now?" ), timeout=180) elif self.afterEvent == AFTEREVENT.DEEPSTANDBY: if NavigationInstance.instance.RecordTimer.isRecording( ) or abs(NavigationInstance.instance.RecordTimer. getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance. RecordTimer.getNextZapTime() - time()) <= 900: self.do_backoff() return False if not Screens.Standby.inTryQuitMainloop: if Screens.Standby.inStandby: quitMainloop(1) else: Notifications.AddNotificationWithUniqueIDCallback( self.sendTryQuitMainloopNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to shutdown your receiver. Do that now?" ), timeout=180) return True
class PowerTimerEntry(timer.TimerEntry, object): def __init__(self, begin, end, disabled = False, afterEvent = AFTEREVENT.NONE, timerType = TIMERTYPE.WAKEUP, checkOldTimers = False, autosleepdelay = 60): timer.TimerEntry.__init__(self, int(begin), int(end)) if checkOldTimers: if self.begin < time() - 1209600: self.begin = int(time()) if self.end < self.begin: self.end = self.begin self.dontSave = False self.disabled = disabled self.timer = None self.__record_service = None self.start_prepare = 0 self.timerType = timerType self.afterEvent = afterEvent self.autoincrease = False self.autoincreasetime = 3600 * 24 # 1 day self.autosleepinstandbyonly = 'no' self.autosleepdelay = autosleepdelay self.autosleeprepeat = 'once' self.autosleepwindow = 'no' self.autosleepbegin = self.begin self.autosleepend = self.end self.nettraffic = 'no' self.trafficlimit = 100 self.netip = 'no' self.ipadress = "0.0.0.0" self.log_entries = [] self.resetState() self.messageBoxAnswerPending = False #check autopowertimer if (self.timerType == TIMERTYPE.AUTOSTANDBY or self.timerType == TIMERTYPE.AUTODEEPSTANDBY) and not self.disabled and time() > 3600 and self.begin > time(): self.begin = int(time()) #the begin is in the future -> set to current time = no start delay of this timer def __repr__(self): timertype = { TIMERTYPE.NONE: "nothing", TIMERTYPE.WAKEUP: "wakeup", TIMERTYPE.WAKEUPTOSTANDBY: "wakeuptostandby", TIMERTYPE.AUTOSTANDBY: "autostandby", TIMERTYPE.AUTODEEPSTANDBY: "autodeepstandby", TIMERTYPE.STANDBY: "standby", TIMERTYPE.DEEPSTANDBY: "deepstandby", TIMERTYPE.REBOOT: "reboot", TIMERTYPE.RESTART: "restart" }[self.timerType] if not self.disabled: return "PowerTimerEntry(type=%s, begin=%s)" % (timertype, ctime(self.begin)) else: return "PowerTimerEntry(type=%s, begin=%s Disabled)" % (timertype, ctime(self.begin)) def log(self, code, msg): self.log_entries.append((int(time()), code, msg)) def do_backoff(self): if Screens.Standby.inStandby and not wasTimerWakeup or RSsave or RBsave or aeDSsave or DSsave: self.backoff = 300 else: if self.backoff == 0: self.backoff = 300 else: self.backoff += 300 if self.backoff > 900: self.backoff = 900 self.log(10, "backoff: retry in %d minutes" % (int(self.backoff)/60)) def activate(self): global RSsave, RBsave, DSsave, aeDSsave, wasTimerWakeup, InfoBar if not InfoBar: try: from Screens.InfoBar import InfoBar except Exception, e: print "[PowerTimer] import from 'Screens.InfoBar import InfoBar' failed:", e isRecTimerWakeup = breakPT = shiftPT = False now = time() next_state = self.state + 1 self.log(5, "activating state %d" % next_state) if next_state == self.StatePrepared and (self.timerType == TIMERTYPE.AUTOSTANDBY or self.timerType == TIMERTYPE.AUTODEEPSTANDBY): eActionMap.getInstance().bindAction('', -0x7FFFFFFF, self.keyPressed) if self.autosleepwindow == 'yes': ltm = localtime(now) asb = strftime("%H:%M", localtime(self.autosleepbegin)).split(':') ase = strftime("%H:%M", localtime(self.autosleepend)).split(':') self.autosleepbegin = int(mktime(datetime(ltm.tm_year, ltm.tm_mon, ltm.tm_mday, int(asb[0]), int(asb[1])).timetuple())) self.autosleepend = int(mktime(datetime(ltm.tm_year, ltm.tm_mon, ltm.tm_mday, int(ase[0]), int(ase[1])).timetuple())) if self.autosleepend <= self.autosleepbegin: self.autosleepbegin -= 86400 if self.getAutoSleepWindow(): if now < self.autosleepbegin and now > self.autosleepbegin - self.prepare_time - 3: #begin is in prepare time window self.begin = self.end = self.autosleepbegin + int(self.autosleepdelay)*60 else: self.begin = self.end = int(now) + int(self.autosleepdelay)*60 else: return False if self.timerType == TIMERTYPE.AUTODEEPSTANDBY: self.getNetworkTraffic(getInitialValue = True) if (next_state == self.StateRunning or next_state == self.StateEnded) and NavigationInstance.instance.PowerTimer is None: #TODO: running/ended timer at system start has no nav instance #First fix: crash in getPriorityCheck (NavigationInstance.instance.PowerTimer...) #Second fix: suppress the message (A finished powertimer wants to ...) if debug: print "*****NavigationInstance.instance.PowerTimer is None*****", self.timerType, self.state, ctime(self.begin), ctime(self.end) return True elif next_state == self.StateRunning and abs(self.begin - now) > 900: return True elif next_state == self.StateEnded and abs(self.end - now) > 900: return True if next_state == self.StateRunning or next_state == self.StateEnded: if NavigationInstance.instance.isRecordTimerImageStandard: isRecTimerWakeup = NavigationInstance.instance.RecordTimer.isRecTimerWakeup() if isRecTimerWakeup: wasTimerWakeup = True elif os.path.exists("/tmp/was_powertimer_wakeup") and not wasTimerWakeup: wasTimerWakeup = int(open("/tmp/was_powertimer_wakeup", "r").read()) and True or False if next_state == self.StatePrepared: self.log(6, "prepare ok, waiting for begin: %s" % ctime(self.begin)) self.backoff = 0 return True elif next_state == self.StateRunning: # if this timer has been cancelled, just go to "end" state. if self.cancelled: return True if self.failed: return True if self.timerType == TIMERTYPE.NONE: return True elif self.timerType == TIMERTYPE.WAKEUP: if Screens.Standby.inStandby: Screens.Standby.inStandby.Power() return True elif self.timerType == TIMERTYPE.WAKEUPTOSTANDBY: return True elif self.timerType == TIMERTYPE.STANDBY: if debug: print "self.timerType == TIMERTYPE.STANDBY:" prioPT = [TIMERTYPE.WAKEUP,TIMERTYPE.RESTART,TIMERTYPE.REBOOT,TIMERTYPE.DEEPSTANDBY] prioPTae = [AFTEREVENT.WAKEUP,AFTEREVENT.DEEPSTANDBY] shiftPT,breakPT = self.getPriorityCheck(prioPT,prioPTae) if not Screens.Standby.inStandby and not breakPT: # not already in standby callback = self.sendStandbyNotification message = _("A finished powertimer wants to set your\n%s %s to standby. Do that now?") % (getMachineBrand(), getMachineName()) messageboxtyp = MessageBox.TYPE_YESNO timeout = 180 default = True if InfoBar and InfoBar.instance: InfoBar.instance.openInfoBarMessageWithCallback(callback, message, messageboxtyp, timeout, default) else: Notifications.AddNotificationWithCallback(callback, MessageBox, message, messageboxtyp, timeout = timeout, default = default) return True elif self.timerType == TIMERTYPE.AUTOSTANDBY: if debug: print "self.timerType == TIMERTYPE.AUTOSTANDBY:" if not self.getAutoSleepWindow(): return False if not Screens.Standby.inStandby and not self.messageBoxAnswerPending: # not already in standby self.messageBoxAnswerPending = True callback = self.sendStandbyNotification message = _("A finished powertimer wants to set your\n%s %s to standby. Do that now?") % (getMachineBrand(), getMachineName()) messageboxtyp = MessageBox.TYPE_YESNO timeout = 180 default = True if InfoBar and InfoBar.instance: InfoBar.instance.openInfoBarMessageWithCallback(callback, message, messageboxtyp, timeout, default) else: Notifications.AddNotificationWithCallback(callback, MessageBox, message, messageboxtyp, timeout = timeout, default = default) if self.autosleeprepeat == "once": eActionMap.getInstance().unbindAction('', self.keyPressed) return True else: self.begin = self.end = int(now) + int(self.autosleepdelay)*60 else: self.begin = self.end = int(now) + int(self.autosleepdelay)*60 elif self.timerType == TIMERTYPE.AUTODEEPSTANDBY: if debug: print "self.timerType == TIMERTYPE.AUTODEEPSTANDBY:" if not self.getAutoSleepWindow(): return False if isRecTimerWakeup or (self.autosleepinstandbyonly == 'yes' and not Screens.Standby.inStandby) \ or NavigationInstance.instance.PowerTimer.isProcessing() or abs(NavigationInstance.instance.PowerTimer.getNextPowerManagerTime() - now) <= 900 or self.getNetworkAdress() or self.getNetworkTraffic() \ or NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - now) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - now) <= 900: self.do_backoff() # retry self.begin = self.end = int(now) + self.backoff return False elif not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if self.autosleeprepeat == "once": self.disabled = True if Screens.Standby.inStandby or self.autosleepinstandbyonly == 'noquery': # in standby or option 'without query' is enabled print "[PowerTimer] quitMainloop #1" quitMainloop(1) return True elif not self.messageBoxAnswerPending: self.messageBoxAnswerPending = True callback = self.sendTryQuitMainloopNotification message = _("A finished powertimer wants to shutdown your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()) messageboxtyp = MessageBox.TYPE_YESNO timeout = 180 default = True if InfoBar and InfoBar.instance: InfoBar.instance.openInfoBarMessageWithCallback(callback, message, messageboxtyp, timeout, default) else: Notifications.AddNotificationWithCallback(callback, MessageBox, message, messageboxtyp, timeout = timeout, default = default) if self.autosleeprepeat == "once": eActionMap.getInstance().unbindAction('', self.keyPressed) return True self.begin = self.end = int(now) + int(self.autosleepdelay)*60 elif self.timerType == TIMERTYPE.RESTART: if debug: print "self.timerType == TIMERTYPE.RESTART:" #check priority prioPT = [TIMERTYPE.RESTART,TIMERTYPE.REBOOT,TIMERTYPE.DEEPSTANDBY] prioPTae = [AFTEREVENT.DEEPSTANDBY] shiftPT,breakPT = self.getPriorityCheck(prioPT,prioPTae) #a timer with higher priority was shifted - no execution of current timer if RBsave or aeDSsave or DSsave: if debug: print "break#1" breakPT = True #a timer with lower priority was shifted - shift now current timer and wait for restore the saved time values from other timer if False: if debug: print "shift#1" breakPT = False shiftPT = True #shift or break if isRecTimerWakeup or shiftPT or breakPT \ or NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - now) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - now) <= 900: if self.repeated and not RSsave: self.savebegin = self.begin self.saveend = self.end RSsave = True if not breakPT: self.do_backoff() #check difference begin to end before shift begin time if RSsave and self.end - self.begin > 3 and self.end - now - self.backoff <= 240: breakPT = True #breakPT if breakPT: if self.repeated and RSsave: try: self.begin = self.savebegin self.end = self.saveend except: pass RSsave = False return True # retry oldbegin = self.begin self.begin = int(now) + self.backoff if abs(self.end - oldbegin) <= 3: self.end = self.begin else: if not self.repeated and self.end < self.begin + 300: self.end = self.begin + 300 return False elif not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if self.repeated and RSsave: try: self.begin = self.savebegin self.end = self.saveend except: pass if Screens.Standby.inStandby: # in standby print "[PowerTimer] quitMainloop #4" quitMainloop(3) else: callback = self.sendTryToRestartNotification message = _("A finished powertimer wants to restart the user interface.\nDo that now?") % (getMachineBrand(), getMachineName()) messageboxtyp = MessageBox.TYPE_YESNO timeout = 180 default = True if InfoBar and InfoBar.instance: InfoBar.instance.openInfoBarMessageWithCallback(callback, message, messageboxtyp, timeout, default) else: Notifications.AddNotificationWithCallback(callback, MessageBox, message, messageboxtyp, timeout = timeout, default = default) RSsave = False return True elif self.timerType == TIMERTYPE.REBOOT: if debug: print "self.timerType == TIMERTYPE.REBOOT:" #check priority prioPT = [TIMERTYPE.REBOOT,TIMERTYPE.DEEPSTANDBY] prioPTae = [AFTEREVENT.DEEPSTANDBY] shiftPT,breakPT = self.getPriorityCheck(prioPT,prioPTae) #a timer with higher priority was shifted - no execution of current timer if aeDSsave or DSsave: if debug: print "break#1" breakPT = True #a timer with lower priority was shifted - shift now current timer and wait for restore the saved time values from other timer if RSsave: if debug: print "shift#1" breakPT = False shiftPT = True #shift or break if isRecTimerWakeup or shiftPT or breakPT \ or NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - now) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - now) <= 900: if self.repeated and not RBsave: self.savebegin = self.begin self.saveend = self.end RBsave = True if not breakPT: self.do_backoff() #check difference begin to end before shift begin time if RBsave and self.end - self.begin > 3 and self.end - now - self.backoff <= 240: breakPT = True #breakPT if breakPT: if self.repeated and RBsave: try: self.begin = self.savebegin self.end = self.saveend except: pass RBsave = False return True # retry oldbegin = self.begin self.begin = int(now) + self.backoff if abs(self.end - oldbegin) <= 3: self.end = self.begin else: if not self.repeated and self.end < self.begin + 300: self.end = self.begin + 300 return False elif not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if self.repeated and RBsave: try: self.begin = self.savebegin self.end = self.saveend except: pass if Screens.Standby.inStandby: # in standby print "[PowerTimer] quitMainloop #3" quitMainloop(2) else: callback = self.sendTryToRebootNotification message = _("A finished powertimer wants to reboot your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()) messageboxtyp = MessageBox.TYPE_YESNO timeout = 180 default = True if InfoBar and InfoBar.instance: InfoBar.instance.openInfoBarMessageWithCallback(callback, message, messageboxtyp, timeout, default) else: Notifications.AddNotificationWithCallback(callback, MessageBox, message, messageboxtyp, timeout = timeout, default = default) RBsave = False return True elif self.timerType == TIMERTYPE.DEEPSTANDBY: if debug: print "self.timerType == TIMERTYPE.DEEPSTANDBY:" #check priority prioPT = [TIMERTYPE.WAKEUP,TIMERTYPE.WAKEUPTOSTANDBY,TIMERTYPE.DEEPSTANDBY] prioPTae = [AFTEREVENT.WAKEUP,AFTEREVENT.WAKEUPTOSTANDBY,AFTEREVENT.DEEPSTANDBY] shiftPT,breakPT = self.getPriorityCheck(prioPT,prioPTae) #a timer with higher priority was shifted - no execution of current timer if False: if debug: print "break#1" breakPT = True #a timer with lower priority was shifted - shift now current timer and wait for restore the saved time values from other timer if RSsave or RBsave or aeDSsave: if debug: print "shift#1" breakPT = False shiftPT = True #shift or break if isRecTimerWakeup or shiftPT or breakPT \ or NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - now) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - now) <= 900: if self.repeated and not DSsave: self.savebegin = self.begin self.saveend = self.end DSsave = True if not breakPT: self.do_backoff() #check difference begin to end before shift begin time if DSsave and self.end - self.begin > 3 and self.end - now - self.backoff <= 240: breakPT = True #breakPT if breakPT: if self.repeated and DSsave: try: self.begin = self.savebegin self.end = self.saveend except: pass DSsave = False return True # retry oldbegin = self.begin self.begin = int(now) + self.backoff if abs(self.end - oldbegin) <= 3: self.end = self.begin else: if not self.repeated and self.end < self.begin + 300: self.end = self.begin + 300 return False elif not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if self.repeated and DSsave: try: self.begin = self.savebegin self.end = self.saveend except: pass if Screens.Standby.inStandby: # in standby print "[PowerTimer] quitMainloop #2" quitMainloop(1) else: callback = self.sendTryQuitMainloopNotification message = _("A finished powertimer wants to shutdown your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()) messageboxtyp = MessageBox.TYPE_YESNO timeout = 180 default = True if InfoBar and InfoBar.instance: InfoBar.instance.openInfoBarMessageWithCallback(callback, message, messageboxtyp, timeout, default) else: Notifications.AddNotificationWithCallback(callback, MessageBox, message, messageboxtyp, timeout = timeout, default = default) DSsave = False return True elif next_state == self.StateEnded: if self.afterEvent == AFTEREVENT.WAKEUP: if Screens.Standby.inStandby: Screens.Standby.inStandby.Power() elif self.afterEvent == AFTEREVENT.STANDBY: if not Screens.Standby.inStandby: # not already in standby callback = self.sendStandbyNotification message = _("A finished powertimer wants to set your\n%s %s to standby. Do that now?") % (getMachineBrand(), getMachineName()) messageboxtyp = MessageBox.TYPE_YESNO timeout = 180 default = True if InfoBar and InfoBar.instance: InfoBar.instance.openInfoBarMessageWithCallback(callback, message, messageboxtyp, timeout, default) else: Notifications.AddNotificationWithCallback(callback, MessageBox, message, messageboxtyp, timeout = timeout, default = default) elif self.afterEvent == AFTEREVENT.DEEPSTANDBY: if debug: print "self.afterEvent == AFTEREVENT.DEEPSTANDBY:" #check priority prioPT = [TIMERTYPE.WAKEUP,TIMERTYPE.WAKEUPTOSTANDBY,TIMERTYPE.DEEPSTANDBY] prioPTae = [AFTEREVENT.WAKEUP,AFTEREVENT.WAKEUPTOSTANDBY,AFTEREVENT.DEEPSTANDBY] shiftPT,breakPT = self.getPriorityCheck(prioPT,prioPTae) #a timer with higher priority was shifted - no execution of current timer if DSsave: if debug: print "break#1" breakPT = True #a timer with lower priority was shifted - shift now current timer and wait for restore the saved time values if RSsave or RBsave: if debug: print "shift#1" breakPT = False shiftPT = True #shift or break runningPT = False #option: check other powertimer is running (current disabled) #runningPT = NavigationInstance.instance.PowerTimer.isProcessing(exceptTimer = TIMERTYPE.NONE, endedTimer = self.timerType) if isRecTimerWakeup or shiftPT or breakPT or runningPT \ or NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - now) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - now) <= 900: if self.repeated and not aeDSsave: self.savebegin = self.begin self.saveend = self.end aeDSsave = True if not breakPT: self.do_backoff() #breakPT if breakPT: if self.repeated and aeDSsave: try: self.begin = self.savebegin self.end = self.saveend except: pass aeDSsave = False return True # retry self.end = int(now) + self.backoff return False elif not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if self.repeated and aeDSsave: try: self.begin = self.savebegin self.end = self.saveend except: pass if Screens.Standby.inStandby: # in standby print "[PowerTimer] quitMainloop #5" quitMainloop(1) else: callback = self.sendTryQuitMainloopNotification message = _("A finished powertimer wants to shutdown your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()) messageboxtyp = MessageBox.TYPE_YESNO timeout = 180 default = True if InfoBar and InfoBar.instance: InfoBar.instance.openInfoBarMessageWithCallback(callback, message, messageboxtyp, timeout, default) else: Notifications.AddNotificationWithCallback(callback, MessageBox, message, messageboxtyp, timeout = timeout, default = default) aeDSsave = False NavigationInstance.instance.PowerTimer.saveTimer() resetTimerWakeup() return True
def __close(self): eActionMap.getInstance().unbindAction('', self.__keypress)
def activate(self): next_state = self.state + 1 self.log(5, "activating state %d" % next_state) if next_state == self.StatePrepared and ( self.timerType == TIMERTYPE.AUTOSTANDBY or self.timerType == TIMERTYPE.AUTODEEPSTANDBY): # This is the first action for an auto* timer. # It binds any key press to keyPressed(), which resets the timer delay, # and sets the initial delay. eActionMap.getInstance().bindAction('', -0x7FFFFFFF, self.keyPressed) self.begin = time() + int(self.autosleepdelay) * 60 if self.end <= self.begin: self.end = self.begin if next_state == self.StatePrepared: self.log(6, "prepare ok, waiting for begin") self.next_activation = self.begin self.backoff = 0 return True elif next_state == self.StateRunning: self.wasPowerTimerWakeup = False if os.path.exists("/tmp/was_powertimer_wakeup"): self.wasPowerTimerWakeup = int( open("/tmp/was_powertimer_wakeup", "r").read()) and True or False os.remove("/tmp/was_powertimer_wakeup") # if this timer has been cancelled, just go to "end" state. if self.cancelled: return True if self.failed: return True if self.timerType == TIMERTYPE.WAKEUP: if Screens.Standby.inStandby: Screens.Standby.inStandby.Power() return True elif self.timerType == TIMERTYPE.WAKEUPTOSTANDBY: return True elif self.timerType == TIMERTYPE.STANDBY: if not Screens.Standby.inStandby: # not already in standby Notifications.AddNotificationWithUniqueIDCallback( self.sendStandbyNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to set your receiver to standby. Do that now?" ), timeout=180) return True elif self.timerType == TIMERTYPE.AUTOSTANDBY: if NavigationInstance.instance.getCurrentlyPlayingServiceReference( ) and ('0:0:0:0:0:0:0:0:0' in NavigationInstance.instance. getCurrentlyPlayingServiceReference().toString() or '4097:' in NavigationInstance.instance. getCurrentlyPlayingServiceReference().toString()): self.do_backoff() # retry return False if not Screens.Standby.inStandby: # not already in standby Notifications.AddNotificationWithUniqueIDCallback( self.sendStandbyNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to set your receiver to standby. Do that now?" ), timeout=180) if self.autosleeprepeat == "once": eActionMap.getInstance().unbindAction( '', self.keyPressed) return True else: self.begin = time() + int(self.autosleepdelay) * 60 if self.end <= self.begin: self.end = self.begin else: self.begin = time() + int(self.autosleepdelay) * 60 if self.end <= self.begin: self.end = self.begin elif self.timerType == TIMERTYPE.AUTODEEPSTANDBY: # Check for there being any active Movie playback or IPTV channel # or any streaming clients before going to Deep Standby. # However, it is possible to put the box into Standby with the # MoviePlayer still active (it will play if the box is taken out # of Standby) - similarly for the IPTV player. This should not # prevent a DeepStandby # And check for existing or imminent recordings, etc.. # Also added () around the test and split them across lines # to make it clearer what each test is. from Components.Converter.ClientsStreaming import ClientsStreaming if ((not Screens.Standby.inStandby and NavigationInstance. instance.getCurrentlyPlayingServiceReference() and ('0:0:0:0:0:0:0:0:0' in NavigationInstance.instance. getCurrentlyPlayingServiceReference().toString() or '4097:' in NavigationInstance.instance. getCurrentlyPlayingServiceReference().toString()) or (int(ClientsStreaming("NUMBER").getText()) > 0)) or (NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer. getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer. getNextZapTime() - time()) <= 900) or (self.autosleepinstandbyonly == 'yes' and not Screens.Standby.inStandby) or (self.autosleepinstandbyonly == 'yes' and Screens.Standby.inStandby and internalHDDNotSleeping())): self.do_backoff() # retry return False if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if Screens.Standby.inStandby: # in standby quitMainloop(1) return True else: Notifications.AddNotificationWithUniqueIDCallback( self.sendTryQuitMainloopNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to shutdown your receiver. Do that now?" ), timeout=180) if self.autosleeprepeat == "once": eActionMap.getInstance().unbindAction( '', self.keyPressed) return True else: self.begin = time() + int(self.autosleepdelay) * 60 if self.end <= self.begin: self.end = self.begin elif self.timerType == TIMERTYPE.DEEPSTANDBY and self.wasPowerTimerWakeup: return True elif self.timerType == TIMERTYPE.DEEPSTANDBY and not self.wasPowerTimerWakeup: if NavigationInstance.instance.RecordTimer.isRecording( ) or abs(NavigationInstance.instance.RecordTimer. getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance. RecordTimer.getNextZapTime() - time()) <= 900: self.do_backoff() # retry return False if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if Screens.Standby.inStandby: # in standby quitMainloop(1) else: Notifications.AddNotificationWithUniqueIDCallback( self.sendTryQuitMainloopNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to shutdown your receiver. Do that now?" ), timeout=180) return True elif self.timerType == TIMERTYPE.REBOOT: if NavigationInstance.instance.RecordTimer.isRecording( ) or abs(NavigationInstance.instance.RecordTimer. getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance. RecordTimer.getNextZapTime() - time()) <= 900: self.do_backoff() # retry return False if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if Screens.Standby.inStandby: # in standby quitMainloop(2) else: Notifications.AddNotificationWithUniqueIDCallback( self.sendTryToRebootNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to reboot your receiver. Do that now?" ), timeout=180) return True elif self.timerType == TIMERTYPE.RESTART: if NavigationInstance.instance.RecordTimer.isRecording( ) or abs(NavigationInstance.instance.RecordTimer. getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance. RecordTimer.getNextZapTime() - time()) <= 900: self.do_backoff() # retry return False if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if Screens.Standby.inStandby: # in standby quitMainloop(3) else: Notifications.AddNotificationWithUniqueIDCallback( self.sendTryToRestartNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to restart the user interface.\nDo that now?" ), timeout=180) return True elif next_state == self.StateEnded: old_end = self.end NavigationInstance.instance.PowerTimer.saveTimer() if self.afterEvent == AFTEREVENT.STANDBY: if not Screens.Standby.inStandby: # not already in standby Notifications.AddNotificationWithUniqueIDCallback( self.sendStandbyNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to set your receiver to standby. Do that now?" ), timeout=180) elif self.afterEvent == AFTEREVENT.DEEPSTANDBY: if NavigationInstance.instance.RecordTimer.isRecording( ) or abs(NavigationInstance.instance.RecordTimer. getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance. RecordTimer.getNextZapTime() - time()) <= 900: self.do_backoff() # retry return False if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if Screens.Standby.inStandby: # in standby quitMainloop(1) else: Notifications.AddNotificationWithUniqueIDCallback( self.sendTryQuitMainloopNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to shutdown your receiver. Do that now?" ), timeout=180) return True
def keypressScreenSaver(self, key, flag): if flag: self.screensaver.hide() self.show() self.ScreenSaverTimerStart() eActionMap.getInstance().unbindAction('', self.keypressScreenSaver)
def __onExecEnd(self): if self.screensaver.shown: self.screensaver.hide() eActionMap.getInstance().unbindAction('', self.keypressScreenSaver) self.screenSaverTimer.stop()
def leaveStandby(self): eActionMap.getInstance().bindAction('', -maxint - 1, self.DimUpEvent)
def keypress(key=None, flag=1): if flag and (RecordTimerEntry.wasInStandby or RecordTimerEntry.wasInDeepStandby): RecordTimerEntry.wasInStandby = False RecordTimerEntry.wasInDeepStandby = False eActionMap.getInstance().unbindAction('', RecordTimerEntry.keypress)
def setWasInDeepStandby(): RecordTimerEntry.wasInDeepStandby = True eActionMap.getInstance().bindAction('', -maxint - 1, RecordTimerEntry.keypress)
def closeHelp(self): eActionMap.getInstance().unbindAction("", self["list"].handleButton) self["list"].onSelectionChanged.remove(self.selectionChanged)
def __init__(self): assert not HdmiCec.instance, "only one HdmiCec instance is allowed!" HdmiCec.instance = self self.wait = eTimer() self.wait.timeout.get().append(self.sendCmd) self.waitKeyEvent = eTimer() self.waitKeyEvent.timeout.get().append(self.sendKeyEvent) self.queueKeyEvent = [] self.repeat = eTimer() self.repeat.timeout.get().append(self.wakeupMessages) self.queue = [] self.delay = eTimer() self.delay.timeout.get().append(self.sendStandbyMessages) self.useStandby = True self.handlingStandbyFromTV = False eHdmiCEC.getInstance().messageReceived.get().append( self.messageReceived) config.misc.standbyCounter.addNotifier(self.onEnterStandby, initial_call=False) config.misc.DeepStandby.addNotifier(self.onEnterDeepStandby, initial_call=False) self.setFixedPhysicalAddress( config.hdmicec.fixed_physical_address.value) self.volumeForwardingEnabled = False self.volumeForwardingDestination = 0 self.wakeup_from_tv = False eActionMap.getInstance().bindAction('', -maxint - 1, self.keyEvent) config.hdmicec.volume_forwarding.addNotifier( self.configVolumeForwarding) config.hdmicec.enabled.addNotifier(self.configVolumeForwarding) if config.hdmicec.enabled.value: assert not HdmiCec.instance, "only one HdmiCec instance is allowed!" HdmiCec.instance = self self.wait = eTimer() self.wait.timeout.get().append(self.sendCmd) self.waitKeyEvent = eTimer() self.waitKeyEvent.timeout.get().append(self.sendKeyEvent) self.queueKeyEvent = [] self.repeat = eTimer() self.repeat.timeout.get().append(self.wakeupMessages) self.queue = [] self.delay = eTimer() self.delay.timeout.get().append(self.sendStandbyMessages) self.useStandby = True eHdmiCEC.getInstance().messageReceived.get().append( self.messageReceived) config.misc.standbyCounter.addNotifier(self.onEnterStandby, initial_call=False) config.misc.DeepStandby.addNotifier(self.onEnterDeepStandby, initial_call=False) self.setFixedPhysicalAddress( config.hdmicec.fixed_physical_address.value) self.volumeForwardingEnabled = False self.volumeForwardingDestination = 0 self.wakeup_from_tv = False eActionMap.getInstance().bindAction('', -maxint - 1, self.keyEvent) config.hdmicec.volume_forwarding.addNotifier( self.configVolumeForwarding) config.hdmicec.enabled.addNotifier(self.configVolumeForwarding) if config.hdmicec.enabled.value: if config.hdmicec.report_active_menu.value: if config.hdmicec.report_active_source.value and NavigationInstance.instance and not NavigationInstance.instance.isRestartUI( ): self.sendMessage(0, "sourceinactive") self.sendMessage(0, "menuactive") if config.hdmicec.handle_deepstandby_events.value and ( not getFPWasTimerWakeup() or (config.usage.startup_to_standby.value == "no" and config.misc.prev_wakeup_time_type.value == 3)): self.onLeaveStandby()
def closeConfirmBox(self, answer): eActionMap.getInstance().unbindAction('', self.action) self.close(answer)
def __init__(self): self.ScreenshotConsole = Console() self.previousflag = 0 eActionMap.getInstance().bindAction('', -0x7FFFFFFF, self.screenshotKey)
def enableKeyMap(self): globalActionMap.setEnabled(True) eActionMap.getInstance().bindKey("keymap.xml", "generic", 103, 5, "ListboxActions", "moveUp") eActionMap.getInstance().bindKey("keymap.xml", "generic", 108, 5, "ListboxActions", "moveDown") eActionMap.getInstance().bindKey("keymap.xml", "generic", 105, 5, "ListboxActions", "pageUp") eActionMap.getInstance().bindKey("keymap.xml", "generic", 106, 5, "ListboxActions", "pageDown")
{ "cancel": self.close, }, -1) self["ButtonSetupButtonActions"] = ButtonSetupActionMap(["ButtonSetupActions"], dict((x[1], self.ButtonSetupGlobal) for x in ButtonSetupKeys)) self.longkeyPressed = False self.onLayoutFinish.append(self.__layoutFinished) self.onExecBegin.append(self.getFunctions) self.onShown.append(self.disableKeyMap) self.onClose.append(self.enableKeyMap) def __layoutFinished(self): self["choosen"].selectionEnabled(0) def disableKeyMap(self): globalActionMap.setEnabled(False) eActionMap.getInstance().unbindNativeKey("ListboxActions", 0) eActionMap.getInstance().unbindNativeKey("ListboxActions", 1) eActionMap.getInstance().unbindNativeKey("ListboxActions", 4) eActionMap.getInstance().unbindNativeKey("ListboxActions", 5) def enableKeyMap(self): globalActionMap.setEnabled(True) eActionMap.getInstance().bindKey("keymap.xml", "generic", 103, 5, "ListboxActions", "moveUp") eActionMap.getInstance().bindKey("keymap.xml", "generic", 108, 5, "ListboxActions", "moveDown") eActionMap.getInstance().bindKey("keymap.xml", "generic", 105, 5, "ListboxActions", "pageUp") eActionMap.getInstance().bindKey("keymap.xml", "generic", 106, 5, "ListboxActions", "pageDown") def ButtonSetupGlobal(self, key): if self.longkeyPressed: self.longkeyPressed = False else:
def disableKeyMap(self): globalActionMap.setEnabled(False) eActionMap.getInstance().unbindNativeKey("ListboxActions", 0) eActionMap.getInstance().unbindNativeKey("ListboxActions", 1) eActionMap.getInstance().unbindNativeKey("ListboxActions", 4) eActionMap.getInstance().unbindNativeKey("ListboxActions", 5)
def connectHighPrioAction(self): self.highPrioActionSlot = eActionMap.getInstance().bindAction( '', -0x7FFFFFFF, self.closeAnyKey) if self.additionalActionMap: self.additionalActionMap.execBegin()
def doOnClose(self): eActionMap.getInstance().unbindAction('', self["list"].handleButton) self["list"].onSelChanged.remove(self.SelectionChanged)
def leaveStandby(self): eActionMap.getInstance().bindAction('', -sys.maxsize - 1, self.DimUpEvent)
def showCB(self, key=None, flag=1): self.show() self.session.nav.playService(last_service) eActionMap.getInstance().unbindAction('', self.showCB) self.disableActions_Timer.start(100, True)
def disableKeyMap(self): eActionMap.getInstance().unbindNativeKey("ListboxActions", 0) eActionMap.getInstance().unbindNativeKey("ListboxActions", 1) eActionMap.getInstance().unbindNativeKey("ListboxActions", 4) eActionMap.getInstance().unbindNativeKey("ListboxActions", 5)
def activate(self): global RSsave, RBsave, DSsave, aeDSsave, wasTimerWakeup isRecTimerWakeup = breakPT = shiftPT = False now = time() next_state = self.state + 1 self.log(5, "activating state %d" % next_state) if next_state == self.StatePrepared and (self.timerType == TIMERTYPE.AUTOSTANDBY or self.timerType == TIMERTYPE.AUTODEEPSTANDBY): eActionMap.getInstance().bindAction('', -0x7FFFFFFF, self.keyPressed) if self.autosleepwindow == 'yes': ltm = localtime(now) asb = strftime("%H:%M", localtime(self.autosleepbegin)).split(':') ase = strftime("%H:%M", localtime(self.autosleepend)).split(':') self.autosleepbegin = int(mktime(datetime(ltm.tm_year, ltm.tm_mon, ltm.tm_mday, int(asb[0]), int(asb[1])).timetuple())) self.autosleepend = int(mktime(datetime(ltm.tm_year, ltm.tm_mon, ltm.tm_mday, int(ase[0]), int(ase[1])).timetuple())) if self.autosleepend <= self.autosleepbegin: self.autosleepbegin -= 86400 if self.getAutoSleepWindow(): if now < self.autosleepbegin and now > self.autosleepbegin - self.prepare_time - 3: #begin is in prepare time window self.begin = self.end = self.autosleepbegin + int(self.autosleepdelay)*60 else: self.begin = self.end = int(now) + int(self.autosleepdelay)*60 else: return False if self.timerType == TIMERTYPE.AUTODEEPSTANDBY: self.getNetworkTraffic(getInitialValue = True) if (next_state == self.StateRunning or next_state == self.StateEnded) and NavigationInstance.instance.PowerTimer is None: #TODO: running/ended timer at system start has no nav instance #First fix: crash in getPriorityCheck (NavigationInstance.instance.PowerTimer...) #Second fix: suppress the message (A finished powertimer wants to ...) if debug: print "*****NavigationInstance.instance.PowerTimer is None*****", self.timerType, self.state, ctime(self.begin), ctime(self.end) return True elif next_state == self.StateRunning and abs(self.begin - now) > 900: return True elif next_state == self.StateEnded and abs(self.end - now) > 900: return True if next_state == self.StateRunning or next_state == self.StateEnded: if NavigationInstance.instance.isRecordTimerImageStandard: isRecTimerWakeup = NavigationInstance.instance.RecordTimer.isRecTimerWakeup() if isRecTimerWakeup: wasTimerWakeup = True elif os.path.exists("/tmp/was_powertimer_wakeup") and not wasTimerWakeup: wasTimerWakeup = int(open("/tmp/was_powertimer_wakeup", "r").read()) and True or False if next_state == self.StatePrepared: self.log(6, "prepare ok, waiting for begin: %s" % ctime(self.begin)) self.backoff = 0 return True elif next_state == self.StateRunning: # if this timer has been cancelled, just go to "end" state. if self.cancelled: return True if self.failed: return True if self.timerType == TIMERTYPE.NONE: return True elif self.timerType == TIMERTYPE.WAKEUP: if debug: print "self.timerType == TIMERTYPE.WAKEUP:" if Screens.Standby.inStandby: Screens.Standby.inStandby.Power() return True #elif self.timerType == TIMERTYPE.WAKEUPTOSTANDBY: # return True elif self.timerType == TIMERTYPE.WAKEUPTOSTANDBY or self.timerType == TIMERTYPE.STANDBY: if debug: if self.timerType == TIMERTYPE.WAKEUPTOSTANDBY: print "self.timerType == TIMERTYPE.WAKEUPTOSTANDBY:" else: print "self.timerType == TIMERTYPE.STANDBY:" prioPT = [TIMERTYPE.WAKEUP,TIMERTYPE.RESTART,TIMERTYPE.REBOOT,TIMERTYPE.DEEPSTANDBY] prioPTae = [AFTEREVENT.WAKEUP,AFTEREVENT.DEEPSTANDBY] shiftPT,breakPT = self.getPriorityCheck(prioPT,prioPTae) if not Screens.Standby.inStandby and not breakPT: # not already in standby Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A finished powertimer wants to set your\n%s %s to standby. Do that now?") % (getMachineBrand(), getMachineName()), timeout = 180) return True elif self.timerType == TIMERTYPE.AUTOSTANDBY: if debug: print "self.timerType == TIMERTYPE.AUTOSTANDBY:" if not self.getAutoSleepWindow(): return False if not Screens.Standby.inStandby: # not already in standby Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A finished powertimer wants to set your\n%s %s to standby. Do that now?") % (getMachineBrand(), getMachineName()), timeout = 180) if self.autosleeprepeat == "once": eActionMap.getInstance().unbindAction('', self.keyPressed) return True else: self.begin = self.end = int(now) + int(self.autosleepdelay)*60 else: self.begin = self.end = int(now) + int(self.autosleepdelay)*60 elif self.timerType == TIMERTYPE.AUTODEEPSTANDBY: if debug: print "self.timerType == TIMERTYPE.AUTODEEPSTANDBY:" if not self.getAutoSleepWindow(): return False if isRecTimerWakeup or (self.autosleepinstandbyonly == 'yes' and not Screens.Standby.inStandby) \ or NavigationInstance.instance.PowerTimer.isProcessing() or abs(NavigationInstance.instance.PowerTimer.getNextPowerManagerTime() - now) <= 900 or self.getNetworkAdress() or self.getNetworkTraffic() \ or NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - now) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - now) <= 900: self.do_backoff() # retry self.begin = self.end = int(now) + self.backoff return False elif not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if self.autosleeprepeat == "once": self.disabled = True if Screens.Standby.inStandby or self.autosleepinstandbyonly == 'noquery': # in standby or option 'without query' is enabled print "[PowerTimer] quitMainloop #1" quitMainloop(1) return True else: Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A finished powertimer wants to shutdown your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()), timeout = 180) if self.autosleeprepeat == "once": eActionMap.getInstance().unbindAction('', self.keyPressed) return True else: self.begin = self.end = int(now) + int(self.autosleepdelay)*60 elif self.timerType == TIMERTYPE.RESTART: if debug: print "self.timerType == TIMERTYPE.RESTART:" #check priority prioPT = [TIMERTYPE.RESTART,TIMERTYPE.REBOOT,TIMERTYPE.DEEPSTANDBY] prioPTae = [AFTEREVENT.DEEPSTANDBY] shiftPT,breakPT = self.getPriorityCheck(prioPT,prioPTae) #a timer with higher priority was shifted - no execution of current timer if RBsave or aeDSsave or DSsave: if debug: print "break#1" breakPT = True #a timer with lower priority was shifted - shift now current timer and wait for restore the saved time values from other timer if False: if debug: print "shift#1" breakPT = False shiftPT = True #shift or break if isRecTimerWakeup or shiftPT or breakPT \ or NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - now) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - now) <= 900: if self.repeated and not RSsave: self.savebegin = self.begin self.saveend = self.end RSsave = True if not breakPT: self.do_backoff() #check difference begin to end before shift begin time if RSsave and self.end - self.begin > 3 and self.end - now - self.backoff <= 240: breakPT = True #breakPT if breakPT: if self.repeated and RSsave: try: self.begin = self.savebegin self.end = self.saveend except: pass RSsave = False return True # retry oldbegin = self.begin self.begin = int(now) + self.backoff if abs(self.end - oldbegin) <= 3: self.end = self.begin else: if not self.repeated and self.end < self.begin + 300: self.end = self.begin + 300 return False elif not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if self.repeated and RSsave: try: self.begin = self.savebegin self.end = self.saveend except: pass if Screens.Standby.inStandby: # in standby print "[PowerTimer] quitMainloop #4" quitMainloop(3) else: Notifications.AddNotificationWithCallback(self.sendTryToRestartNotification, MessageBox, _("A finished powertimer wants to restart the user interface.\nDo that now?"), timeout = 180) RSsave = False return True elif self.timerType == TIMERTYPE.REBOOT: if debug: print "self.timerType == TIMERTYPE.REBOOT:" #check priority prioPT = [TIMERTYPE.REBOOT,TIMERTYPE.DEEPSTANDBY] prioPTae = [AFTEREVENT.DEEPSTANDBY] shiftPT,breakPT = self.getPriorityCheck(prioPT,prioPTae) #a timer with higher priority was shifted - no execution of current timer if aeDSsave or DSsave: if debug: print "break#1" breakPT = True #a timer with lower priority was shifted - shift now current timer and wait for restore the saved time values from other timer if RSsave: if debug: print "shift#1" breakPT = False shiftPT = True #shift or break if isRecTimerWakeup or shiftPT or breakPT \ or NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - now) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - now) <= 900: if self.repeated and not RBsave: self.savebegin = self.begin self.saveend = self.end RBsave = True if not breakPT: self.do_backoff() #check difference begin to end before shift begin time if RBsave and self.end - self.begin > 3 and self.end - now - self.backoff <= 240: breakPT = True #breakPT if breakPT: if self.repeated and RBsave: try: self.begin = self.savebegin self.end = self.saveend except: pass RBsave = False return True # retry oldbegin = self.begin self.begin = int(now) + self.backoff if abs(self.end - oldbegin) <= 3: self.end = self.begin else: if not self.repeated and self.end < self.begin + 300: self.end = self.begin + 300 return False elif not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if self.repeated and RBsave: try: self.begin = self.savebegin self.end = self.saveend except: pass if Screens.Standby.inStandby: # in standby print "[PowerTimer] quitMainloop #3" quitMainloop(2) else: Notifications.AddNotificationWithCallback(self.sendTryToRebootNotification, MessageBox, _("A finished powertimer wants to reboot your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()), timeout = 180) RBsave = False return True elif self.timerType == TIMERTYPE.DEEPSTANDBY: if debug: print "self.timerType == TIMERTYPE.DEEPSTANDBY:" #check priority prioPT = [TIMERTYPE.WAKEUP,TIMERTYPE.WAKEUPTOSTANDBY,TIMERTYPE.DEEPSTANDBY] prioPTae = [AFTEREVENT.WAKEUP,AFTEREVENT.WAKEUPTOSTANDBY,AFTEREVENT.DEEPSTANDBY] shiftPT,breakPT = self.getPriorityCheck(prioPT,prioPTae) #a timer with higher priority was shifted - no execution of current timer if False: if debug: print "break#1" breakPT = True #a timer with lower priority was shifted - shift now current timer and wait for restore the saved time values from other timer if RSsave or RBsave or aeDSsave: if debug: print "shift#1" breakPT = False shiftPT = True #shift or break if isRecTimerWakeup or shiftPT or breakPT \ or NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - now) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - now) <= 900: if self.repeated and not DSsave: self.savebegin = self.begin self.saveend = self.end DSsave = True if not breakPT: self.do_backoff() #check difference begin to end before shift begin time if DSsave and self.end - self.begin > 3 and self.end - now - self.backoff <= 240: breakPT = True #breakPT if breakPT: if self.repeated and DSsave: try: self.begin = self.savebegin self.end = self.saveend except: pass DSsave = False return True # retry oldbegin = self.begin self.begin = int(now) + self.backoff if abs(self.end - oldbegin) <= 3: self.end = self.begin else: if not self.repeated and self.end < self.begin + 300: self.end = self.begin + 300 return False elif not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if self.repeated and DSsave: try: self.begin = self.savebegin self.end = self.saveend except: pass if Screens.Standby.inStandby: # in standby print "[PowerTimer] quitMainloop #2" quitMainloop(1) else: Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A finished powertimer wants to shutdown your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()), timeout = 180) DSsave = False return True elif next_state == self.StateEnded: if self.afterEvent == AFTEREVENT.WAKEUP: if Screens.Standby.inStandby: Screens.Standby.inStandby.Power() elif self.afterEvent == AFTEREVENT.STANDBY: if not Screens.Standby.inStandby: # not already in standby Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A finished powertimer wants to set your\n%s %s to standby. Do that now?") % (getMachineBrand(), getMachineName()), timeout = 180) elif self.afterEvent == AFTEREVENT.DEEPSTANDBY: if debug: print "self.afterEvent == AFTEREVENT.DEEPSTANDBY:" #check priority prioPT = [TIMERTYPE.WAKEUP,TIMERTYPE.WAKEUPTOSTANDBY,TIMERTYPE.DEEPSTANDBY] prioPTae = [AFTEREVENT.WAKEUP,AFTEREVENT.WAKEUPTOSTANDBY,AFTEREVENT.DEEPSTANDBY] shiftPT,breakPT = self.getPriorityCheck(prioPT,prioPTae) #a timer with higher priority was shifted - no execution of current timer if DSsave: if debug: print "break#1" breakPT = True #a timer with lower priority was shifted - shift now current timer and wait for restore the saved time values if RSsave or RBsave: if debug: print "shift#1" breakPT = False shiftPT = True #shift or break runningPT = False #option: check other powertimer is running (current disabled) #runningPT = NavigationInstance.instance.PowerTimer.isProcessing(exceptTimer = TIMERTYPE.NONE, endedTimer = self.timerType) if isRecTimerWakeup or shiftPT or breakPT or runningPT \ or NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - now) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - now) <= 900: if self.repeated and not aeDSsave: self.savebegin = self.begin self.saveend = self.end aeDSsave = True if not breakPT: self.do_backoff() #breakPT if breakPT: if self.repeated and aeDSsave: try: self.begin = self.savebegin self.end = self.saveend except: pass aeDSsave = False return True # retry self.end = int(now) + self.backoff return False elif not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if self.repeated and aeDSsave: try: self.begin = self.savebegin self.end = self.saveend except: pass if Screens.Standby.inStandby: # in standby print "[PowerTimer] quitMainloop #5" quitMainloop(1) else: Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A finished powertimer wants to shutdown your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()), timeout = 180) aeDSsave = False NavigationInstance.instance.PowerTimer.saveTimer() resetTimerWakeup() return True
def keypress(self, key=None, flag=1): if flag and self.wasInStandby: self.wasInStandby = False eActionMap.getInstance().unbindAction('', self.keypress)
def messageReceivedKey(address, message): logcmd = "[VTI HDMI-CEC] received cec message part two %x from %x" % ( message, address) if logcmd: if config.hdmicec.logenabledserial.value: print logcmd if config.hdmicec.logenabledfile.value: filelog = "echo %s >> /tmp/hdmicec.log" % (logcmd) system(filelog) if config.hdmicec.enabled.value is True: rcdevicename = iInputDevices.getDeviceName( 'event0') # hschang : get rc device name, /dev/input/event0 keyaction = eActionMap.getInstance() key = None #start translate keycodes if message == 0x32 or message == 0x09: #key menu key = int(139) elif message == 0x20: #key 0 key = int(11) elif message == 0x21: #key 1 key = int(2) elif message == 0x22: #key 2 key = int(3) elif message == 0x23: #key 3 key = int(4) elif message == 0x24: #key 4 key = int(5) elif message == 0x25: #key 5 key = int(6) elif message == 0x26: #key 6 key = int(7) elif message == 0x27: #key 7 key = int(8) elif message == 0x28: #key 8 key = int(9) elif message == 0x29: #key 10 key = int(10) elif message == 0x30: #key bouquet up key = int(402) elif message == 0x31: #key bouquet down key = int(403) elif message == 0x53: #key info/epg key = int(358) elif message == 0x00: #key ok key = int(352) elif message == 0x03: #key left key = int(105) elif message == 0x04: #key right key = int(106) elif message == 0x01: #key up key = int(103) elif message == 0x02: #key down key = int(108) elif message == 0x0d: #key exit key = int(174) elif message == 0x72: #key red key = int(398) elif message == 0x71: #key blue key = int(401) elif message == 0x73: #key green key = int(399) elif message == 0x74: #key yellow key = int(400) elif message == 0x44: #key play if rcdevicename.find("advanced"): key = int(164) # KEY_PLAYPAUSE else: key = int(207) # KEY_PLAY elif message == 0x46: #key pause if rcdevicename.find("advanced"): key = int(164) # KEY_PLAYPAUSE else: key = int(119) # KEY_PAUSE elif message == 0x45: #key stop key = int(128) elif message == 0x47: #key record key = int(167) elif message == 0x49: #fast forward if rcdevicename.find("advanced"): key = int(163) # KEY_NEXTSONG else: key = int(208) # KEY_FASTFORWARD elif message == 0x48: #rewind if rcdevicename.find("advanced"): key = int(165) # KEY_NEXTSONG else: key = int(168) # KEY_FASTFORWARD elif message == 0x60: #play 2 key = int(207) elif message == 0x61: #key pause 2 if rcdevicename.find("advanced"): key = int(164) # KEY_PLAYPAUSE else: key = int(119) # KEY_PAUSE elif message == 0x64: #key stop 2 key = int(128) elif message == 0x62: #key record 2 key = int(167) #end translate keycodes if key: keyaction.keyPressed(rcdevicename, key, int(0)) keyaction.keyPressed(rcdevicename, key, int(1))
def activate(self): next_state = self.state + 1 self.log(5, "activating state %d" % next_state) if next_state == 1 and (self.timerType == TIMERTYPE.AUTOSTANDBY or self.timerType == TIMERTYPE.AUTODEEPSTANDBY): eActionMap.getInstance().bindAction('', -0x7FFFFFFF, self.keyPressed) self.begin = time() + int(self.autosleepdelay)*60 if self.end <= self.begin: self.end = self.begin if next_state == self.StatePrepared: self.log(6, "prepare ok, waiting for begin") self.next_activation = self.begin self.backoff = 0 return True elif next_state == self.StateRunning: self.wasPowerTimerWakeup = False if os.path.exists("/tmp/was_timer_wakeup"): self.wasPowerTimerWakeup = int(open("/tmp/was_powertimer_wakeup", "r").read()) and True or False os.remove("/tmp/was_powertimer_wakeup") # if this timer has been cancelled, just go to "end" state. if self.cancelled: return True if self.failed: return True if self.timerType == TIMERTYPE.WAKEUP: if Screens.Standby.inStandby: Screens.Standby.inStandby.Power() return True elif self.timerType == TIMERTYPE.WAKEUPTOSTANDBY: return True elif self.timerType == TIMERTYPE.STANDBY: if not Screens.Standby.inStandby: # not already in standby Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("Your STB_BOX wants to set your STB_BOX to standby.\nDo that now?"), timeout = 180) return True elif self.timerType == TIMERTYPE.AUTOSTANDBY: if not Screens.Standby.inStandby: # not already in standby Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("Your STB_BOX wants to set your STB_BOX to standby.\nDo that now?"), timeout = 180) if self.autosleeprepeat == "once": eActionMap.getInstance().unbindAction('', self.keyPressed) return True else: self.begin = time() + int(self.autosleepdelay)*60 if self.end <= self.begin: self.end = self.begin else: self.begin = time() + int(self.autosleepdelay)*60 if self.end <= self.begin: self.end = self.begin elif self.timerType == TIMERTYPE.AUTODEEPSTANDBY: if (NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900) or (self.autosleepinstandbyonly == 'yes' and not Screens.Standby.inStandby): self.do_backoff() # retry self.begin = time() + self.backoff if self.end <= self.begin: self.end = self.begin return False if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if Screens.Standby.inStandby: # in standby quitMainloop(1) return True else: Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("Your STB_BOX wants to shut down your STB_BOX.\nDo that now?"), timeout = 180) if self.autosleeprepeat == "once": eActionMap.getInstance().unbindAction('', self.keyPressed) return True else: self.begin = time() + int(self.autosleepdelay)*60 if self.end <= self.begin: self.end = self.begin elif self.timerType == TIMERTYPE.DEEPSTANDBY and self.wasPowerTimerWakeup: return True elif self.timerType == TIMERTYPE.DEEPSTANDBY and not self.wasPowerTimerWakeup: if NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900: self.do_backoff() # retry self.begin = time() + self.backoff if self.end <= self.begin: self.end = self.begin return False if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if Screens.Standby.inStandby: # in standby quitMainloop(1) else: Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("Your STB_BOX wants to shut down your STB_BOX.\nDo that now?"), timeout = 180) return True elif self.timerType == TIMERTYPE.REBOOT: if NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900: self.do_backoff() # retry self.begin = time() + self.backoff if self.end <= self.begin: self.end = self.begin return False if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if Screens.Standby.inStandby: # in standby quitMainloop(2) else: Notifications.AddNotificationWithCallback(self.sendTryToRebootNotification, MessageBox, _("Your STB_BOX wants to reboot your STB_BOX.\nDo that now?"), timeout = 180) return True elif self.timerType == TIMERTYPE.RESTART: if NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900: self.do_backoff() # retry self.begin = time() + self.backoff if self.end <= self.begin: self.end = self.begin return False if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if Screens.Standby.inStandby: # in standby quitMainloop(3) else: Notifications.AddNotificationWithCallback(self.sendTryToRestartNotification, MessageBox, _("Your STB_BOX wants to restart the user interface.\nDo that now?"), timeout = 180) return True elif next_state == self.StateEnded: old_end = self.end NavigationInstance.instance.PowerTimer.saveTimer() if self.afterEvent == AFTEREVENT.STANDBY: if not Screens.Standby.inStandby: # not already in standby Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A finished powertimer wants to set your\nSTB_BOX to standby. Do that now?"), timeout = 180) elif self.afterEvent == AFTEREVENT.DEEPSTANDBY: if NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900: self.do_backoff() # retry self.begin = time() + self.backoff if self.end <= self.begin: self.end = self.begin return False if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if Screens.Standby.inStandby: # in standby quitMainloop(1) else: Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A finished power timer wants to shut down\nyour STB_BOX. Shutdown now?"), timeout = 180) return True
def setWasInStandby(): if not RecordTimerEntry.wasInStandby: if not RecordTimerEntry.wasInDeepStandby: eActionMap.getInstance().bindAction('', -maxint - 1, RecordTimerEntry.keypress) RecordTimerEntry.wasInDeepStandby = False RecordTimerEntry.wasInStandby = True
def standbyCounterChanged(self, configElement): Screens.Standby.inStandby.onClose.append(self.leaveStandby) self.autoDimDownLCDTimer.stop() self.autoDimUpLCDTimer.stop() eActionMap.getInstance().unbindAction('', self.DimUpEvent)