25 lines
576 B
Python
25 lines
576 B
Python
# Copyright 2019 (c) Anna Schumaker.
|
|
|
|
class Notify:
|
|
notifications = {}
|
|
|
|
def __init__(self):
|
|
raise NotImplementedError
|
|
|
|
def clear():
|
|
Notify.notifications.clear()
|
|
|
|
def notify(name, *args):
|
|
for func in Notify.notifications.get(name, []):
|
|
func(*args)
|
|
|
|
def notify_cancel(name, func):
|
|
cb = Notify.notifications.get(name, [])
|
|
if func in cb:
|
|
cb.remove(func)
|
|
|
|
def notify_me(name, func):
|
|
cb = Notify.notifications.setdefault(name, [])
|
|
if not func in cb:
|
|
cb.append(func)
|