-
Notifications
You must be signed in to change notification settings - Fork 0
/
toast_notification.py
47 lines (36 loc) · 1.56 KB
/
toast_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
44
45
46
47
from win32api import *
from win32gui import *
import win32con
import sys, os
import struct
import time
# Class
class WindowsBalloonTip:
def __init__(self):
message_map = { win32con.WM_DESTROY: self.OnDestroy,}
# Register the window class.
wc = WNDCLASS()
self.hinst = wc.hInstance = GetModuleHandle(None)
wc.lpszClassName = 'PythonTaskbar'
wc.lpfnWndProc = message_map # could also specify a wndprocab.
self.classAtom = RegisterClass(wc)
def OnDestroy(self, hwnd, msg, wparam, lparam):
nid = (self.hwnd, 0)
Shell_NotifyIcon(NIM_DELETE, nid)
PostQuitMessage(0)
def balloon_tip(self,title, msg):
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
hwnd = CreateWindow(self.classAtom, "Taskbar",style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, self.hinst, None)
UpdateWindow(hwnd)
hicon = LoadIcon(0, win32con.IDI_APPLICATION)
flags =NIF_ICON | NIF_MESSAGE | NIF_TIP
nid = (hwnd, 0, flags, win32con.WM_USER+20, hicon, 'Tooltip')
Shell_NotifyIcon(NIM_ADD, nid)
Shell_NotifyIcon(NIM_MODIFY, (hwnd, 0, NIF_INFO, win32con.WM_USER+20, hicon, 'Balloon Tooltip', msg, 200, title,NIIF_INFO))
time.sleep(1)
# Main
if __name__ == '__main__':
# Example
w=WindowsBalloonTip()
w.balloon_tip('Bandwith Usage', 'Chrome.exe seem to use 80% of Bandwith.')
w.balloon_tip('Bandwith Usage', 'Steam.exe seem to use 50% of Bandwith.')