コード例 #1
0
    def __init__(self):

        self.PYIDA_QUICKCALL_MESSAGE = win32gui.RegisterWindowMessage(
            "PYIDA_QUICKCALL")
        self.PYIDASRVR_BROADCAST_MESSAGE = win32gui.RegisterWindowMessage(
            "PYIDA_SERVER")
        if debugLevel > 1:
            print "QuickCall: %x BroadCast: %x" % (
                self.PYIDA_QUICKCALL_MESSAGE, self.PYIDASRVR_BROADCAST_MESSAGE)

        message_map = {
            self.PYIDA_QUICKCALL_MESSAGE: self.OnQuickCall,
            self.PYIDASRVR_BROADCAST_MESSAGE: self.OnBroadcast,
            win32con.WM_COPYDATA: self.OnCopyData,
        }

        wc = win32gui.WNDCLASS()
        wc.lpfnWndProc = message_map
        wc.lpszClassName = 'MyWindowClass'
        hinst = wc.hInstance = win32api.GetModuleHandle(None)
        self.classAtom = win32gui.RegisterClass(wc)

        self.hwnd = win32gui.CreateWindow(self.classAtom, "win32gui test", 0,
                                          0, 0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)

        registerServer(self.hwnd)
        print "Python listening for WM_COPYDATA on hwnd = %d" % self.hwnd
コード例 #2
0
ファイル: taskbar.py プロジェクト: tsoldaat/enso-portable
    def __init__(self,
                 icon,
                 hover_text,
                 menu_options,
                 on_quit=None,
                 default_menu_index=None,
                 window_class_name = "EnsoTrayWndClass",):

        self.default_icon = icon
        self.hover_text = hover_text
        self.notify_id = None
        if on_quit:
            self.on_quit = on_quit
        self.custom_menu_items = {}

        self.WM_ONLOAD = win32gui.RegisterWindowMessage("SystrayOnLoad")
        self.WM_CREATED = win32gui.RegisterWindowMessage("TaskbarCreated")
        message_map = {
                self.WM_CREATED : self._on_restart,
                self.WM_ONLOAD: self._on_load,
                win32con.WM_DESTROY: self._on_destroy,
                win32con.WM_COMMAND: self._on_command,
                win32con.WM_USER + 20 : self._on_taskbar_notify,
        }

        # Register the Window class.
        self._window_class = win32gui.WNDCLASS()
        self._window_class.hInstance = win32api.GetModuleHandle(None)
        self._window_class.lpszClassName = window_class_name
        self._window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;
        self._window_class.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW)
        self._window_class.hbrBackground = win32con.COLOR_WINDOW
        self._window_class.lpfnWndProc = message_map # could also specify a wndproc.

        # Don't blow up if class already registered to make testing easier
        try:
            self.class_atom = win32gui.RegisterClass(self._window_class)
        except win32gui.error as err_info:
            if err_info.winerror != winerror.ERROR_CLASS_ALREADY_EXISTS:
                raise

        # Create the helper Window
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(
            self.class_atom,
            window_class_name, #Title same as class-name
            style,
            0,
            0,
            win32con.CW_USEDEFAULT,
            win32con.CW_USEDEFAULT,
            0,
            0,
            self._window_class.hInstance,
            None)
        win32gui.UpdateWindow(self.hwnd)

        self._create_icons()
コード例 #3
0
    def __init__(
        self,
        icon,
        hover_text,
        menu_options,
        on_quit=None,
        default_menu_index=None,
        window_class_name="EnsoTrayWndClass",
    ):

        self.default_icon = icon
        self.hover_text = hover_text
        self.notify_id = None
        self._on_quit = None
        if on_quit:
            if not callable(on_quit):
                raise Exception(
                    "SysTrayIcon on_quit parameter must be callable")
            self._on_quit = on_quit
        self.custom_menu_items = {}

        self.WM_ONLOAD = win32gui.RegisterWindowMessage("SystrayOnLoad")
        self.WM_CREATED = win32gui.RegisterWindowMessage("TaskbarCreated")
        message_map = {
            self.WM_CREATED: self._on_restart,
            self.WM_ONLOAD: self._on_load,
            win32con.WM_DESTROY: self._on_destroy,
            win32con.WM_COMMAND: self._on_command,
            win32con.WM_USER + 20: self._on_taskbar_notify,
        }

        # Register the Window class.
        self._window_class = win32gui.WNDCLASS()
        self._window_class.hInstance = win32api.GetModuleHandle(
            None)  # @UndefinedVariable
        self._window_class.lpszClassName = window_class_name
        self._window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        self._window_class.hCursor = win32api.LoadCursor(
            0, win32con.IDC_ARROW)  # @UndefinedVariable
        self._window_class.hbrBackground = win32con.COLOR_WINDOW
        self._window_class.lpfnWndProc = message_map  # could also specify a wndproc.

        # Don't blow up if class already registered to make testing easier
        try:
            self.class_atom = win32gui.RegisterClass(self._window_class)
        except win32gui.error, err_info:
            if err_info.winerror != winerror.ERROR_CLASS_ALREADY_EXISTS:
                raise
