Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. from win10toast import ToastNotifier
  2. from threading import Thread
  3. from time import sleep
  4.  
  5.  
  6. class Line:
  7. def __init__(self):
  8. self.line = []
  9. self.kill_thread = False
  10. self.notifier_thread = Thread(target=self.notifier)
  11. self.notifier_thread.start()
  12.  
  13. def append(self, item: dict):
  14. """
  15. :item: notification settings. {title: value, message: value, duration: value, icon_path: value}
  16. """
  17. self.line.append(item)
  18.  
  19. def destroy(self):
  20. self.kill_thread = True
  21.  
  22. def notifier(self):
  23. while True:
  24. if self.line:
  25. item = self.line[0]
  26. self.line.remove(item)
  27.  
  28. toast = self.notify(item['title'], item['message'], item['duration'], item['icon_path'])
  29.  
  30. while toast.notification_active():
  31. sleep(1)
  32.  
  33. else:
  34. if self.kill_thread:
  35. exit(0)
  36.  
  37. sleep(0.1)
  38.  
  39. @staticmethod
  40. def notify(title: str, message: str, duration: int, icon_path: str):
  41. toast = ToastNotifier()
  42. toast.show_toast(title=title, msg=message, duration=duration, icon_path=icon_path, threaded=True)
  43.  
  44. return toast
  45.  
  46.  
  47. line = Line()
  48. # The following notifications will be displayed one by one
  49. line.append({
  50. 'title': 'title',
  51. 'message': '1',
  52. 'duration': 10,
  53. 'icon_path': None
  54. })
  55. line.append({
  56. 'title': 'title',
  57. 'message': '2',
  58. 'duration': 10,
  59. 'icon_path': None
  60. })
  61.  
  62. line.destroy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement