X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/9f8ba87f60249139f18f10ab4ba84b187a97da33..952b0b0786797f21c603f7e8eaaed69c0e30ef78:/lib/python/Tools/Notifications.py diff --git a/lib/python/Tools/Notifications.py b/lib/python/Tools/Notifications.py index 3cb107cc..0410a4e2 100644 --- a/lib/python/Tools/Notifications.py +++ b/lib/python/Tools/Notifications.py @@ -3,10 +3,43 @@ notifications = [ ] notificationAdded = [ ] +# notifications which are currently on screen (and might be closed by similiar notifications) +current_notifications = [ ] + +def __AddNotification(fnc, screen, id, *args, **kwargs): + notifications.append((fnc, screen, args, kwargs, id)) + for x in notificationAdded: + x() + def AddNotification(screen, *args, **kwargs): AddNotificationWithCallback(None, screen, *args, **kwargs) def AddNotificationWithCallback(fnc, screen, *args, **kwargs): - notifications.append((fnc, screen, args, kwargs)) - for x in notificationAdded: - x() + __AddNotification(fnc, screen, None, *args, **kwargs) + +def AddNotificationWithID(id, screen, *args, **kwargs): + __AddNotification(None, screen, id, *args, **kwargs) + +# we don't support notifications with callback and ID as this +# would require manually calling the callback on cancelled popups. + +def RemovePopup(id): + # remove similiar notifications + print "RemovePopup, id =", id + for x in notifications: + if x[4] and x[4] == id: + print "(found in notifications)" + notifications.remove(x) + + for x in current_notifications: + if x[0] == id: + print "(found in current notifications)" + x[1].close() + +from Screens.MessageBox import MessageBox + +def AddPopup(text, type, timeout, id = None): + if id is not None: + RemovePopup(id) + print "AddPopup, id =", id + AddNotificationWithID(id, MessageBox, text = text, type = type, timeout = timeout, close_on_any_key = True)