-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPython_Notification.py
43 lines (30 loc) · 1.18 KB
/
Python_Notification.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Drawing import Icon
from System.Windows.Forms import (Application, ContextMenu, MenuItem, NotifyIcon)
class Notification(object):
def __init__(self):
self.initNotifyIcon()
self.showBalloon("Saving...", "Your DVD is being archived")
def initNotifyIcon(self):
self.notifyIcon = NotifyIcon()
self.notifyIcon.Icon = Icon("dvd.ico")
self.notifyIcon.Visible = True
self.notifyIcon.ContextMenu = self.initContextMenu()
def showBalloon(self, title, text, duration=1000):
self.notifyIcon.BalloonTipTitle = title
self.notifyIcon.BalloonTipText = text
self.notifyIcon.ShowBalloonTip(duration)
def initContextMenu(self):
contextMenu = ContextMenu()
exitMenuItem = MenuItem("Exit")
exitMenuItem.Click += self.onExit
contextMenu.MenuItems.Add(exitMenuItem)
return contextMenu
def onExit(self, sender, event):
self.notifyIcon.Visible = False
Application.Exit()
if __name__ == "__main__":
main = Notification()
Application.Run()