def __init__(self): # Register window class; it's okay to do this multiple times wc = WNDCLASS() wc.lpszClassName = "ServoTaskbarNotification" wc.lpfnWndProc = {win32con.WM_DESTROY: self.OnDestroy} self.classAtom = RegisterClass(wc) self.hinst = wc.hInstance = GetModuleHandle(None)
def __init__(self, icon_path, msg_q): """Initialize.""" self.visible = 0 self.log = [] self._thread = None self.msg_q = msg_q self.message_box = Mbox() message_map = { WM_DESTROY: self.onDestroy, WM_USER + 20: self.onTaskbarNotify, } wc = WNDCLASS() hinst = wc.hInstance = GetModuleHandle(None) icon_flags = LR_LOADFROMFILE | LR_DEFAULTSIZE try: self.hicon = LoadImage(hinst, os.path.realpath(icon_path), IMAGE_ICON, 0, 0, icon_flags) except Exception as e: print(str(e)) self.hicon = LoadIcon(0, IDI_APPLICATION) wc.lpszClassName = str("Trustbase_notification") #lol wc.style = CS_VREDRAW | CS_HREDRAW #wc.hCursor = win32gui.LoadCursor( 0, win32con.IDC_ARROW ) wc.hbrBackground = COLOR_WINDOW wc.lpfnWndProc = message_map # could also specify a wndproc. classAtom = RegisterClass(wc) # Create the Window. style = WS_OVERLAPPED | WS_SYSMENU self.hwnd = CreateWindow( classAtom, "MITM_alert", style, \ 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, \ 0, 0, hinst, None) UpdateWindow(self.hwnd) self.notification_id = 1 self.show()
def __init__(self): # Register window class; it's okay to do this multiple times wc = WNDCLASS() wc.lpszClassName = 'ServoTaskbarNotification' wc.lpfnWndProc = { win32con.WM_DESTROY: self.OnDestroy, } self.classAtom = RegisterClass(wc) self.hinst = wc.hInstance = GetModuleHandle(None)
def __init__(self): """Initialize.""" message_map = {WM_DESTROY: self.on_destroy, } # Register the window class. wc = WNDCLASS() self.hinst = wc.hInstance = GetModuleHandle(None) wc.lpszClassName = str("PythonTaskbar") # must be a string wc.lpfnWndProc = message_map # could also specify a wndproc. self.classAtom = RegisterClass(wc)
def __init__(self): """Initialize.""" message_map = {WM_DESTROY: self.on_destroy} # Register the window class. wc = WNDCLASS() self.hinst = wc.hInstance = GetModuleHandle(None) wc.lpszClassName = str("PythonTaskbar") # must be a string wc.lpfnWndProc = message_map # could also specify a wndproc. self.classAtom = RegisterClass(wc)
def __init__(self, message, title): message_map = {win32con.WM_DESTROY: self.OnDestroy} # Register the Window class. wc = WNDCLASS() hinst = wc.hInstance = GetModuleHandle(None) wc.lpszClassName = "PythonTaskbar" wc.lpfnWndProc = message_map # could also specify a wndproc. classAtom = RegisterClass(wc) # Create the Window. style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = CreateWindow( classAtom, "Taskbar", style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None, ) UpdateWindow(self.hwnd) iconPathName = os.path.abspath( os.path.join(sys.path[0], "balloontip.ico")) icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE try: hicon = LoadImage(hinst, iconPathName, win32con.IMAGE_ICON, 0, 0, icon_flags) except: hicon = LoadIcon(0, win32con.IDI_APPLICATION) flags = NIF_ICON | NIF_MESSAGE | NIF_TIP nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, hicon, "tooltip") Shell_NotifyIcon(NIM_ADD, nid) Shell_NotifyIcon( NIM_MODIFY, ( self.hwnd, 0, NIF_INFO, win32con.WM_USER + 20, hicon, "Balloon tooltip", message, 200, title, ), ) time.sleep(10) DestroyWindow(self.hwnd) UnregisterClass(classAtom, hinst)
from abc import ABC from typing import final from win32api import GetModuleHandle from win32con import CW_USEDEFAULT, IMAGE_ICON, LR_DEFAULTSIZE, LR_LOADFROMFILE, WM_USER, \ WS_OVERLAPPED, WS_SYSMENU from win32gui import CreateWindow, DestroyWindow, LoadImage, NIF_ICON, NIF_INFO, NIF_MESSAGE, NIF_TIP, NIM_ADD, \ NIM_MODIFY, NIM_DELETE, RegisterClass, Shell_NotifyIcon, UpdateWindow, WNDCLASS from i18n import I18N_RESOURCES _wnd_class = WNDCLASS() _wnd_class.hInstance = GetModuleHandle(None) _wnd_class.lpszClassName = 'Railway Station Simulator' _wnd_class.lpfnWndProc = {} _wnd_class_instance = RegisterClass(_wnd_class) class Notification(ABC): def __init__(self, logger, caption_key, message_key, current_locale, caption_args=(), message_args=()): self.logger = logger self.handler = CreateWindow(_wnd_class_instance, "Taskbar", WS_OVERLAPPED | WS_SYSMENU, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, _wnd_class.hInstance, None)
def __call__(self, summary, message="", timeout=2000, **kwargs): tip = kwargs.get("tip", "Balloon tooltip") # Register the Window class. wc = WNDCLASS() hinst = wc.hInstance = GetModuleHandle(None) wc.lpszClassName = "PythonTaskbar" wc.lpfnWndProc = self.message_map # could also specify a wndproc. classAtom = RegisterClass(wc) # Create the Window. style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = CreateWindow( classAtom, "Taskbar", style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None, ) UpdateWindow(self.hwnd) # Icons managment iconPathName = os.path.abspath( os.path.join(sys.path[0], "balloontip.ico")) icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE try: hicon = LoadImage(hinst, iconPathName, win32con.IMAGE_ICON, 0, 0, icon_flags) except Exception: hicon = LoadIcon(0, win32con.IDI_APPLICATION) flags = NIF_ICON | NIF_MESSAGE | NIF_TIP nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, hicon, "tooltip") # Notify Shell_NotifyIcon(NIM_ADD, nid) Shell_NotifyIcon( NIM_MODIFY, ( self.hwnd, 0, NIF_INFO, win32con.WM_USER + 20, hicon, tip, message, timeout, summary, ), ) # Destroy DestroyWindow(self.hwnd) classAtom = UnregisterClass(classAtom, hinst) return True