Example #1
0
 def _build_message_map(self):
     #set message map
     #TODO: move these into systray.constants
     self.WM_ONLOAD = win32gui.RegisterWindowMessage("SystrayOnLoad")
     self.WM_CREATED = win32gui.RegisterWindowMessage("TaskbarCreated")
     
     message_map = {self.WM_CREATED : self.restart, 
                    self.WM_ONLOAD: self.on_load,
                    win32con.WM_DESTROY: self.destroy, 
                    win32con.WM_COMMAND: self.command,
                    win32con.WM_USER+20 : self.notify 
                    }
                    
     return message_map
Example #2
0
    def __init__(self,
                 icon,
                 gui,
                 hover_text,
                 menu_options,
                 on_quit=None,
                 default_menu_index=None,
                 window_class_name=None,):

        self.icon = icon
        self.gui = gui  # 增加了这个参数,是产生托盘的GUI类的实例,参见后面代码
        self.hover_text = hover_text
        self.on_quit = on_quit

        # 生成菜单
        # 改了选项的文字,把'quit'替换成自己想用的代表'退出'的文字
        menu_options = menu_options + ((u'退出', 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()  # 生成窗口结构对象
        self.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.LoadCursor(
            0, win32con.IDC_ARROW)  # 窗口鼠标光标
        window_class.hbrBackground = win32con.COLOR_WINDOW  # 窗口背景色
        # could also specify a wndproc.   #定义窗口处理函数
        window_class.lpfnWndProc = message_map
        self.classAtom = win32gui.RegisterClass(window_class)  # 注册窗口类
        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(self.classAtom,  # 生成窗口   类名
                                          self.window_class_name,  # 窗口title
                                          style,  # 类型
                                          0,  # x
                                          0,  # y
                                          win32con.CW_USEDEFAULT,  # 宽度
                                          win32con.CW_USEDEFAULT,  # 高度
                                          0,  # 父窗口
                                          0,  # 菜单
                                          self.hinst,  # 句柄实例
                                          None)  # 必须为None,未知项
        win32gui.UpdateWindow(self.hwnd)  # 更新窗口
        self.notify_id = None
        self.refresh_icon()

        win32gui.PumpMessages()  # 消息循环直到窗口退出
Example #3
0
 def create_window(self):
     message_map = {
         win32gui.RegisterWindowMessage('TaskbarCreated'): self.on_restart,
         win32con.WM_DESTROY: self.on_destroy,
         win32con.WM_COMMAND: self.on_command,
         win32con.WM_USER + 20: self.on_notify_icon,
     }
     # 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.LoadCursor(0, win32con.IDC_ARROW)
     window_class.hbrBackground = win32con.COLOR_WINDOW
     window_class.lpfnWndProc = message_map
     classAtom = win32gui.RegisterClass(window_class)
     # Create the Window.
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     self.hwnd = win32gui.CreateWindow(
         classAtom,
         self.WINDOW_CLASS_NAME,
         style,
         0,
         0,
         win32con.CW_USEDEFAULT,
         win32con.CW_USEDEFAULT,
         0,
         0,
         hinst,
         None,
     )
     win32gui.UpdateWindow(self.hwnd)
 def start_icon(self):
     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.LoadCursor(0, win32con.IDC_ARROW)
     window_class.hbrBackground = win32con.COLOR_WINDOW
     window_class.lpfnWndProc = message_map # could also specify a wndproc.
     classAtom = win32gui.RegisterClass(window_class)
     # Create the Window.
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     self.hwnd = win32gui.CreateWindow(classAtom,
                                       self.window_class_name,
                                       style,
                                       0,
                                       0,
                                       win32con.CW_USEDEFAULT,
                                       win32con.CW_USEDEFAULT,
                                       0,
                                       0,
                                       hinst,
                                       None)
     win32gui.UpdateWindow(self.hwnd)
     self.notify_id = None
     self.refresh_icon()
     win32gui.PumpMessages()
Example #5
0
 def __init__(self,
              icon,
              hover_text,
              menu_options,
              on_quit=None,
              default_menu_index=None,
              window_class_name=None,
              passClass=True):
     
     self.icon = icon
     self.hover_text = hover_text
     self.on_quit = on_quit
     self.passClass = passClass
     
     menu_options =(('退出程序', None, self.QUIT),) + menu_options
     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()
     self.window_class = window_class
     hinst = window_class.hInstance = win32gui.GetModuleHandle(None)
     self.hinst = hinst
     window_class.lpszClassName = self.window_class_name
     window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;
     window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
     window_class.hbrBackground = win32con.COLOR_WINDOW
     window_class.lpfnWndProc = message_map # could also specify a wndproc.
     classAtom = win32gui.RegisterClass(window_class)
     self.classAtom = classAtom
     # Create the Window.
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     self.hwnd = win32gui.CreateWindow(classAtom,
                                       self.window_class_name,
                                       style,
                                       0,
                                       0,
                                       win32con.CW_USEDEFAULT,
                                       win32con.CW_USEDEFAULT,
                                       0,
                                       0,
                                       hinst,
                                       None)
     win32gui.UpdateWindow(self.hwnd)
     self.notify_id = None
     self.refresh_icon()
     
     win32gui.PumpMessages()
Example #6
0
    def __init__(self,
                 icon,
                 hover_text,
                 menu_options,
                 on_quit=None,
                 default_menu_index=None,
                 window_class_name=None,
                 lock=None,
                 init_callback=None):

        self.icon = icon
        self.hover_text = hover_text
        self.on_quit = on_quit

        self.hmenu = None
        self.lock = lock

        self.init_menu_options(menu_options)

        self.default_menu_index = (default_menu_index or 0)
        self.window_class_name = window_class_name or "SysTrayIconPy"

        try:
            message_map = {
                win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart,
                win32con.WM_DESTROY: self.destroy,
                win32con.WM_COMMAND: self.command,
                win32con.WM_USER + 20: self.notify,
                win32con.WM_USER + 21: self._refresh_icon_event
            }
            # 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.LoadCursor(0, win32con.IDC_ARROW)
            window_class.hbrBackground = win32con.COLOR_WINDOW
            window_class.lpfnWndProc = message_map  # could also specify a wndproc.
            classAtom = win32gui.RegisterClass(window_class)
            # Create the Window.
            style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
            self.hwnd = win32gui.CreateWindow(classAtom,
                                              self.window_class_name, style, 0,
                                              0, win32con.CW_USEDEFAULT,
                                              win32con.CW_USEDEFAULT, 0, 0,
                                              hinst, None)
            win32gui.UpdateWindow(self.hwnd)
            self.notify_id = None
            self.refresh_icon()
            atexit.register(self.destroy, None, None, None, None)
            SysTrayIcon.instance = self
            self.threadid = win32api.GetCurrentThreadId()
        finally:
            if init_callback is not None:
                init_callback(self)
        win32gui.PumpMessages()
Example #7
0
 def dispatch(self):
     return {
         win32gui.RegisterWindowMessage("TaskbarCreated"): self.set_icon,
         win32con.WM_CLOSE: self.on_close,
         win32con.WM_QUIT: self.on_close,
         win32con.WM_QUERYENDSESSION: self.on_close,
         win32con.WM_ENDSESSION: self.on_close,
         win32con.WM_COMMAND: self.on_command,
         win32con.WM_USER + 20: self.on_notify,
     }
Example #8
0
 def __init__(self, apiServer):
     
     self.apiServer = apiServer
     
     self.icon = AppFolders.iconsPath("logo.ico")
     print self.icon
     self.hover_text = "iBrew"
         
     menu_options = (
                     ('Interface', None, self.show),
                    )
     
     menu_options = menu_options + (('Quit', 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 = 1
     self.window_class_name = "ComicStreamerTrayIcon"
     
     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.LoadCursor(0, win32con.IDC_ARROW)
     window_class.hbrBackground = win32con.COLOR_WINDOW
     window_class.lpfnWndProc = message_map # could also specify a wndproc.
     classAtom = win32gui.RegisterClass(window_class)
     # Create the Window.
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     self.hwnd = win32gui.CreateWindow(classAtom,
                                       self.window_class_name,
                                       style,
                                       0,
                                       0,
                                       win32con.CW_USEDEFAULT,
                                       win32con.CW_USEDEFAULT,
                                       0,
                                       0,
                                       hinst,
                                       None)
     win32gui.UpdateWindow(self.hwnd)
     self.notify_id = None
     self.refresh_icon()
Example #9
0
    def __init__(self):
        super(Shell, self).__init__()

        msg_taskbar_restart = win32gui.RegisterWindowMessage("TaskbarCreated")
        self.message_map = {
            msg_taskbar_restart: self.OnRestart,
            win32con.WM_DESTROY: self.OnDestroy,
            win32con.WM_COMMAND: self.OnCommand,
            win32con.WM_USER + 20: self.OnTaskbarNotify,
        }

        self.main_frame = MainFrame(self.message_map)
        self.status_icon = StatusIcon(self)
Example #10
0
    def __init__(
        self,
        icon,
        hover_text,
        static_options,
        left_click_callback=None,
        addition_menu_callback=None,
        on_restart=None,
        default_menu_index=None,
        window_class_name=None,
    ):

        self.icon = icon
        self.hover_text = hover_text
        self.on_restart = on_restart
        self.LCC = left_click_callback
        self.AMC = addition_menu_callback

        self._next_action_id = self.FIRST_ID
        self.static_actions = dict()
        self.static_options = self._add_ids_to_menu_options(
            list(static_options), self.static_actions)

        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.LoadCursor(0, win32con.IDC_ARROW)
        window_class.hbrBackground = win32con.COLOR_WINDOW
        window_class.lpfnWndProc = message_map  # could also specify a wndproc.
        classAtom = win32gui.RegisterClass(window_class)
        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(classAtom, self.window_class_name,
                                          style, 0, 0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)
        win32gui.UpdateWindow(self.hwnd)
        self.notify_id = None
        self.refresh_icon()
Example #11
0
    def __init__(self):
        super(Shell, self).__init__()

        msg_taskbar_restart = win32gui.RegisterWindowMessage("TaskbarCreated")
        self.message_map = {msg_taskbar_restart: self.OnRestart,
                            win32con.WM_DESTROY: self.OnDestroy,
                            win32con.WM_COMMAND: self.OnCommand,
                            win32con.WM_USER + 20: self.OnTaskbarNotify, }

        self.main_frame = MainFrame(self.message_map)
        self.status_icon = StatusIcon(self)
        self.notice_index = -1  # rolling index of topmost notice in the queue

        self.console = None
        self.destroyed = False
Example #12
0
 def __init__(self,
              icon,
              hover_text,
              menu_cb,
              on_quit=None,
              default_menu_index=None,
              window_class_name=None,):
     
     self.icon = icon
     self.hover_text = hover_text
     self.on_quit = on_quit
     
     self.menu_cb = menu_cb
     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.LoadCursor(0, win32con.IDC_ARROW)
     window_class.hbrBackground = win32con.COLOR_WINDOW
     window_class.lpfnWndProc = message_map # could also specify a wndproc.
     classAtom = win32gui.RegisterClass(window_class)
     # Create the Window.
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     self.hwnd = win32gui.CreateWindow(classAtom,
                                       self.window_class_name,
                                       style,
                                       0,
                                       0,
                                       win32con.CW_USEDEFAULT,
                                       win32con.CW_USEDEFAULT,
                                       0,
                                       0,
                                       hinst,
                                       None)
     win32gui.UpdateWindow(self.hwnd)
     self.notify_id = None
     self.refresh_icon()
     
     win32gui.PumpMessages()
Example #13
0
File: win32.py Project: djon3s/APAF
    def __init__(self, reactor, callback):
        self.icon = os.path.join(config.drawable_dir, 'systray.ico')
        self.hover_text = config.description
        self.window_class_name = config.appname
        self.default_menu_index = 1
        self.reactor = reactor

        self.menu_actions_by_id = dict()
        self._next_action_id = 0
        self.SPECIAL_ACTIONS = list()
        self.menu_options = self._add_ids_to_menu_options((
            ('Open Panel service in Browser', None, base.open_panel_browser),
            # services list submenu
            ('Services', None, (('Fooo', None, self.bye), ('bar', None,
                                                           self.bye))),
            ('Quit', None, self.bye),
        ))

        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.LoadCursor(0, win32con.IDC_ARROW)
        window_class.hbrBackground = win32con.COLOR_WINDOW
        window_class.lpfnWndProc = message_map  # could also specify a wndproc.
        classAtom = win32gui.RegisterClass(window_class)
        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(classAtom, self.window_class_name,
                                          style, 0, 0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)
        win32gui.UpdateWindow(self.hwnd)
        self.notify_id = None
        self.refresh_icon()

        ## finally start the reactor
        callback()
        reactor.run()
        win32gui.PumpMessages()
    def __init__(self, autostart):
        self.autostart = autostart
        self.thread_id = win32api.GetCurrentThreadId()
        if not self.autostart:
            launch(self)
        name = "Open Media Library"
        self.icon = "ico/oml.ico"
        self.hover_text = name
        self.on_quit = quit

        menu_options = (('Open Media Library', None, None),
                        ('Launch', None, launch), ('Quit', 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 = 1
        self.window_class_name = name

        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.LoadCursor(0, win32con.IDC_ARROW)
        window_class.hbrBackground = win32con.COLOR_WINDOW
        window_class.lpfnWndProc = message_map  # could also specify a wndproc.
        classAtom = win32gui.RegisterClass(window_class)
        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(classAtom, self.window_class_name,
                                          style, 0, 0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)
        win32gui.UpdateWindow(self.hwnd)
        self.notify_id = None
        self.refresh_icon()
        win32gui.PumpMessages()
    def __init__(
        self,
        keyboard_handler,
        icon,
        hover_text,
        menu_options,
        on_quit=None,
        default_menu_index=None,
        window_class_name=None,
    ):

        threading.Thread.__init__(self)

        self.icon = icon
        self.hover_text = hover_text
        self.on_quit = on_quit
        self.KbH = keyboard_handler

        menu_options = menu_options + (('Quit', 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()
        self.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.LoadCursor(0, win32con.IDC_ARROW)
        window_class.hbrBackground = win32con.COLOR_WINDOW
        window_class.lpfnWndProc = message_map  # could also specify a wndproc.
        self.classAtom = win32gui.RegisterClass(window_class)
Example #16
0
    def __init__(
        self,
        icon,
        hover_text,
        menu_options,
        menu_options2,
        on_quit=None,
        default_menu_index=None,
        window_class_name=None,
    ):

        self.button_doubleclicked = False
        self.playing = None
        self.playingID = ''
        self.toggle = False
        self.vlc = vlcimp.Instance()
        self.player = self.vlc.media_player_new()
        self.icon = icon
        self.hover_text = hover_text
        self.on_quit = on_quit
        self.menu = None

        self.media_list = []
        self.icon_list = []
        opt_default = ''
        menu_options = menu_options + (
            ('Stop', None, self.STOP, opt_default), )
        menu_options2 = menu_options2 + (
            ('Quit', None, self.QUIT, opt_default), )

        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_options2 = self._add_ids_to_menu_options(list(menu_options2))
        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 "SystemTrayRadio"

        message_map = {
            win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart,
            win32con.WM_DESTROY: self.destroy,
            win32con.WM_COMMAND: self.command,
            win32con.WM_USER + 20: self.notify,
        }

        hinst = win32gui.GetModuleHandle(None)
        window_class = win32gui.WNDCLASS()
        window_class.hInstance = hinst
        window_class.lpszClassName = self.window_class_name
        window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
        window_class.hbrBackground = win32con.COLOR_WINDOW
        window_class.lpfnWndProc = message_map
        classAtom = win32gui.RegisterClass(window_class)
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(classAtom, self.window_class_name,
                                          style, 0, 0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)
        win32gui.UpdateWindow(self.hwnd)
        self.notify_id = None
        self.refresh_icon()
        win32gui.PumpMessages()
Example #17
0
	def __init__(self,
				 icon,
				 hover_text,
				 menu_options,
				 on_quit=None,
				 default_menu_index=None,
				 window_class_name=None,
				 data_feedback=None,
				 extra_icon_paths=None):
		
		self.icon = icon
		self.hover_text = hover_text
		self.on_quit = on_quit
		self.extra_icon_paths = extra_icon_paths
		
		menu_options = menu_options + (('Quit', 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"
		
		# This dict sets up a coorespondance from received win32gui messages (in the form of standard integer constants as defined in win32con)
		#   and the desired action to take upon receiving the message.
		#   WM_USER is the beginning of a reserved block of user-definable messages.
		message_map = {win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart,
					   win32con.WM_DESTROY: self.destroy,
					   win32con.WM_COMMAND: self.command,
					   win32con.WM_USER+self.OFFSET : self.notify,
					   win32con.WM_USER+self.OFFSET+1 : self.change_icon,}
		# 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.LoadCursor(0, win32con.IDC_ARROW)
		window_class.hbrBackground = win32con.COLOR_WINDOW
		window_class.lpfnWndProc = message_map # could also specify a wndproc.
		classAtom = win32gui.RegisterClass(window_class)
		# Create the Window.
		style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
		self.hwnd = win32gui.CreateWindow(classAtom,
										  self.window_class_name,
										  style,
										  0,
										  0,
										  win32con.CW_USEDEFAULT,
										  win32con.CW_USEDEFAULT,
										  0,
										  0,
										  hinst,
										  None)
		win32gui.UpdateWindow(self.hwnd)
		self.notify_id = None
		self.refresh_icon()
		
		# Send data to calling script. Used to retrieve hwnd in order to send messages.
		if(data_feedback): data_feedback(self)
		
		# Runs the main loop that waits for messages in this thread
		win32gui.PumpMessages()
    def __init__(self,
                 icon,
                 hover_text,
                 menu_options,
                 on_exit=None,
                 default_menu_index=None,
                 window_class_name=None,
                 call_on_startup=None):
        """
        The SysTrayIcon class implements an icon in the windows system tray, which allows left click on the icon for an action
        and right click for a menu
        :param icon: Full path to icon file
        :param hover_text: Text to show when hovering above icon
        :param menu_options: List of menu options and functions to call
        :param on_exit: FUnction to call when exiting
        :param default_menu_index: The menu item to select when clicking the icon
        :param window_class_name: Classname
        :param call_on_startup: Function to call on startup
        """
        self.icon = icon
        self.hover_text = hover_text
        self.on_exit = on_exit

        menu_options = menu_options + [('Exit', None, self.EXIT)]
        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
        }
        if self.on_exit:
            message_map[win32con.WM_QUERYENDSESSION] = self.on_exit
        # 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.LoadCursor(0, win32con.IDC_ARROW)
        window_class.hbrBackground = win32con.COLOR_WINDOW
        window_class.lpfnWndProc = message_map  # could also specify a wndproc.
        classAtom = win32gui.RegisterClass(window_class)
        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(classAtom, self.window_class_name,
                                          style, 0, 0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)
        win32gui.UpdateWindow(self.hwnd)
        self.notify_id = None
        self.refresh_icon()

        if call_on_startup is not None:
            call_on_startup(self)
        win32gui.PumpMessages()
Example #19
0
    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 + (('Quit', 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,
            # owner-draw related handlers.
            win32con.WM_MEASUREITEM: self.OnMeasureItem,
            win32con.WM_DRAWITEM: self.OnDrawItem,
            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.LoadCursor(0, win32con.IDC_ARROW)
        window_class.hbrBackground = win32con.COLOR_WINDOW
        window_class.lpfnWndProc = message_map  # could also specify a wndproc.
        classAtom = win32gui.RegisterClass(window_class)
        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(classAtom, self.window_class_name,
                                          style, 0, 0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)
        win32gui.UpdateWindow(self.hwnd)
        self.notify_id = None
        self.refresh_icon()

        # Load up some information about menus needed by our owner-draw code.
        # The font to use on the menu.
        ncm = win32gui.SystemParametersInfo(win32con.SPI_GETNONCLIENTMETRICS)
        self.font_menu = win32gui.CreateFontIndirect(ncm['lfMenuFont'])
        # spacing for our ownerdraw menus - not sure exactly what constants
        # should be used (and if you owner-draw all items on the menu, it
        # doesn't matter!)
        self.menu_icon_height = win32api.GetSystemMetrics(
            win32con.SM_CYMENU) - 4
        self.menu_icon_width = self.menu_icon_height
        self.icon_x_pad = 8  # space from end of icon to start of text.
        # A map we use to stash away data we need for ownerdraw.  Keyed
        # by integer ID - that ID will be set in dwTypeData of the menu item.
        self.menu_item_map = {}

        win32gui.PumpMessages()