Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from win10toast import ToastNotifier
- from threading import Thread
- from time import sleep
- class Line:
- def __init__(self):
- self.line = []
- self.kill_thread = False
- self.notifier_thread = Thread(target=self.notifier)
- self.notifier_thread.start()
- def append(self, item: dict):
- """
- :item: notification settings. {title: value, message: value, duration: value, icon_path: value}
- """
- self.line.append(item)
- def destroy(self):
- self.kill_thread = True
- def notifier(self):
- while True:
- if self.line:
- item = self.line[0]
- self.line.remove(item)
- toast = self.notify(item['title'], item['message'], item['duration'], item['icon_path'])
- while toast.notification_active():
- sleep(1)
- else:
- if self.kill_thread:
- exit(0)
- sleep(0.1)
- @staticmethod
- def notify(title: str, message: str, duration: int, icon_path: str):
- toast = ToastNotifier()
- toast.show_toast(title=title, msg=message, duration=duration, icon_path=icon_path, threaded=True)
- return toast
- line = Line()
- # The following notifications will be displayed one by one
- line.append({
- 'title': 'title',
- 'message': '1',
- 'duration': 10,
- 'icon_path': None
- })
- line.append({
- 'title': 'title',
- 'message': '2',
- 'duration': 10,
- 'icon_path': None
- })
- line.destroy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement