我想实现动态读取串口数据,当收到数据时,已经在桌面右下角建立的图标闪烁显示有数据开始处理,无数据时显示等待图标,我弄了下,只能手动点击触发,对这个类有点不太明白如何实现收到数据自动切换图标,请论坛高手给指点一下,在此谢过!
代码如下
#encoding:utf-8
import os
import sys
import time
import win32api
import win32con
import win32gui_struct
import threading
try:
import winxpgui as win32gui
except ImportError:
import win32gui
mainfile = os.path.dirname(sys.argv[0])
class SysTrayIcon(object):
QUIT = "QUIT"
SPECIAL_ACTIONS = [QUIT]
FIRST_ID = 1023
def __init__(self,
icon,
hover_text,
menu_options,
on_quit=None,
default_menu_index=None,
window_class_name=None,):
self.icon = icon
self.hover_text = hover_text
self.on_quit = on_quit
menu_options = menu_options + (("退出", None, self.QUIT),)
self._next_action_id = self.FIRST_ID
self.menu_actions_by_id = set()
self.menu_options = self._add_ids_to_menu_options(list(menu_options))
self.menu_actions_by_id = dict(self.menu_actions_by_id)
del self._next_action_id
self.default_menu_index = (default_menu_index or 0)
self.window_class_name = window_class_name or "SysTrayIconPy"
message_map = {win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart,
win32con.WM_DESTROY: self.destroy,
win32con.WM_COMMAND: self.command,
win32con.WM_USER+20 : self.notify,}
# Register the Window class.
window_class = win32gui.WNDCLASS()
hinst = window_class.hInstance = win32gui.GetModuleHandle(None)
window_class.lpszClassName = self.window_class_name
window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;
window_class.hCursor = win32gui.LoadCurso