From 3db964eee299eae5c98a48753a096fe7786af29a Mon Sep 17 00:00:00 2001 From: Felix Domke Date: Wed, 30 Nov 2005 00:16:24 +0000 Subject: [PATCH] add notifications --- RecordTimer.py | 16 +++++++++++++--- lib/python/Screens/InfoBar.py | 12 +++++++----- lib/python/Screens/InfoBarGenerics.py | 24 +++++++++++++++++++++++- lib/python/Screens/Screen.py | 16 +++++++++++++++- lib/python/Tools/Makefile.am | 2 +- lib/python/Tools/Notifications.py | 13 +++++++++++++ lib/python/Tools/__init__.py | 2 +- 7 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 lib/python/Tools/Notifications.py diff --git a/RecordTimer.py b/RecordTimer.py index d893382a..e42c168f 100644 --- a/RecordTimer.py +++ b/RecordTimer.py @@ -1,11 +1,12 @@ import time import codecs #from time import datetime -from Tools import Directories +from Tools import Directories, Notifications import timer import xml.dom.minidom +from Screens.MessageBox import MessageBox import NavigationInstance from Tools.XMLTools import elementsWithTag @@ -63,12 +64,14 @@ class RecordTimerEntry(timer.TimerEntry): if self.record_service == None: print "timer record failed." else: - self.record_service.prepare(self.Filename + ".ts") + if self.record_service.prepare(self.Filename + ".ts"): + # error. + Notifications.AddNotificationWithCallback(self.failureCB, MessageBox, _("A timer failed to record!\nReason: unknown.")) + f = open(self.Filename + ".ts.meta", "w") f.write(str(self.service_ref) + "\n") f.write(self.epg_data + "\n") del f - elif self.record_service == None: if event != self.EventAbort: print "timer record start failed, can't finish recording." @@ -80,6 +83,11 @@ class RecordTimerEntry(timer.TimerEntry): self.record_service = None print "Timer successfully ended" + def failureCB(self, answer): + if answer == True: + print "kill user to record" + else: + print "user killed record" def createTimer(xml): begin = int(xml.getAttribute("begin")) @@ -158,6 +166,8 @@ class RecordTimer(timer.Timer): entry.repeated = False + entry.repeated = False + if entry.state == timer.TimerEntry.StateRunning: print "remove running timer." entry.end = time.time() diff --git a/lib/python/Screens/InfoBar.py b/lib/python/Screens/InfoBar.py index 62e4fcd2..3ddb1c3c 100644 --- a/lib/python/Screens/InfoBar.py +++ b/lib/python/Screens/InfoBar.py @@ -7,10 +7,12 @@ from Components.Clock import Clock from Components.ActionMap import ActionMap from Components.ServicePosition import ServicePosition +from Tools.Notifications import AddNotificationWithCallback + from Screens.InfoBarGenerics import InfoBarVolumeControl, InfoBarShowHide, \ InfoBarPowerKey, InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, \ InfoBarEPG, InfoBarEvent, InfoBarServiceName, InfoBarPVR, InfoBarInstantRecord, \ - InfoBarAudioSelection, InfoBarAdditionalInfo + InfoBarAudioSelection, InfoBarAdditionalInfo, InfoBarNotifications from Screens.HelpMenu import HelpableScreen, HelpMenu @@ -21,7 +23,7 @@ import time class InfoBar(Screen, InfoBarVolumeControl, InfoBarShowHide, InfoBarPowerKey, InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarEPG, InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord, InfoBarAudioSelection, - HelpableScreen, InfoBarAdditionalInfo): + HelpableScreen, InfoBarAdditionalInfo, InfoBarNotifications): def __init__(self, session): Screen.__init__(self, session) @@ -35,7 +37,7 @@ class InfoBar(Screen, InfoBarVolumeControl, InfoBarShowHide, InfoBarPowerKey, InfoBarVolumeControl, InfoBarShowHide, InfoBarPowerKey, \ InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarEPG, \ InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord, InfoBarAudioSelection, \ - InfoBarAdditionalInfo: + InfoBarAdditionalInfo, InfoBarNotifications: x.__init__(self) self.helpList.append((self["actions"], "InfobarActions", [("showMovies", "Watch a Movie...")])) @@ -51,7 +53,7 @@ class InfoBar(Screen, InfoBarVolumeControl, InfoBarShowHide, InfoBarPowerKey, class MoviePlayer(Screen, InfoBarVolumeControl, InfoBarShowHide, InfoBarPowerKey, \ InfoBarMenu, \ - InfoBarServiceName, InfoBarPVR, InfoBarAudioSelection, HelpableScreen): + InfoBarServiceName, InfoBarPVR, InfoBarAudioSelection, HelpableScreen, InfoBarNotifications): def __init__(self, session, service): Screen.__init__(self, session) @@ -61,7 +63,7 @@ class MoviePlayer(Screen, InfoBarVolumeControl, InfoBarShowHide, InfoBarPowerKey "leavePlayer": self.leavePlayer }) - for x in HelpableScreen, InfoBarVolumeControl, InfoBarShowHide, InfoBarPowerKey, InfoBarMenu, InfoBarServiceName, InfoBarPVR, InfoBarAudioSelection: + for x in HelpableScreen, InfoBarVolumeControl, InfoBarShowHide, InfoBarPowerKey, InfoBarMenu, InfoBarServiceName, InfoBarPVR, InfoBarAudioSelection, InfoBarNotifications: x.__init__(self) self["CurrentTime"] = ServicePosition(self.session.nav, ServicePosition.TYPE_REMAINING) diff --git a/lib/python/Screens/InfoBarGenerics.py b/lib/python/Screens/InfoBarGenerics.py index 978a1134..c1842796 100644 --- a/lib/python/Screens/InfoBarGenerics.py +++ b/lib/python/Screens/InfoBarGenerics.py @@ -20,6 +20,8 @@ from Screens.Mute import Mute from Screens.Standby import Standby from Screens.EventView import EventView +from Tools import Notifications + #from enigma import eTimer, eDVBVolumecontrol, quitMainloop from enigma import * @@ -522,4 +524,24 @@ class InfoBarAdditionalInfo: self["ButtonRedText"] = Label(_("Record")) self["ButtonGreen"] = Pixmap() self["ButtonYellow"] = Pixmap() - self["ButtonBlue"] = Pixmap() \ No newline at end of file + self["ButtonBlue"] = Pixmap() + +class InfoBarNotifications: + def __init__(self): + self.onExecBegin.append(self.checkNotifications) + Notifications.notificationAdded.append(self.checkNotificationsIfExecing) + + def checkNotificationsIfExecing(self): + if self.execing: + self.checkNotifications() + + def checkNotifications(self): + if len(Notifications.notifications): + n = Notifications.notifications[0] + Notifications.notifications = Notifications.notifications[1:] + print "open",n + cb = n[0] + if cb is not None: + self.session.openWithCallback(cb, *n[1:]) + else: + self.session.open(*n[1:]) diff --git a/lib/python/Screens/Screen.py b/lib/python/Screens/Screen.py index 13e31d67..231cbfaa 100644 --- a/lib/python/Screens/Screen.py +++ b/lib/python/Screens/Screen.py @@ -15,26 +15,40 @@ class Screen(dict, HTMLSkin, GUISkin): self.onExecBegin = [ ] self.onShown = [ ] + self.execing = False + # in order to support screens *without* a help, # we need the list in every screen. how ironic. self.helpList = [ ] def execBegin(self): + self.active_components = [ ] for x in self.onExecBegin: x() + if self.session.currentDialog != self: + return + # assert self.session == None, "a screen can only exec one per time" # self.session = session + for (name, val) in self.items(): val.execBegin() + if self.session.currentDialog != self: + return + self.active_components.append(val) + self.execing = True + for x in self.onShown: x() def execEnd(self): - for (name, val) in self.items(): +# for (name, val) in self.items(): + for val in self.active_components: val.execEnd() # assert self.session != None, "execEnd on non-execing screen!" # self.session = None + self.execing = False # never call this directly - it will be called from the session! def doClose(self): diff --git a/lib/python/Tools/Makefile.am b/lib/python/Tools/Makefile.am index d2054589..bee4dde1 100644 --- a/lib/python/Tools/Makefile.am +++ b/lib/python/Tools/Makefile.am @@ -1,4 +1,4 @@ installdir = $(LIBDIR)/enigma2/python/Tools install_DATA = \ - FuzzyDate.py XMLTools.py Directories.py NumericalTextInput.py KeyBindings.py BoundFunction.py ISO639.py __init__.py + FuzzyDate.py XMLTools.py Directories.py NumericalTextInput.py KeyBindings.py BoundFunction.py ISO639.py Notifications.py __init__.py diff --git a/lib/python/Tools/Notifications.py b/lib/python/Tools/Notifications.py new file mode 100644 index 00000000..b547639b --- /dev/null +++ b/lib/python/Tools/Notifications.py @@ -0,0 +1,13 @@ + +notifications = [ ] + +notificationAdded = [ ] + +def AddNotification(screen, *args): + AddNotificationWithCallback(None, screen, *args) + +def AddNotificationWithCallback(fnc, screen, *args): + notifications.append((fnc, screen) + args) + for x in notificationAdded: + x() + diff --git a/lib/python/Tools/__init__.py b/lib/python/Tools/__init__.py index 2d7c2efa..df963dad 100644 --- a/lib/python/Tools/__init__.py +++ b/lib/python/Tools/__init__.py @@ -1 +1 @@ -all = ["FuzzyDate.py", "XMLTools.py", "Directories.py", "KeyBindings.py", "BoundFunction.py", "ISO639.py"] +all = ["FuzzyDate.py", "XMLTools.py", "Directories.py", "KeyBindings.py", "BoundFunction.py", "ISO639.py", "Notifications"] -- 2.30.2