def notify(self, title, message, app_name): ''' Displays a balloon in the systray. Can be called multiple times with different parameter values. ''' self.remove_notify() # add icon and messages to window hicon = self._hicon flags = NIF_TIP | NIF_INFO icon_flag = 0 if hicon is not None: flags |= NIF_ICON # if icon is default app's one, don't display it in message if self._balloon_icon is not None: icon_flag = NIIF_USER | NIIF_LARGE_ICON notify_data = win_api_defs.get_NOTIFYICONDATAW( 0, self._hwnd, id(self), flags, 0, hicon, app_name, 0, 0, message, NOTIFYICON_VERSION_4, title, icon_flag, win_api_defs.GUID(), self._balloon_icon ) self._notify_data = notify_data if not win_api_defs.Shell_NotifyIconW(NIM_ADD, notify_data): raise Exception('Shell_NotifyIconW failed.') if not win_api_defs.Shell_NotifyIconW(NIM_SETVERSION, notify_data): raise Exception('Shell_NotifyIconW failed.')
def remove_notify(self): ''' Removes the notify balloon, if displayed. ''' if self._notify_data is not None: win_api_defs.Shell_NotifyIconW(NIM_DELETE, self._notify_data) self._notify_data = None