85452e11a3301d3b3b6a4cf3aac9e03180fa5c89
[enigma2.git] / lib / python / Tools / Notifications.py
1
2 notifications = [ ]
3
4 notificationAdded = [ ]
5
6
7 # notifications which are currently on screen (and might be closed by similiar notifications)
8 current_notifications = [ ]
9
10 def __AddNotification(fnc, screen, id, *args, **kwargs):
11         notifications.append((fnc, screen, args, kwargs, id))
12         for x in notificationAdded:
13                 x()
14
15 def AddNotification(screen, *args, **kwargs):
16         AddNotificationWithCallback(None, screen, *args, **kwargs)
17
18 def AddNotificationWithCallback(fnc, screen, *args, **kwargs):
19         __AddNotification(fnc, screen, None, *args, **kwargs)
20
21 def AddNotificationWithID(id, screen, *args, **kwargs):
22         __AddNotification(None, screen, id, *args, **kwargs)
23
24 # we don't support notifications with callback and ID as this
25 # would require manually calling the callback on cancelled popups.
26
27 def RemovePopup(id):
28         # remove similiar notifications
29         print "RemovePopup, id =", id
30         for x in notifications:
31                 if x[4] and x[4] == id:
32                         print "(found in notifications)"
33                         notifications.remove(x)
34
35         for x in current_notifications:
36                 if x[0] == id:
37                         print "(found in current notifications)"
38                         x[1].close()
39
40 def AddPopup(text, type, timeout, id = None):
41         if id is not None:
42                 RemovePopup(id)
43         from Screens.MessageBox import MessageBox
44         print "AddPopup, id =", id
45         AddNotificationWithID(id, MessageBox, text = text, type = type, timeout = timeout)