コード例 #4
0
ファイル: main.py プロジェクト: tzY15368/WinPods
    def __init__(s,
                 icon,
                 hover_text,
                 menu_options,
                 on_quit=None,
                 default_menu_index=None,
                 window_class_name=None, ):
        s.icon = icon
        s.hover_text = hover_text
        s.on_quit = on_quit

        menu_options = menu_options + (('Exit', None, s.QUIT),)
        s._next_action_id = s.FIRST_ID
        s.menu_actions_by_id = set()
        s.menu_options = s._add_ids_to_menu_options(list(menu_options))
        s.menu_actions_by_id = dict(s.menu_actions_by_id)
        del s._next_action_id

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

        message_map = {win32gui.RegisterWindowMessage("TaskbarCreated"): s.refresh_icon,
                       win32con.WM_DESTROY: s.destroy,
                       win32con.WM_COMMAND: s.command,
                       win32con.WM_USER + 20: s.notify, }
        # 注册窗口类。
        window_class = win32gui.WNDCLASS()
        window_class.hInstance = win32gui.GetModuleHandle(None)
        window_class.lpszClassName = s.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  # 也可以指定wndproc.
        s.classAtom = win32gui.RegisterClass(window_class)
コード例 #5
0
    def __init__(self):
        super(KeyCounter, self).__init__()

        self.HWND = None
        self.hook = pyHook.HookManager()
        self.FPS = 60
        self.MSPF = int(round(1000.0 / self.FPS))
        self.font = None
        self.tooltip = self.name
        # Private message to be used in THIS program ONLY
        self.MESSAGE = random.randint(win32con.WM_USER, 0x7FFF)
        self.__MESSAGE_TC = win32gui.RegisterWindowMessage('TaskbarCreated')
        self.__NOTIFY_ID = None
        self.MENU = None
        self.APP_NAME = u'{} {}'.format(self.name, self.version)
        self.MENU_FUNCS = {
            'Quit': self.stop,
        }
        self.MENU_TEXTS = [
            self.APP_NAME,
            'Quit',
        ][::-1]
        self.__last_text_extent = (0, 0)
        self.SICHECK_EVENT = None
        self.GUID = '76B80C3C-11AB-47CD-A124-BADB07F41DB8'
コード例 #6
0
    def __init__(self,
                 icon,
                 hover_text,
                 menu_options=(),
                 on_quit=None,
                 window_class_name=None,
                 gui=None):
        self.icon = icon
        self.hover_text = hover_text
        self.on_quit = on_quit
        self.gui = gui
        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.window_class_name = window_class_name or "SysTrayIconPy"

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

        window_class = win32gui.WNDCLASS()
        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
        self.classAtom = win32gui.RegisterClass(window_class)
コード例 #7
0
 def initialize(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()
コード例 #8
0
    def __init__(self):
        wx.EvtHandler.__init__(self)
        msg_TaskbarCreated = win32gui.RegisterWindowMessage("TaskbarCreated")
        message_map = {
            msg_TaskbarCreated: self.OnTaskbarCreated,
            win32con.WM_DESTROY: self.OnDestroy,
            win32con.WM_COMMAND: self.OnCommand,
            win32con.WM_USER + 20: self.OnTaskbarNotify
        }

        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32api.GetModuleHandle(None)
        wc.lpszClassName = "SysTrayIcon"
        wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        wc.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW)
        wc.hbrBackground = win32con.COLOR_WINDOW
        wc.lpfnWndProc = message_map

        classAtom = win32gui.RegisterClass(wc)

        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(wc.lpszClassName, "SysTrayIcon",
                                          style, 0, 0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)
        win32gui.UpdateWindow(self.hwnd)
        self._nid = None
        self.in_popup = False
        self.menu = None
        self.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.OnRightUp)
        # With wxPython 4, calling <EvtHandler>.Destroy() no longer makes the
        # instance evaluate to False in boolean comparisons, so we emulate that
        # functionality
        self._destroyed = False
コード例 #9
0
    def __init__(self, menu_options, tray_name="willSpeak"):
        # Create instance level variable
        self.menu_options = menu_options

        # Create task mappings for try events
        message_map = {
            win32gui.RegisterWindowMessage("TaskbarCreated"): self.OnRestart,
            win32con.WM_DESTROY: self.OnDestroy,
            win32con.WM_COMMAND: self.OnCommand,
            win32con.WM_USER + 20: self.OnTaskbarNotify,
        }

        # Register the Window class.
        window_class = win32gui.WNDCLASS()
        window_class.lpszClassName = tray_name
        hinst = window_class.hInstance = win32gui.GetModuleHandle(None)
        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, tray_name, style, 0, 0,
                                          win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)
        win32gui.UpdateWindow(self.hwnd)
        self.notify_id = None
        self.create_icon()
        win32gui.PumpMessages()
コード例 #10
0
def TestObjectFromWindow():
    # Check we can use ObjectFromLresult to get the COM object from the
    # HWND - see KB Q249232
    # Locating the HWND is different than the KB says...
    hwnd = win32gui.FindWindow('IEFrame', None)
    for child_class in [
            'TabWindowClass', 'Shell DocObject View',
            'Internet Explorer_Server'
    ]:
        hwnd = win32gui.FindWindowEx(hwnd, 0, child_class, None)
        # ack - not working for markh on vista with IE8 (or maybe it is the
        # lack of the 'accessibility' components mentioned in Q249232)
        # either way - not working!
        return
    # But here is the point - once you have an 'Internet Explorer_Server',
    # you can send a message and use ObjectFromLresult to get it back.
    msg = win32gui.RegisterWindowMessage("WM_HTML_GETOBJECT")
    rc, result = win32gui.SendMessageTimeout(hwnd, msg, 0, 0,
                                             win32con.SMTO_ABORTIFHUNG, 1000)
    ob = pythoncom.ObjectFromLresult(result, pythoncom.IID_IDispatch, 0)
    doc = Dispatch(ob)
    # just to prove it works, set the background color of the document.
    for color in "red green blue orange white".split():
        doc.bgColor = color
        time.sleep(0.2)
コード例 #11
0
ファイル: taskbar.py プロジェクト: adamorucu/Usage-Tracker
   def __init__(self):
      restart_message = win32gui.RegisterWindowMessage('TaskBar Created')
      message_map = {restart_message: self.restart,
                     win32con.WM_DESTROY: self.destroy,
                     win32con.WM_COMMAND: self.command,
                     win32con.WM_USER+20: self.taskbar_notify}

      wc = win32gui.WNDCLASS()
      hinst = wc.hInstance = win32api.GetModuleHandle(None)
      wc.lpszClassName = "Tracker"
      wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
      wc.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW)
      wc.hbrBackground = win32con.COLOR_WINDOW
      wc.lpfnWndProc = message_map  # could also specify a wndproc

      # Don't blow up if class already registered to make testing easier
      try:
         classAtom = win32gui.RegisterClass(wc)
      except win32gui.error:
         raise

      # Create the Window.
      style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
      self.hwnd = win32gui.CreateWindow(wc.lpszClassName, "Taskbar Demo", style,
                                        0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT,
                                        0, 0, hinst, None)
      win32gui.UpdateWindow(self.hwnd)
      self.create_icon()
コード例 #12
0
ファイル: tongshi.py プロジェクト: zhuzhenping/datafeed
    def __init__(self, host='localhost', password=None):
        self.client = Client(host=host, password=password, socket_timeout=10)

        msg_task_bar_restart = win32gui.RegisterWindowMessage("TaskbarCreated")
        message_map = {
            msg_task_bar_restart: self._on_restart,
            win32con.WM_DESTROY: self._on_destroy,
            win32con.WM_COMMAND: self._on_command,
            self._WM_USER_STOCK_DATA: self._on_data_receive,
            win32con.WM_USER + 20: self._on_taskbar_notify
        }
        # Register the Window class.
        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32api.GetModuleHandle(None)
        wc.lpszClassName = "StockTaskBar"
        wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        wc.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW)
        wc.hbrBackground = win32con.COLOR_WINDOW
        wc.lpfnWndProc = message_map  # could also specify a wndproc.

        # Don't blow up if class already registered to make testing easier
        try:
            classAtom = win32gui.RegisterClass(wc)
        except win32gui.error, err_info:
            if err_info.winerror != winerror.ERROR_CLASS_ALREADY_EXISTS:
                raise
コード例 #13
0
    def __init__(self):
        msg_TaskbarRestart = win32gui.RegisterWindowMessage("TaskbarCreated")
        message_map = {
            msg_TaskbarRestart: self.OnRestart,
            win32con.WM_DESTROY: self.OnDestroy,
            win32con.WM_COMMAND: self.OnCommand,
            win32con.WM_USER + 20: self.OnTaskbarNotify,
        }
        # Register the Window class.
        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32api.GetModuleHandle(None)
        wc.lpszClassName = "PythonTaskbarDemo"
        wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        wc.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW)
        wc.hbrBackground = win32con.COLOR_WINDOW
        wc.lpfnWndProc = message_map  # could also specify a wndproc.

        # Don't blow up if class already registered to make testing easier
        try:
            classAtom = win32gui.RegisterClass(wc)
        except win32gui.error as err_info:
            if err_info.winerror != winerror.ERROR_CLASS_ALREADY_EXISTS:
                raise

        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(wc.lpszClassName, "Taskbar Demo",
                                          style, 0, 0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)
        win32gui.UpdateWindow(self.hwnd)
        self._DoCreateIcons()
コード例 #14
0
ファイル: trayicon.py プロジェクト: kaiCu/gbi-client
    def create_window(self, window_name='Dummy Window'):
        message_map = {
            win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart,
            win32con.WM_DESTROY: self.destroy,
            win32con.WM_COMMAND: self.command,
            self.message_id : self.notify,
        }

        # Register the Window class.
        window_class = win32gui.WNDCLASS()
        window_class.lpszClassName = 'geobox_client_tray_icon'
        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
        class_atom = win32gui.RegisterClass(window_class)
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU

        window_id = win32gui.CreateWindow(
            class_atom,
            window_name,
            style,
            0, 0,
            0, 0,
            0,
            0,
            None,
            None
        )
        log.debug('Dummy window created')
        win32gui.UpdateWindow(window_id)
        return window_id
コード例 #15
0
ファイル: win32.py プロジェクト: jakebarnwell/PythonGenerator
 def initWin32(self):
     hInst = win32api.GetModuleHandle(None)
     self._status = SCA_ATTACH_NOT_CONNECTED
     api_attach = win32gui.RegisterWindowMessage(
         "SkypeControlAPIAttach");
     self.api_discover = api_discover = win32gui.RegisterWindowMessage(
         "SkypeControlAPIDiscover");
     wc = win32gui.WNDCLASS()
     wc.hInstance = hInst
     wc.lpfnWndProc = {
         api_attach: self._attached,
         api_discover: self._discovered,
         win32con.WM_CREATE: self._created,
         win32con.WM_COPYDATA: self._copydata,
     }
     wc.lpszClassName = className = "SkypePythonHandler"
     rc = win32gui.RegisterClass(wc)
     self._win = win32gui.CreateWindow(
         rc, "SkypePython", 0, 0, 0, 0, 0, 0, 0, hInst, None)
コード例 #16
0
 def _init_getword(self):
     LICENSEID = "{00000000-0000-0000-0000-000000000000}"
     MOUSEHOOK_CAPTURE_OK_MSG = "MOUSEHOOK_CAPTUREOK_MSG-" + LICENSEID
     self.MOUSEHOOK_CAPTURE_OK = win32gui.RegisterWindowMessage(
         MOUSEHOOK_CAPTURE_OK_MSG)
     self.icall = ctypes.windll.LoadLibrary('ICall')
     self.icall.SetMouseHook(self.hwnd)
     self.icall.MouseEnableCap(True)
     self.icall.GetWordEnableCap(True)
     self.getword_loaded = True
コード例 #17
0
    def __init__(self,
                 menu_options,
                 program_name='Python Taskbar',
                 window_name=None):

        self.logger = logging.getLogger("tray")
        self.cache = {}
        self._commands = {
            'OnMenuOpen': [],
            'OnMenuClose': [],
            'OnWindowHide': [],
            'OnWindowRestore': []
        }
        self.program_name = program_name
        try:
            self.console_hwnd = WindowHandle(parent=False, console=True)
        except NameError:
            self.console_hwnd = None
        self._refresh_menu(menu_options)
        if window_name is None:
            window_name = program_name

        #Set up callbacks
        msg_TaskbarRestart = win32gui.RegisterWindowMessage('TaskbarCreated')
        message_map = {
            msg_TaskbarRestart: self.OnRestart,
            win32con.WM_DESTROY: self.OnDestroy,
            win32con.WM_COMMAND: self.OnCommand,
            TRAY_EVENT: self.OnTaskbarNotify,
        }
        #Register the Window class.
        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32api.GetModuleHandle(None)
        wc.lpszClassName = window_name
        wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        wc.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW)
        wc.hbrBackground = win32con.COLOR_WINDOW
        wc.lpfnWndProc = message_map  # could also specify a wndproc.

        #Don't blow up if class already registered to make testing easier
        try:
            classAtom = win32gui.RegisterClass(wc)
        except (win32gui.error, err_info):
            if err_info.winerror != winerror.ERROR_CLASS_ALREADY_EXISTS:
                raise

        #Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(wc.lpszClassName, window_name, style, \
                0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
                0, 0, hinst, None)
        win32gui.UpdateWindow(self.hwnd)
        self._set_icon()
        self.logger.info('Window created.')
コード例 #18
0
    def __init__(
        self,
        icon,
        hover_text,
        menu_options,
        on_quit=None,
        default_menu_index=None,
        window_class_name=None,
    ):
        self.menu = None
        self.icon = icon
        self.hover_text = hover_text
        self.on_quit = on_quit

        menu_options = menu_options + [
            ['Quit', icon_power, 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.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()
コード例 #19
0
    def __init__(s,
                 icon,
                 hover_text,
                 menu_options,
                 on_quit,
                 tk_window=None,
                 default_menu_index=None,
                 window_class_name=None,
                 app=None):
        '''
        icon         需要显示的图标文件路径
        hover_text   鼠标停留在图标上方时显示的文字
        menu_options 右键菜单,格式: (('a', None, callback), ('b', None, (('b1', None, callback),)))
        on_quit      传递退出函数,在执行退出时一并运行
        tk_window    传递Tk窗口,s.root,用于单击图标显示窗口
        default_menu_index 不显示的右键菜单序号
        window_class_name  窗口类名
        '''
        s.icon = icon
        s.hover_text = hover_text
        s.on_quit = on_quit
        s.root = tk_window
        s.app = app
        s.show_config = False

        menu_options = menu_options + (('退出', None, s.QUIT), )
        s._next_action_id = s.FIRST_ID
        s.menu_actions_by_id = set()
        s.menu_options = s._add_ids_to_menu_options(list(menu_options))
        s.menu_actions_by_id = dict(s.menu_actions_by_id)
        del s._next_action_id

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

        message_map = {
            win32gui.RegisterWindowMessage("TaskbarCreated"): s.restart,
            win32con.WM_DESTROY: s.destroy,
            win32con.WM_COMMAND: s.command,
            win32con.WM_USER + 20: s.notify,
        }
        # 注册窗口类。
        wc = win32gui.WNDCLASS()
        wc.hInstance = win32gui.GetModuleHandle(None)
        wc.lpszClassName = s.window_class_name
        wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        wc.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
        wc.hbrBackground = win32con.COLOR_WINDOW
        wc.lpfnWndProc = message_map  # 也可以指定wndproc.
        s.classAtom = win32gui.RegisterClass(wc)
コード例 #20
0
    def __init__(self):
        msg_TaskbarRestart = win32gui.RegisterWindowMessage("TaskbarCreated")
        #定义一个新的窗口消息
        message_map = {                         #建立函数命令字典,用于窗口回调函数的四个参数
                msg_TaskbarRestart: self.OnRestart,
                win32con.WM_DESTROY: self.OnDestroy,
                win32con.WM_COMMAND: self.OnCommand,
                win32con.WM_USER+20 : self.OnTaskbarNotify,
        }
        self.menu = win32gui.CreatePopupMenu()  #产生一个菜单句柄menu
        win32gui.AppendMenu(self.menu, win32con.MF_STRING, 1023,
                            "显示/隐藏窗口")  #给菜单添加子项,1027可以一直下去
        win32gui.AppendMenu(self.menu, win32con.MF_STRING, 1024, "设置")
        win32gui.AppendMenu(self.menu, win32con.MF_STRING, 1025, "退出程序")
        #win32gui.EnableMenuItem(menu,1023,win32con.MF_GRAYED)#是用菜单句柄,对菜单进行操作

        # Register the Window class.
        self.wc = win32gui.WNDCLASS()  #局部变量wc改成窗口类的实例
        hinst = self.wc.hInstance = win32api.GetModuleHandle(None)  #获得程序模块句柄
        self.wc.lpszClassName = ("PythonTaskbarDemo")  #窗口类的类名
        self.wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        #窗口类的style特征,水平重画和竖直重画
        self.wc.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW)
        self.wc.hbrBackground = win32con.COLOR_WINDOW
        self.wc.lpfnWndProc = message_map  # could also specify a wndproc,给窗口回调函数赋值
        '''这里传进去的其实是函数指针,它里面保存的是我们定义的windowproc的入口地址'''
        # Don't blow up if class already registered to make testing easier
        try:
            classAtom = win32gui.RegisterClass(self.wc)  #用wc将classatom注册为一个窗口类
        except win32gui.error and err_info:
            if err_info.winerror != winerror.ERROR_CLASS_ALREADY_EXISTS:
                raise

        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(
            self.wc.lpszClassName,
            "Taskbar Demo",
            style,  #创建一个窗口 
            0,
            0,
            win32con.CW_USEDEFAULT,
            win32con.CW_USEDEFAULT,
            0,
            0,
            hinst,
            None)
        win32gui.UpdateWindow(self.hwnd)  #更新窗口
        self._DoCreateIcons()
        win32gui.PumpMessages()
コード例 #21
0
    def __init__(self, config, logon):
        self._config = config
        self._schedulers = []
        self._scheduledScans = []
        self._processes = []
        self._balloon_info = None
        self._balloonThreadLock = threading.Lock()
        self._checkversionattempts = 0
        self._dbupdateattempts = 0
        self._nomenu = False
        self._reschedule_delay = 300
        self._scheduleCount = 0
        msg_TaskbarRestart = win32gui.RegisterWindowMessage("TaskbarCreated")
        message_map = {
            msg_TaskbarRestart: self.OnRestart,
            win32con.WM_DESTROY: self.OnDestroy,
            win32con.WM_COMMAND: self.OnCommand,
            MainWindow.WM_TASKBAR_NOTIFY: self.OnTaskbarNotify,
            MainWindow.WM_CONFIG_UPDATED: self.OnConfigUpdated,
            MainWindow.WM_SHOW_BALLOON: self.OnShowBalloon,
            MainWindow.WM_CHECK_VERSION: self.OnCheckVersion,
        }
        # Register the Window class.
        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32api.GetModuleHandle(None)
        wc.lpszClassName = "ClamWinTrayWindow"
        wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        wc.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
        wc.hbrBackground = win32con.COLOR_WINDOW
        wc.lpfnWndProc = message_map  # could also specify a wndproc.
        classAtom = win32gui.RegisterClass(wc)
        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow( classAtom, "ClamWin", style, \
                0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
                0, 0, hinst, None)
        win32gui.UpdateWindow(self.hwnd)

        # create mutex to prevent further instances
        self._hActiveMutex = win32event.CreateMutex(None, True,
                                                    self.ACTIVE_MUTEX)
        self._DoCreateIcons()
        self._InitSchedulers(logon)

        # start config monitor thread
        self._configMonitor = MonitorConfig(self.NotifyConfig, (self.hwnd, ))
        self._configMonitor.start()
コード例 #22
0
    def __init__(self):
        self.CLstate = win32api.GetAsyncKeyState(win32con.VK_CAPITAL)

        msg_TaskbarRestart = win32gui.RegisterWindowMessage("Taskbar")
        # registers a new unique window

        message_map = {  # dict containing functions, that will
            msg_TaskbarRestart: self.
            OnRestart,  # be used in this tray program every function recieves 
            win32con.WM_DESTROY:
            self.OnDestroy,  # self, hwnd, msg, wparam, lparam on call.
            win32con.WM_USER + 20:
            self.OnTaskbarNotify,  # for use by private window classes
        }

        # Register the Window class.
        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32api.GetModuleHandle(
            None)  # returns a 'None' handle to the instance
        # that contains the window procedure for the class.
        wc.lpszClassName = "TaskbarScreenBrghtnss"  # specifies the window class name (!)
        wc.lpfnWndProc = message_map  # (!) connects functions to window

        try:  # registering a class window and check
            classAtom = win32gui.RegisterClass(wc)  # if it is already exists
        except win32gui.error as err_info:
            if err_info.winerror != winerror.ERROR_CLASS_ALREADY_EXISTS:
                raise

        # Create the Window
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU  # configuration window's style

        # creates window and returns handle (probably)
        self.hwnd = win32gui.CreateWindow(classAtom, "Brghtns", style, \
                0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
                0, 0, hinst, None)

        # updates current Windows GUI, giving handle of a new GUI-element
        win32gui.UpdateWindow(self.hwnd)

        # Hides a console window
        Minimize = win32gui.GetForegroundWindow()
        win32gui.ShowWindow(Minimize, win32con.SW_HIDE)

        # calls function that deply an icon on the tray
        self._DoCreateIcons()
コード例 #23
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

        logger.info(common.CHECK_MARK_ICO_PATH)
        menu_options += (
            ('开机启动', common.CHECK_MARK_ICO_PATH, self.BOOTUP),
            ('更换壁纸', None, self.CHANGE_WALLPAPER),
            ('退出', 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.refresh_icon,
            win32con.WM_DESTROY: self.destroy,
            win32con.WM_COMMAND: self.command,
            win32con.WM_USER + 20: self.notify,
        }
        # 注册窗口类。
        window_class = win32gui.WNDCLASS()
        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  # 也可以指定wndproc.
        self.classAtom = win32gui.RegisterClass(window_class)
コード例 #24
0
ファイル: __init__.py プロジェクト: vault-the/pyrexecd
 def initialize(klass):
     WM_RESTART = win32gui.RegisterWindowMessage('TaskbarCreated')
     klass.WM_NOTIFY = win32con.WM_USER + 1
     klass.WNDCLASS = win32gui.WNDCLASS()
     klass.WNDCLASS.hInstance = win32gui.GetModuleHandle(None)
     klass.WNDCLASS.lpszClassName = 'Py_' + klass.__name__
     klass.WNDCLASS.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
     klass.WNDCLASS.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
     klass.WNDCLASS.hIcon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
     klass.WNDCLASS.hbrBackground = win32con.COLOR_WINDOW
     klass.WNDCLASS.lpfnWndProc = {
         WM_RESTART: klass._restart,
         klass.WM_NOTIFY: klass._notify,
         win32con.WM_CLOSE: klass._close,
         win32con.WM_DESTROY: klass._destroy,
         win32con.WM_COMMAND: klass._command,
     }
     klass.CLASS_ATOM = win32gui.RegisterClass(klass.WNDCLASS)
     klass._instance = {}
     return
コード例 #25
0
 def __init__(self, netkeeper):
     msg_TaskbarRestart = win32gui.RegisterWindowMessage("NKService")
     message_map = {
         msg_TaskbarRestart: self.OnRestart,
         win32con.WM_DESTROY: self.OnDestroy,
         win32con.WM_COMMAND: self.OnCommand,
         win32con.WM_USER + 20: self.OnTaskbarNotify,
     }
     # 注册窗口类
     wndclass = win32gui.WNDCLASS()
     hinst = wndclass.hInstance = win32api.GetModuleHandle(None)
     wndclass.lpszClassName = "NetkeeperTrayIcon"
     wndclass.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
     wndclass.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW)
     wndclass.hbrBackground = win32con.COLOR_WINDOW
     wndclass.lpfnWndProc = message_map
     try:
         classAtom = win32gui.RegisterClass(wndclass)
     except win32gui.error, err_info:
         if err_info.winerror != winerror.ERROR_CLASS_ALREADY_EXISTS:
             raise
コード例 #26
0
ファイル: uykutray.py プロジェクト: 5l1v3r1/uykutray
	def __init__(self):
		msg_TaskbarRestart = win32gui.RegisterWindowMessage("TaskbarOlustur");
		message_map = {
				msg_TaskbarRestart: self.OnRestart,
				win32con.WM_DESTROY: self.OnDestroy,
				win32con.WM_COMMAND: self.OnCommand,
				win32con.WM_USER+20 : self.OnTaskbarNotify,
		}

		wc = win32gui.WNDCLASS()
		hinst = wc.hInstance = win32api.GetModuleHandle(None)
		wc.lpszClassName = "murat"
		wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;
		wc.hCursor = win32api.LoadCursor( 0, win32con.IDC_ARROW )
		wc.hbrBackground = win32con.COLOR_WINDOW
		wc.lpfnWndProc = message_map 

		try:
			classAtom = win32gui.RegisterClass(wc)
		except win32gui.error, err_info:
			if err_info.winerror!=winerror.ERROR_CLASS_ALREADY_EXISTS:
				raise
コード例 #27
0
    def __init__(self, icon, hover_text, menu_options=None, on_quit=None):
        self.icon = icon
        self.icon_shared = False
        self.hover_text = hover_text
        self.on_quit = on_quit

        menu_options = menu_options or ()
        menu_options = menu_options + (('quit', None, self.QUIT),)
        self.next_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)
        self.default_menu_index = self.DEFAULT_MENU_INDEX
        self.win_class_name = self.WIN_CLASS_NAME

        #---- wndProc callback ----
        #
        self.message_dict = {
            win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart,
            win32con.WM_DESTROY: self.destroy,
            win32con.WM_CLOSE: self.destroy,
            win32con.WM_COMMAND: self.command,
            win32con.WM_USER + self.NOTIFY: self.notify,
        }
        self.notify_id = None
        self.message_loop_thread = None
        self.hwnd = None
        self.hicon = None
        self.menu = None
        # register the window class
        window_class = win32gui.WNDCLASS()
        self.hinst = window_class.hInstance = win32gui.GetModuleHandle(None)
        window_class.lpszClassName = self.win_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 = self.message_dict # could also specify a wndproc
        win32gui.RegisterClass(window_class)
コード例 #28
0
	def __init__(self):
		msg_TaskbarRestart = win32gui.RegisterWindowMessage("TaskbarOlustur");
		message_map = {
				msg_TaskbarRestart: self.OnRestart,
				win32con.WM_DESTROY: self.OnDestroy,
				win32con.WM_COMMAND: self.OnCommand,
				win32con.WM_USER+20 : self.OnTaskbarNotify,
		}
		# Register the Window class.
		wc = win32gui.WNDCLASS()
		hinst = wc.hInstance = win32api.GetModuleHandle(None)
		wc.lpszClassName = "dolarTray"
		wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;
		wc.hCursor = win32api.LoadCursor( 0, win32con.IDC_ARROW )
		wc.hbrBackground = win32con.COLOR_WINDOW
		wc.lpfnWndProc = message_map # could also specify a wndproc.

		# Don't blow up if class already registered to make testing easier
		try:
			classAtom = win32gui.RegisterClass(wc)
		except win32gui.error, err_info:
			if err_info.winerror!=winerror.ERROR_CLASS_ALREADY_EXISTS:
				raise
コード例 #29
0
    def __init__(self):
        self.code = "TabletOrderingYD"
        self.name = "平板点餐服务YD"

        # 获取编程环境下的代码路径
        # self.path = os.path.abspath(os.path.dirname(__file__))
        # 获取打包后的可执行文件路径
        self.path = os.path.dirname(sys.executable)

        # 获取配置参数
        config = configparser.ConfigParser()
        confFile = os.path.join(self.path, "wx.conf")
        if os.path.exists(confFile):
            config.read(confFile, encoding="utf-8")
            self.WXPort = config.getint("client", "WXPort")
            if self.WXPort == 0 or self.WXPort == None:
                self.WXPort = 8009
        else:
            self.WXPort = 8009
        self.logFile = os.path.join(self.path, "wxlog.log")

        # 创建日志对象
        self.logger = self._getLogger()

        msg_TaskbarRestart = win32gui.RegisterWindowMessage("TaskbarCreated")
        message_map = {
            msg_TaskbarRestart: self.OnRestart,
            win32con.WM_CLOSE: self.OnClose,
            win32con.WM_DESTROY: self.OnDestroy,
            win32con.WM_COMMAND: self.OnCommand,
            win32con.WM_USER + 20: self.OnTaskbarNotify,
            1280: self.OnPostMessage,
        }
        # Register the Window class.
        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32api.GetModuleHandle(None)
        wc.lpszClassName = self.code
        wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        wc.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW)
        wc.hbrBackground = win32con.COLOR_WINDOW
        wc.lpfnWndProc = message_map  # could also specify a wndproc.

        # Don't blow up if class already registered to make testing easier
        try:
            classAtom = win32gui.RegisterClass(wc)
        except Exception as e:
            self.logger.error(str(e))

                # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(wc.lpszClassName, self.name, style,
                                          0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT,
                                          0, 0, hinst, None)
        win32gui.UpdateWindow(self.hwnd)
        self._DoCreateIcons()

        # 获取启动WX窗口的程序句柄
        self._interHandle = 0
        if len(sys.argv) > 1:
            if sys.argv[1].isdigit():
                if self._interHandle == 0 and int(sys.argv[1]) > 0:
                    self._interHandle = int(sys.argv[1])

        # 初始化登录标志
        self._loginFlag = 0

        # 创建socket server线程
        if self._interHandle > 0:
            # 通知接口程序WX的窗口句柄
            windll.user32.PostMessageW(self._interHandle, 1280, 0, self.hwnd)

            # 创建线程共享数据队列
            self.messageQ = Queue()

            try:
                tSocket = Thread(target=self.OnSocket, args=(self.WXPort, self.messageQ, self._interHandle, ))
                tSocket.daemon = True
                tSocket.start()
            except Exception as e:
                self.logger.error("启动进程Err:" + str(e))
コード例 #30
0
        log("OnTaskbarNotify(%s,%s,%s,%s) button(s) lookup: %s, callback=%s",
            hwnd, msg, wparam, lparam, bm, cc)
        if bm is not None and cc:
            for button_event in bm:
                cc(*button_event)
        return 1

    def close(self):
        log("win32NotifyIcon.close()")
        win32NotifyIcon.remove_callbacks(self.hwnd)
        win32NotifyIcon.OnDestroy(self.hwnd, None, None, None)


WM_TRAY_EVENT = win32con.WM_USER + 20  #a message id we choose
message_map = {
    win32gui.RegisterWindowMessage("TaskbarCreated"): win32NotifyIcon.restart,
    win32con.WM_DESTROY: win32NotifyIcon.OnDestroy,
    win32con.WM_COMMAND: win32NotifyIcon.OnCommand,
    WM_TRAY_EVENT: win32NotifyIcon.OnTaskbarNotify,
}
NIwc = win32gui.WNDCLASS()
NIwc.hInstance = win32api.GetModuleHandle(None)
NIwc.lpszClassName = "win32NotifyIcon"
NIwc.lpfnWndProc = message_map  # could also specify a wndproc.
NIclassAtom = win32gui.RegisterClass(NIwc)


def main():
    def notify_callback(hwnd):
        menu = win32gui.CreatePopupMenu()
        win32gui.AppendMenu(menu, win32con.MF_STRING, 1024, "Generate balloon")