Exemplo n.º 1
0
    def run(self):
        hinst = win32api.GetModuleHandle(None)
        wndclass = win32gui.WNDCLASS()
        wndclass.hInstance = hinst
        wndclass.lpszClassName = "ulteoEventHandler"
        messageMap = {win32con.WM_QUERYENDSESSION: wndproc}
        wndclass.lpfnWndProc = messageMap

        try:
            myWindowClass = win32gui.RegisterClass(wndclass)
            hwnd = win32gui.CreateWindowEx(win32con.WS_EX_LEFT, myWindowClass,
                                           "ulteoEH", 0, 0, 0,
                                           win32con.CW_USEDEFAULT,
                                           win32con.CW_USEDEFAULT, 0, 0, hinst,
                                           None)
        except Exception, e:
            print("Failed to create internal windows: %s" % str(e))
Exemplo n.º 2
0
    def _win32_setup(self):
        hInstance = win32api.GetModuleHandle()
        className = str(uuid.uuid4())  # probably a better way to do this

        # http://msdn.microsoft.com/en-us/library/windows/desktop/ms633576(v=vs.85).aspx
        # win32gui does not support WNDCLASSEX.
        wndClass = win32gui.WNDCLASS()
        # http://msdn.microsoft.com/en-us/library/windows/desktop/ff729176(v=vs.85).aspx
        wndClass.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
        wndClass.lpfnWndProc = self._win_message
        wndClass.hInstance = hInstance
        wndClass.hCursor = win32gui.LoadCursor(None, win32con.IDC_ARROW)
        wndClass.hbrBackground = win32gui.GetStockObject(win32con.WHITE_BRUSH)
        wndClass.lpszClassName = className
        # win32gui does not support RegisterClassEx
        wndClassAtom = win32gui.RegisterClass(wndClass)
        return wndClassAtom, hInstance
Exemplo n.º 3
0
    def __init__(self, parent):
        '''构造函数'''

        wx.Frame.__init__(self, parent, -1, APP_TITLE)
        self.SetBackgroundColour(wx.Colour(240, 240, 240))
        self.SetSize((800, 600))
        self.Center()

        if hasattr(sys, "frozen") and getattr(sys, "frozen") == "windows_exe":
            exeName = win32api.GetModuleFileName(win32api.GetModuleHandle(None))
            icon = wx.Icon(exeName, wx.BITMAP_TYPE_ICO)
        else :
            icon = wx.Icon(APP_ICON, wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon)

        preview = wx.Panel(self, -1, style=wx.SUNKEN_BORDER)
        preview.SetBackgroundColour(wx.Colour(0, 0, 0))
        btn_capture = wx.Button(self, -1, u'拍照', size=(100, -1))
        btn_up = wx.Button(self, -1, u'↑', size=(30, 30))
        btn_down = wx.Button(self, -1, u'↓', size=(30, 30))
        btn_left = wx.Button(self, -1, u'←', size=(30, 30))
        btn_right = wx.Button(self, -1, u'→', size=(30, 30))
        tc = wx.TextCtrl(self, -1, '', style=wx.TE_MULTILINE)

        sizer_arrow_mid = wx.BoxSizer()
        sizer_arrow_mid.Add(btn_left, 0, wx.RIGHT, 16)
        sizer_arrow_mid.Add(btn_right, 0, wx.LEFT, 16)

        #sizer_arrow = wx.BoxSizer(wx.VERTICAL)
        sizer_arrow = wx.StaticBoxSizer(wx.StaticBox(self, -1, u'方向键'), wx.VERTICAL)
        sizer_arrow.Add(btn_up, 0, wx.ALIGN_CENTER|wx.ALL, 0)
        sizer_arrow.Add(sizer_arrow_mid, 0, wx.TOP|wx.BOTTOM, 1)
        sizer_arrow.Add(btn_down, 0, wx.ALIGN_CENTER|wx.ALL, 0)

        sizer_right = wx.BoxSizer(wx.VERTICAL)
        sizer_right.Add(btn_capture, 0, wx.ALL, 20)
        sizer_right.Add(sizer_arrow, 0, wx.ALIGN_CENTER|wx.ALL, 0)
        sizer_right.Add(tc, 1, wx.ALL, 10)

        sizer_max = wx.BoxSizer()
        sizer_max.Add(preview, 1, wx.EXPAND|wx.LEFT|wx.TOP|wx.BOTTOM, 5)
        sizer_max.Add(sizer_right, 0, wx.EXPAND|wx.ALL, 0)

        self.SetAutoLayout(True)
        self.SetSizer(sizer_max)
        self.Layout()
Exemplo n.º 4
0
    def __init__(self):
        wx.Frame.__init__(self, None, -1, APP_TITLE, style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER)
        # 默认style是下列项的组合:wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.RESIZE_BORDER | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN

        self.SetBackgroundColour(wx.Colour(224, 224, 224))
        self.SetSize((800, 600))
        self.Center()

        # # 以下代码处理图标
        if hasattr(sys, "frozen") and getattr(sys, "frozen") == "windows_exe":
            exeName = win32api.GetModuleFileName(win32api.GetModuleHandle(None))
            icon = wx.Icon(exeName, wx.BITMAP_TYPE_ICO)
        else:
            icon = wx.Icon(APP_ICON, wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon)

        # 以下可以添加各类控件
        wx.StaticText(self, -1, u'第一行输入框:', pos=(40, 50), size=(100, -1), style=wx.ALIGN_RIGHT)
        wx.StaticText(self, -1, u'第二行输入框:', pos=(40, 80), size=(100, -1), style=wx.ALIGN_RIGHT)
        self.tip = wx.StaticText(self, -1, u'www', pos=(145, 110), size=(150, -1), style=wx.ST_NO_AUTORESIZE)

        self.tc1 = wx.TextCtrl(self, -1, '', pos=(145, 50), size=(150, -1), name='TC01', style=wx.TE_CENTER)
        self.tc2 = wx.TextCtrl(self, -1, '', pos=(145, 80), size=(150, -1), name='TC02',
                               style=wx.TE_PASSWORD | wx.ALIGN_RIGHT)

        btn_mea = wx.Button(self, -1, u'鼠标左键事件', pos=(350, 50), size=(100, 35))
        btn_meb = wx.Button(self, -1, u'鼠标所有事件', pos=(350, 80), size=(100, 25))
        btn_close = wx.Button(self, -1, u'关闭窗口', pos=(350, 110), size=(100, 25))

        # 控件事件
        self.tc1.Bind(wx.EVT_TEXT, self.EvtText)
        self.tc2.Bind(wx.EVT_TEXT, self.EvtText)
        self.Bind(wx.EVT_BUTTON, self.OnClose, btn_close)

        # 鼠标事件
        btn_mea.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
        btn_mea.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
        btn_mea.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
        btn_meb.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)

        # 键盘事件
        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)

        # 系统事件
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        self.Bind(wx.EVT_SIZE, self.On_size)
Exemplo n.º 5
0
    def _create_window_class():  # noqa: D102
        import win32api
        import win32con
        import win32gui

        # register the window class once
        if NotificationWindow._wc is None:
            NotificationWindow._wc = win32gui.WNDCLASS()
            NotificationWindow._wc.hInstance = win32api.GetModuleHandle(None)
            NotificationWindow._wc.lpszClassName = 'ColconTaskbar'
            NotificationWindow._wc.lpfnWndProc = {
                win32con.WM_DESTROY: NotificationWindow._on_destroy,
            }
            NotificationWindow._class_atom = win32gui.RegisterClass(
                NotificationWindow._wc)

        return (NotificationWindow._wc, NotificationWindow._class_atom)
Exemplo n.º 6
0
def main():
    #get instance handle
    hInstance = win32api.GetModuleHandle()

    # the class name
    className = 'SimpleWin32'


    # create and initialize window class
    wndClass                = win32gui.WNDCLASS()
    wndClass.style          = win32con.CS_HREDRAW | win32con.CS_VREDRAW
    wndClass.lpfnWndProc    = wndProc
    wndClass.hInstance      = hInstance
    wndClass.hIcon          = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
    wndClass.hCursor        = win32gui.LoadCursor(0, win32con.IDC_ARROW)
    wndClass.hbrBackground  = win32gui.GetStockObject(win32con.WHITE_BRUSH)
    wndClass.lpszClassName  = className

    # register window class
    wndClassAtom = None
    try:
        wndClassAtom = win32gui.RegisterClass(wndClass)
    except Exception e :
        print(e) 
        raise e

    hWindow = win32gui.CreateWindow(
        wndClassAtom,                   #it seems message dispatching only works with the atom, not the class name
        'Python Win32 Window',
        win32con.WS_OVERLAPPEDWINDOW,
        win32con.CW_USEDEFAULT,
        win32con.CW_USEDEFAULT,
        win32con.CW_USEDEFAULT,
        win32con.CW_USEDEFAULT,
        0,
        0,
        hInstance,
        None)

    # Show & update the window
    win32gui.ShowWindow(hWindow, win32con.SW_SHOWNORMAL)
    win32gui.UpdateWindow(hWindow)

    # Dispatch messages
    win32gui.PumpMessages()
Exemplo n.º 7
0
    def __init__(self):
        '''构造函数'''
        wx.Frame.__init__(self,None,-1,APP_TITLE,style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER)
        #默认style是下列组合:wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.RESIZE_BORDER | wx.SYSTEM_MENU | wx.CAPTION
        self.SetBackgroundColour(wx.Colour(244,244,244))
        self.SetSize((800,600))
        self.Center()

        # 以下代码处理图标
        if hasattr(sys, "frozen") and getattr(sys, "frozen") == "windows_exe":
            exeName = win32api.GetModuleFileName(win32api.GetModuleHandle(None))
            icon = wx.Icon(exeName, wx.BITMAP_TYPE_ICO)
        else:
            icon = wx.Icon(APP_ICON, wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon)

        # 以下可以添加各类控件
        pass
Exemplo n.º 8
0
    def _DoCreateIcons(self):
        # Try and find a custom icon
        hinst =  win32api.GetModuleHandle(None)
        iconPathName = os.path.abspath(".\\main.ico" )
        if os.path.isfile(iconPathName):
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hicon = win32gui.LoadImage(hinst, iconPathName, win32con.IMAGE_ICON, 0, 0, icon_flags)
        else:
            hicon = win32gui.ExtractIcon(hinst, sys.executable, 0)

        flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
        nid = (self.hwnd, 0, flags, win32con.WM_USER+20, hicon, "HTPC Thermostat")
        try:
            win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
        except win32gui.error:
            # This is common when windows is starting, and this code is hit
            # before the taskbar has been created.
            log.debug("Failed to add the taskbar icon - is explorer running?")
Exemplo n.º 9
0
def _get_icon_bitmap_from_shell32_dll(index_number, size):
    assert isinstance(index_number, int)
    assert is_win

    import win32api
    
    width, height = size
    shell32_dll = win32api.GetModuleFileName(
        win32api.GetModuleHandle('shell32.dll')
    )
    return wx.BitmapFromIcon(
        wx.Icon(
            '%s;%s' % (shell32_dll, index_number),
            wx.BITMAP_TYPE_ICO,
            desiredWidth=width,
            desiredHeight=height
        )
    )
Exemplo n.º 10
0
    def _push(self, title, msg, icon_path, duration, threaded):
        if self._thread and threaded:
            self._thread.join()
        message_map = {win32con.WM_DESTROY: self.on_destroy}

        # register the window class
        self.wc = win32gui.WNDCLASS()
        self.hinst = self.wc.hInstance = win32api.GetModuleHandle(None)
        self.wc.lpszClassName = str("PythonTaskbar")  # Must be a string
        self.wc.lpfnWndProc = message_map
        try:
            self.classAtom = win32gui.RegisterClass(self.wc)
        except Exception:
            pass

        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(self.classAtom, "Taskbar", style, 0,
                                          0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0,
                                          self.hinst, None)
        win32gui.UpdateWindow(self.hwnd)

        if icon_path is not None:
            icon_path = os.path.realpath(icon_path)
        icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE

        try:
            hicon = win32gui.LoadImage(self.hinst, icon_path,
                                       win32gui.IMAGE_ICON, 0, 0, icon_flags)
        except Exception:
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        # Taskbar icon
        flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
        nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, hicon, "Tooltip")
        win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
        win32gui.Shell_NotifyIcon(
            win32gui.NIM_MODIFY,
            (self.hwnd, 0, win32gui.NIF_INFO, win32con.WM_USER + 20, hicon,
             "Balloon Tooltip", msg, 200, title))
        time.sleep(duration)
        win32gui.DestroyWindow(self.hwnd)
        win32gui.UnregisterClass(self.wc.lpszClassName, None)
        return None
Exemplo n.º 11
0
    def listen(self):
        """
        Calls `handlers` for each keyboard event received. This is a blocking call.
        """
        # Adapted from http://www.hackerthreads.org/Topic-42395
        from ctypes import windll, CFUNCTYPE, POINTER, c_int, c_void_p, byref

        event_types = {
            win32con.WM_KEYDOWN: 'key down',
            win32con.WM_KEYUP: 'key up',
            0x104: 'key down',  # WM_SYSKEYDOWN, used for Alt key.
            0x105: 'key up',  # WM_SYSKEYUP, used for Alt key.                 
        }

        def low_level_handler(nCode, wParam, lParam):
            """
            Processes a low level Windows keyboard event.
            """
            event = KeyboardEvent(event_types[wParam], lParam[0], lParam[1],
                                  lParam[2] == 32, lParam[3])
            for handler in self.handlers:
                handler(event)

            # Be a good neighbor and call the next hook.
            return windll.user32.CallNextHookEx(hook_id, nCode, wParam, lParam)

        # Our low level handler signature.
        CMPFUNC = CFUNCTYPE(c_int, c_int, c_int, POINTER(c_void_p))
        # Convert the Python handler into C pointer.
        pointer = CMPFUNC(low_level_handler)

        # Hook both key up and key down events for common keys (non-system).
        hook_id = windll.user32.SetWindowsHookExA(
            win32con.WH_KEYBOARD_LL, pointer, win32api.GetModuleHandle(None),
            0)

        # Register to remove the hook when the interpreter exits. Unfortunately a
        # try/finally block doesn't seem to work here.
        atexit.register(windll.user32.UnhookWindowsHookEx, hook_id)

        while self.keep_running:
            msg = win32gui.GetMessage(None, 0, 0)
            win32gui.TranslateMessage(byref(msg))
            win32gui.DispatchMessage(byref(msg))
Exemplo n.º 12
0
    def __init__(self, parent, name, commands=None, icon_path=None):
        self.parent = parent
        self.name = name
        self.WM_NOTIFY = win32con.WM_USER + 20

        wndproc = {
            win32con.WM_DESTROY: self.on_destroy,
            win32con.WM_COMMAND: self.on_command,
            self.WM_NOTIFY: self.on_tray_notify,
        }

        wc = win32gui.WNDCLASS()
        wc.hInstance = hinst = win32api.GetModuleHandle(None)
        wc.lpszClassName = name.title()
        wc.lpfnWndProc = wndproc
        class_atom = win32gui.RegisterClass(wc)
        self.hwnd = win32gui.CreateWindow(wc.lpszClassName, "",
                                          win32con.WS_POPUP, 0, 0, 1, 1,
                                          parent, 0, hinst, None)
        win32gui.UpdateWindow(self.hwnd)

        if icon_path is not None and os.path.isfile(icon_path):
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hicon = win32gui.LoadImage(None, icon_path, win32con.IMAGE_ICON, 0,
                                       0, icon_flags)
        else:
            shell_dll = os.path.join(win32api.GetSystemDirectory(),
                                     "shell32.dll")
            large, small = win32gui.ExtractIconEx(shell_dll, 19, 1)  #19 or 76
            hicon = small[0]
            win32gui.DestroyIcon(large[0])
        self.hicon = hicon

        flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP | win32gui.NIF_INFO
        nid = (self.hwnd, 0, flags, self.WM_NOTIFY, self.hicon, self.name)
        win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)

        self.next_command_id = 1000
        self.commands = {}
        self.register_command('Exit',
                              lambda: win32gui.DestroyWindow(self.hwnd))
        if commands is not None:
            for n, f in commands[::-1]:
                self.register_command(n, f)
Exemplo n.º 13
0
    def __init__(self, parent):
        '''构造函数'''

        wx.Frame.__init__(self, parent, -1, APP_TITLE)
        to_bmp_image = wx.Image(BACK_IMG, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
        self.bitmap = wx.StaticBitmap(self, -1, to_bmp_image, (0, 0))
        self.SetBackgroundColour('white')
        self.SetSize((400, 300))
        self.SetMaxSize((400, 300))
        self.Center()
        font = wx.Font(30, wx.DECORATIVE, wx.FONTSTYLE_NORMAL,
                       wx.FONTWEIGHT_NORMAL, False, 'Monaco')
        if hasattr(sys, "frozen") and getattr(sys, "frozen") == "windows_exe":
            exeName = win32api.GetModuleFileName(
                win32api.GetModuleHandle(None))
            icon = wx.Icon(exeName, wx.BITMAP_TYPE_ICO)
        else:
            icon = wx.Icon(APP_ICON, wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon)

        self.faceDatabaseButton = wx.Button(self.bitmap,
                                            -1,
                                            u'系统人脸库',
                                            size=(100, 40))
        self.staticFaceRecognitionButton = wx.Button(self.bitmap,
                                                     -1,
                                                     u'静态人脸识别',
                                                     size=(100, 40))
        self.dynamicFaceRecognitionButton = wx.Button(self.bitmap,
                                                      -1,
                                                      u'实时人脸识别',
                                                      size=(100, 40))
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.faceDatabaseButton, 0, wx.ALIGN_CENTER | wx.ALL, 30)
        sizer.Add(self.staticFaceRecognitionButton, 0,
                  wx.ALIGN_CENTER | wx.ALL, 0)
        sizer.Add(self.dynamicFaceRecognitionButton, 0,
                  wx.ALIGN_CENTER | wx.ALL, 30)

        self.dynamicFaceRecognitionButton.Bind(wx.EVT_BUTTON, self.OnDFRB)

        self.SetAutoLayout(True)
        self.SetSizer(sizer)
        self.Layout()
Exemplo n.º 14
0
	def __init__(self , className, serverIp, serverPort, **opts ): 
		message_map = {
			win32con.WM_DESTROY: self.OnDestroy,
			win32con.WM_CLOSE: self.OnClose,
			win32con.WM_COPYDATA: self.OnCopyData,
		}

		wc = win32gui.WNDCLASS() 
		wc.hIcon =  win32gui.LoadIcon(0, win32con.IDI_APPLICATION) 
		wc.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW) 
		wc.hbrBackground = win32con.COLOR_WINDOW 
#		wc.lpszClassName = "WinAdapter"
		wc.lpszClassName = className
		wc.lpfnWndProc = message_map 
		self.hinst = wc.hInstance = win32api.GetModuleHandle(None) 
		self.cAtom = win32gui.RegisterClass(wc)

		self.ConnectorHash = {}
		self.conList	= []
		self.busTh		= None	# busServer thread
		
		#print 'adapter: hinst: %s\n' % self.hinst
		
		self.hwnd = win32gui.CreateWindowEx( 
		win32con.WS_EX_APPWINDOW, 
		self.cAtom, 
		className, #"WinAdapter App",
		win32con.WS_OVERLAPPED | win32con.WS_SYSMENU, 
		win32con.CW_USEDEFAULT, 0, 
		win32con.CW_USEDEFAULT, 0, 
		0, 0, self.hinst, None) 

		global g_HWNDMAIN
		g_HWNDMAIN = self.hwnd

		##win32gui.ShowWindow(self.hwnd, win32con.SW_SHOWDEFAULT) 
		#win32gui.UpdateWindow(self.hwnd) 

		__LOG__.Trace( "WINDOW :[%d]" % (g_HWNDMAIN),  (logging.CRITICAL) )

		self.serverIp	= serverIp
		self.serverPort	= serverPort
		self.busTh 		= busThread( self.serverIp, self.serverPort, **opts )
		self.busTh.start()
Exemplo n.º 15
0
    def __init__(self, wp, imgfile, menu):
        # Create window procedure
        wp.update({
            win32con.WM_DESTROY: self.__destroy,
            win32con.WM_COMMAND: self.command,
            self.MSG_NOTIFY: self.__notify,
        })

        # Window class
        wc = win32gui.WNDCLASS()
        wc.hInstance = win32api.GetModuleHandle(None)
        wc.lpszClassName = 'TrayIcon'
        wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        wc.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW)
        wc.hbrBackground = win32con.COLOR_WINDOW
        wc.lpfnWndProc = wp

        # Register window class
        win32gui.RegisterClass(wc)

        # Create Window
        self.hwnd = win32gui.CreateWindow(
            wc.lpszClassName, '', win32con.WS_OVERLAPPED | win32con.WS_SYSMENU,
            0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0,
            wc.hInstance, None)
        win32gui.UpdateWindow(self.hwnd)

        # Create icon
        self.hicon = win32gui.LoadImage(
            wc.hInstance, imgfile, win32con.IMAGE_ICON, 0, 0,
            win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE)

        # Add icon into task bar
        flag = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
        nid = (self.hwnd, 0, flag, self.MSG_NOTIFY, self.hicon, self.TITLE)
        win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)

        # Create popup menu
        self.menu = win32gui.CreatePopupMenu()
        for text, item in menu:
            self.menu = TrayIcon.create_menu(self.menu, item, text)

        super().__init__()
Exemplo n.º 16
0
    def _DoCreateIcons(self):
        # Try and find a custom icon
        hinst = win32api.GetModuleHandle(None)
        iconPathName = os.path.abspath(
            os.path.join(os.path.split(sys.executable)[0], "img/TrayIcon.ico"))
        if not os.path.isfile(iconPathName):
            # Look in the current folder tree.
            iconPathName = "img/TrayIcon.ico"
        if os.path.isfile(iconPathName):
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hicon = win32gui.LoadImage(hinst, iconPathName,
                                       win32con.IMAGE_ICON, 0, 0, icon_flags)
        else:
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
        nid = (self.hwnd, 0, flags, MainWindow.WM_TASKBAR_NOTIFY, hicon,
               "Blindata Antivirus")
        win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
Exemplo n.º 17
0
    def __init__(self, root, all_sessions=False):
        wc = gui.WNDCLASS()
        wc.hInstance = hInst = api.GetModuleHandle(None)
        wc.lpszClassName = self.className
        wc.lpfnWndProc = self.WndProc
        self.classAtom = gui.RegisterClass(wc)
        self.root = root

        style = 0
        self.hWnd = gui.CreateWindow(self.classAtom, self.wndName, style, 0, 0,
                                     con.CW_USEDEFAULT, con.CW_USEDEFAULT, 0,
                                     0, hInst, None)
        gui.UpdateWindow(self.hWnd)

        if all_sessions:
            scope = ts.NOTIFY_FOR_ALL_SESSIONS
        else:
            scope = ts.NOTIFY_FOR_THIS_SESSION
        ts.WTSRegisterSessionNotification(self.hWnd, scope)
Exemplo n.º 18
0
 def __init__(self):
     win32gui.InitCommonControls()
     self.hinst = win32api.GetModuleHandle(None)
     className = 'MyWndClass'
     message_map = {
         win32con.WM_DESTROY: self.OnDestroy,
     }
     wc = win32gui.WNDCLASS()
     wc.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
     wc.lpfnWndProc = message_map
     wc.lpszClassName = className
     win32gui.RegisterClass(wc)
     style = win32con.WS_OVERLAPPEDWINDOW
     self.hwnd = win32gui.CreateWindow(className, 'My win32api app', style,
                                       win32con.CW_USEDEFAULT,
                                       win32con.CW_USEDEFAULT, 300, 300, 0,
                                       0, self.hinst, None)
     win32gui.UpdateWindow(self.hwnd)
     win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW)
    def __init__(self, iconPath=None):

        self.iconPath = iconPath
        self.status = []

        msg_TaskbarRestart = \
            win32api.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 = 'web2pyTaskbar'
        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,
            'web2pyTaskbar',
            style,
            0,
            0,
            win32con.CW_USEDEFAULT,
            win32con.CW_USEDEFAULT,
            0,
            0,
            hinst,
            None,
        )
        win32gui.UpdateWindow(self.hwnd)
        self.SetServerStopped()
Exemplo n.º 20
0
 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)
Exemplo n.º 21
0
    def __init__(self, adtClassName, regKey):
        message_map = {
            win32con.WM_DESTROY: self.OnDestroy,
            win32con.WM_COPYDATA: self.OnCopyData,
        }

        wc = win32gui.WNDCLASS()
        wc.hIcon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
        wc.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
        wc.hbrBackground = win32con.COLOR_WINDOW
        wc.lpszClassName = "Client_2"
        wc.lpfnWndProc = message_map
        self.hinst = wc.hInstance = win32api.GetModuleHandle(None)

        self.cAtom = win32gui.RegisterClass(wc)

        self.hwnd = win32gui.CreateWindowEx(
            win32con.WS_EX_APPWINDOW, self.cAtom, "Client",
            win32con.WS_OVERLAPPED | win32con.WS_SYSMENU,
            win32con.CW_USEDEFAULT, 0, win32con.CW_USEDEFAULT, 0, 0, 0,
            self.hinst, None)

        print '    [INIT] client : hinst: ', self.hinst, self.hwnd
        win32gui.ShowWindow(self.hwnd, win32con.SW_SHOWDEFAULT)
        win32gui.UpdateWindow(self.hwnd)

        #hWnd = win32gui.FindWindow("WinAdapter", None)
        hWnd = win32gui.FindWindow(adtClassName, None)
        ##################################################
        msg = "REG|^|%s|^|%s" % (self.hwnd, regKey)
        ##################################################

        char_buffer = array.array("c", msg)

        int_data = 1
        char_buffer_address = char_buffer.buffer_info()[0]
        char_buffer_size = char_buffer.buffer_info()[1]

        copy_struct = struct.pack(g_CopyFmt, int_data, char_buffer_size,
                                  char_buffer_address)
        win32gui.SendMessage(hWnd, win32con.WM_COPYDATA, 0, copy_struct)

        print "    [SEND] client -> bus [%s]" % msg
Exemplo n.º 22
0
    def CreateViewWindow(self, prev, settings, browser, rect):
        print(
            "ScintillaShellView.CreateViewWindow",
            prev,
            settings,
            browser,
            rect)
        # Make sure scintilla.dll is loaded.  If not, find it on sys.path
        # (which it generally is for Pythonwin)
        try:
            win32api.GetModuleHandle("Scintilla.dll")
        except win32api.error:
            for p in sys.path:
                fname = os.path.join(p, "Scintilla.dll")
                if not os.path.isfile(fname):
                    fname = os.path.join(p, "Build", "Scintilla.dll")
                if os.path.isfile(fname):
                    win32api.LoadLibrary(fname)
                    break
            else:
                raise RuntimeError("Can't find scintilla!")

        style = win32con.WS_CHILD | win32con.WS_VSCROLL | \
            win32con.WS_HSCROLL | win32con.WS_CLIPCHILDREN | \
            win32con.WS_VISIBLE
        self.hwnd = win32gui.CreateWindow("Scintilla", "Scintilla", style,
                                          rect[0], rect[1], rect[2] -
                                          rect[0], rect[3] - rect[1],
                                          self.hwnd_parent, 1000, 0, None)

        message_map = {
            win32con.WM_SIZE: self.OnSize,
        }
#        win32gui.SetWindowLong(self.hwnd, win32con.GWL_WNDPROC, message_map)

        file_data = file(self.filename, "U").read()

        self._SetupLexer()
        self._SendSci(scintillacon.SCI_ADDTEXT, len(file_data), file_data)
        if self.lineno is not None:
            self._SendSci(scintillacon.SCI_GOTOLINE, self.lineno)
        print("Scintilla's hwnd is", self.hwnd)
Exemplo n.º 23
0
def get_new_desktop_name(parent_hwnd):
    """ Create a dialog box to ask the user for name of desktop to be created """
    msgs={win32con.WM_COMMAND:desktop_name_dlgproc,
          win32con.WM_CLOSE:desktop_name_dlgproc,
          win32con.WM_DESTROY:desktop_name_dlgproc}
    # dlg item [type, caption, id, (x,y,cx,cy), style, ex style
    style=win32con.WS_BORDER|win32con.WS_VISIBLE|win32con.WS_CAPTION|win32con.WS_SYSMENU  ## |win32con.DS_SYSMODAL
    h=win32gui.CreateDialogIndirect(
        win32api.GetModuleHandle(None),
        [['One ugly dialog box !',(100,100,200,100),style,0],
         ['Button','Create', win32con.IDOK, (10,10,30,20),win32con.WS_VISIBLE|win32con.WS_TABSTOP|win32con.BS_HOLLOW|win32con.BS_DEFPUSHBUTTON],
         ['Button','Never mind', win32con.IDCANCEL, (45,10,50,20),win32con.WS_VISIBLE|win32con.WS_TABSTOP|win32con.BS_HOLLOW],
         ['Static','Desktop name:',71,(10,40,70,10),win32con.WS_VISIBLE],
         ['Edit','',72,(75,40,90,10),win32con.WS_VISIBLE]],
        parent_hwnd, msgs)     ## parent_hwnd, msgs)

    win32gui.EnableWindow(h,True)
    hcontrol=win32gui.GetDlgItem(h,72)
    win32gui.EnableWindow(hcontrol,True)
    win32gui.SetFocus(hcontrol)
Exemplo n.º 24
0
    def __init__(self, host, port):

        self.host = host
        self.port = port

        message_map = {win32con.WM_DEVICECHANGE: self.onDeviceChange}

        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32api.GetModuleHandle(None)
        wc.lpszClassName = "DeviceChangeDemo"
        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
        classAtom = win32gui.RegisterClass(wc)
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(classAtom, "Device Change Demo",
                                          style, 0, 0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)
Exemplo n.º 25
0
    def _DoCreateIcons(self):
        # Try and find a custom icon
        hinst = win32api.GetModuleHandle(None)

        icons = glob.glob("*.ico")
        if len(icons) > 0:
            iconPathName = os.path.abspath(os.path.join(os.getcwd(), icons[0]))
        else:
            iconPathName = os.path.abspath(
                os.path.join(os.path.split(sys.executable)[0], "pyc.ico"))
            #sys.executalbe为python解释程序路径
        if not os.path.isfile(iconPathName):  #如果系统ico文件不存在
            # Look in DLLs dir, a-la py 2.5
            iconPathName = os.path.abspath(
                os.path.join(
                    os.path.split(sys.executable)[0], "DLLs", "pyc.ico"))
        if not os.path.isfile(iconPathName):
            # Look in the source tree.
            iconPathName = os.path.abspath(
                os.path.join(
                    os.path.split(sys.executable)[0], "..\\PC\\pyc.ico"))
        if os.path.isfile(iconPathName):
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE  #ico标识,从文件载入和默认大小
            hicon = win32gui.LoadImage(hinst, iconPathName,
                                       win32con.IMAGE_ICON, 0, 0,
                                       icon_flags)  #载入.ico文件
            '''handle = LoadImage(hinst,name,type,cx,cy,fuload)'''
        else:
            print("Can't find a Python icon file - using default")
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP | win32gui.NIF_INFO  #定义托盘图标的样式
        nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, hicon, "安全生产计时器",
               "安全生产计时器系统托盘图标")
        #最后一个选项猪已经跑。。”是气泡提示内容
        try:
            win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)  #增加系统托盘图标
        except win32gui.error:
            # This is common when windows is starting, and this code is hit
            # before the taskbar has been created.
            print("Failed to add the taskbar icon - is explorer running?")
Exemplo n.º 26
0
    def _DoCreateIcons(self):
        hinst = win32api.GetModuleHandle(None)
        iconPathName = os.path.join(os.getcwd(),
                                    'CapsOFF.ico')  # set path to a tray icon
        icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE

        #checks if a choosen path contains an icon
        try:
            hicon = win32gui.LoadImage(hinst, iconPathName,
                                       win32con.IMAGE_ICON, 0, 0, icon_flags)
        except:
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        # sets some flags
        flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP

        # creates tuple, consisting of
        # 1) our program's window's handler
        # 2) zero (?)
        # 3) our flags
        # 4) WM_USER constant + 20
        # 5) handle of loaded icon
        # 6) Name of tray icon when mouse pointing on it
        nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, hicon,
               "Kick Ass Prog")

        try:
            # implements our settings and sets (win32gui.NIM_ADD)
            # our window (nid)in tray
            win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
            win32gui.Shell_NotifyIcon(win32gui.NIM_MODIFY, (self.hwnd, 0, win32gui.NIF_INFO, \
                                      win32con.WM_USER+20, hicon, "Notification", \
                                      'Double-click on me to close', 200, 'Info'))
        except win32gui.error:
            # This is common when windows is starting, and this code is hit
            # before the taskbar has been created.
            print("Failed to add the taskbar icon - is explorer running?")
            # but keep running anyway - when explorer starts, we get the
            # TaskbarCreated message.

        Thread(target=self.show_Caps_state).start()
Exemplo n.º 27
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()
Exemplo n.º 28
0
    def __init__(self, parent):
        '''构造函数'''

        wx.Frame.__init__(self, parent, -1, APP_TITLE)
        self.SetBackgroundColour(wx.Colour(224, 224, 224))
        self.SetSize((320, 300))
        self.Center()

        if hasattr(sys, "frozen") and getattr(sys, "frozen") == "windows_exe":
            exeName = win32api.GetModuleFileName(win32api.GetModuleHandle(None))
            icon = wx.Icon(exeName, wx.BITMAP_TYPE_ICO)
        else :
            icon = wx.Icon(APP_ICON, wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon)

        #font = wx.Font(24, wx.DECORATIVE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, 'Comic Sans MS')
        font = wx.Font(30, wx.DECORATIVE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, 'Monaco')

        self.clock = wx.StaticText(self, -1, u'08:00:00', pos=(50,50), size=(200,50), style=wx.TE_CENTER|wx.SUNKEN_BORDER)
        self.clock.SetForegroundColour(wx.Colour(0, 224, 32))
        self.clock.SetBackgroundColour(wx.Colour(0, 0, 0))
        self.clock.SetFont(font)

        self.stopwatch = wx.StaticText(self, -1, u'0:00:00.0', pos=(50,150), size=(200,50), style=wx.TE_CENTER|wx.SUNKEN_BORDER)
        self.stopwatch.SetForegroundColour(wx.Colour(0, 224, 32))
        self.stopwatch.SetBackgroundColour(wx.Colour(0, 0, 0))
        self.stopwatch.SetFont(font)

        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
        self.timer.Start(50)

        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)

        self.sec_last = None
        self.is_start = False
        self.t_start = None

        thread_sw = threading.Thread(target=self.StopWatchThread)
        thread_sw.setDaemon(True)
        thread_sw.start()
Exemplo n.º 29
0
    def __init__(self):
        win32gui.InitCommonControls()
        self.hinst = win32api.GetModuleHandle(None)

        # Define window class
        className = 'MyWndClass'
        windowName = 'My Window'
        wc = win32gui.WNDCLASS()
        wc.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
        wc.lpfnWndProc = {
            win32con.WM_COMMAND: self.on_command,
            win32con.WM_DESTROY: self.on_destroy,
            win32con.WM_GETMINMAXINFO: self.on_minmaxinfo,
            win32con.WM_NCHITTEST: self.on_hittest,
            win32con.WM_NCCALCSIZE: self.on_calcsize,
            win32con.WM_SIZE: self.on_size,
        }
        wc.lpszClassName = className
        win32gui.RegisterClass(wc)

        # Instantiate window
        self.hwnd = win32gui.CreateWindow(className, windowName,
                                          win32con.WS_OVERLAPPEDWINDOW,
                                          win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 300, 300, 0,
                                          0, self.hinst, None)

        win32gui.UpdateWindow(self.hwnd)
        win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW)

        # Make borderless
        style = win32gui.GetWindowLong(self.hwnd, win32con.GWL_STYLE)
        win32gui.SetWindowLong(self.hwnd, win32con.GWL_STYLE,
                               style & ~border_style_flags)

        # Extend dwm frame. In other words, have the Windows compositor handle
        # a 1px transparent border. This is an easy way to enable Aero snap
        # functionality.
        margins = MARGINS(1, 1, 1, 1)
        windll.dwmapi.DwmExtendFrameIntoClientArea(self.hwnd, margins)
        win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW)
Exemplo n.º 30
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