コード例 #1
0
ファイル: supertooltip.py プロジェクト: tawilkinson/Phoenix
    def MakeWindowTransparent(self, amount):
        """
        Makes the :class:`SuperToolTip` window transparent.

        :param `amount`: the alpha channel value.

        :note: This method is available only on Windows and requires Mark Hammond's
         pywin32 package.
        """

        if not _libimported:
            # No way, only Windows XP with Mark Hammond's win32all
            return

        # this API call is not in all SDKs, only the newer ones, so
        # we will runtime bind this
        if wx.Platform != "__WXMSW__":
            return

        hwnd = self.GetHandle()

        if not hasattr(self, "_winlib"):
            self._winlib = win32api.LoadLibrary("user32")

        pSetLayeredWindowAttributes = win32api.GetProcAddress(self._winlib,
                                                              "SetLayeredWindowAttributes")

        if pSetLayeredWindowAttributes == None:
            return

        exstyle = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
        if 0 == (exstyle & 0x80000):
            win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, exstyle | 0x80000)

        winxpgui.SetLayeredWindowAttributes(hwnd, 0, amount, 2)
コード例 #2
0
def setTransparency(hwnd, amount):
    """
	This is how the method SetTransparent()is implemented
	 on all MS Windows platforms.
	"""
    try:
        import ctypes
        _winlib = ctypes.windll.user32
        style = _winlib.GetWindowLongA(hwnd, 0xffffffecL)
        style |= 0x00080000
        _winlib.SetWindowLongA(hwnd, 0xffffffecL, style)
        _winlib.SetLayeredWindowAttributes(hwnd, 0, amount, 2)
    except ImportError:
        import win32api
        import win32con
        import winxpgui
        _winlib = win32api.LoadLibrary("user32")
        pSetLayeredWindowAttributes = win32api.GetProcAddress(
            _winlib, "SetLayeredWindowAttributes")
        if pSetLayeredWindowAttributes is None:
            return
        exstyle = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
        if (exstyle & 0x80000) == 0:
            win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE,
                                   exstyle | 0x80000)
    winxpgui.SetLayeredWindowAttributes(hwnd, 0, amount, 2)
コード例 #3
0
    def MakeTransparent(self, amount):
        """
        This is how the method SetTransparent() is implemented
            on all MS Windows platforms.
        """
        import os
        if os.name == 'nt':  # could substitute: sys.platform == 'win32'

            hwnd = self.GetHandle()
            try:
                import ctypes  # DLL library interface constants' definitions
                _winlib = ctypes.windll.user32  # create object to access DLL file user32.dll
                style = _winlib.GetWindowLongA(hwnd, '0xffff')
                style |= 0x00080000
                _winlib.SetWindowLongA(hwnd, '0xffff', style)
                _winlib.SetLayeredWindowAttributes(hwnd, 0, amount, 2)

            except ImportError:

                import win32api
                import win32con
                import winxpgui
                _winlib = win32api.LoadLibrary("user32")
                pSetLayeredWindowAttributes = win32api.GetProcAddress(
                    _winlib, "SetLayeredWindowAttributes")
                if pSetLayeredWindowAttributes == None:
                    return
                exstyle = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
                if 0 == (exstyle & 0x80000):
                    win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE,
                                           exstyle | 0x80000)
                winxpgui.SetLayeredWindowAttributes(hwnd, 0, amount, 2)
        else:
            print('OS Platform must be MS Windows')
            self.Destroy()
コード例 #4
0
ファイル: CustomGrid.py プロジェクト: dfparent/dragon-tools
    def MakeTransparent(self, alpha):
        import os, sys

        # input parameter Excel you from 0 to 100 to be consistent with other
        # transparency models.
        # The method below takes a value from 0 to 255.  Need to make the mapping.
        winAlpha = int(alpha * 2.55)

        if sys.platform == 'win32':
            hwnd = self.GetHandle()
            try:
                import ctypes  # DLL library interface constants' definitions
                _winlib = ctypes.windll.user32  # create object to access DLL file user32.dll
                style = _winlib.GetWindowLongA(hwnd, 0xffffffecL)
                style |= 0x00080000
                _winlib.SetWindowLongA(hwnd, 0xffffffecL, style)
                _winlib.SetLayeredWindowAttributes(hwnd, 0, winAlpha, 2)

            except ImportError:
                import win32api, win32con, winxpgui
                _winlib = win32api.LoadLibrary("user32")
                pSetLayeredWindowAttributes = win32api.GetProcAddress(
                    _winlib, "SetLayeredWindowAttributes")
                if pSetLayeredWindowAttributes == None:
                    return
                exstyle = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
                if 0 == (exstyle & 0x80000):
                    win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE,
                                           exstyle | 0x80000)
                winxpgui.SetLayeredWindowAttributes(hwnd, 0, amount, 2)
        else:
            print '####  OS Platform must be MS Windows'
            self.Destroy()
コード例 #5
0
 def make_transparent(self):
     style = win32gui.GetWindowLong(self.window, win32con.GWL_EXSTYLE)
     win32gui.ShowWindow(self.window, win32con.SW_HIDE)
     style |= win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED | win32con.WS_EX_TRANSPARENT | win32con.WS_EX_TOOLWINDOW | win32con.WS_EX_NOACTIVATE
     style &= ~win32con.WS_EX_APPWINDOW
     win32gui.SetWindowLong(self.window, win32con.GWL_EXSTYLE, style)
     sleep(1)
     win32gui.ShowWindow(self.window, win32con.SW_SHOW)
     winxpgui.SetLayeredWindowAttributes(self.window, 0, 0,
                                         win32con.LWA_ALPHA)
コード例 #6
0
ファイル: WindowMgr.py プロジェクト: ccutmis/d3-gamepad
 def set_window_alpha(self, wildcard, alpha_val=180):
     self.reset()
     self.find_window_wildcard(wildcard)
     self.set_foreground()
     win32gui.SetWindowLong(
         self._handle, win32con.GWL_EXSTYLE,
         win32gui.GetWindowLong(self._handle, win32con.GWL_EXSTYLE)
         | win32con.WS_EX_LAYERED)
     winxpgui.SetLayeredWindowAttributes(self._handle,
                                         win32api.RGB(0, 0, 0), alpha_val,
                                         win32con.LWA_ALPHA)
コード例 #7
0
    def set_alpha(self, alpha=100, colorkey=0, mask=False):
        """ Sets the transparency of the window. """
        if self.alpha != None:
            if not self._transparency:
                style = win32gui.GetWindowLong(self._hwnd, GWL_EXSTYLE)
                if (style & WS_EX_LAYERED) != WS_EX_LAYERED:
                    style = style | WS_EX_LAYERED
                    win32gui.SetWindowLong(self._hwnd, GWL_EXSTYLE, style)
                self._transparency = True

            if mask and colorkey:
                flags = LWA_COLORKEY
            else:
                flags = LWA_ALPHA
                if colorkey:
                    flags = flags | LWA_COLORKEY

            win_alpha = int(float(alpha) / 100 * 255)
            winxpgui.SetLayeredWindowAttributes(self._hwnd, colorkey,
                                                win_alpha, flags)
            self.alpha = int(alpha)
コード例 #8
0
    def MakeTransparent(self, amount):
        hwnd = self.GetHandle()
        try:
            import ctypes
            _winlib = ctypes.windll.user32
            style = _winlib.GetWindowLongA(hwnd, 0xffffffecL)
            style |= 0x00080000
            _winlib.SetWindowLongA(hwnd, 0xffffffecL, style)
            _winlib.SetLayeredWindowAttributes(hwnd, 0, amount, 2)

        except ImportError:
            import win32api, win32con, winxpgui
            _winlib = win32api.LoadLibrary("user32")
            pSetLayeredWindowAttributes = win32api.GetProcAddress(
                _winlib, "SetLayeredWindowAttributes")
            if pSetLayeredWindowAttributes == None:
                return
            exstyle = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
            if 0 == (exstyle & 0x80000):
                win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE,
                                       exstyle | 0x80000)
            winxpgui.SetLayeredWindowAttributes(hwnd, 0, amount, 2)
コード例 #9
0
def createOverlay(hwnd, imgOverlay):
    if (constants.debugOutputConsole == 1):
        print("Overlay: start")
        plc = win32gui.GetWindowPlacement(hwnd)
        # TODO: Find a "real" way to test if MWO is running Fullscreen or FullWindowed
        if (plc[0] != 2 or plc[1] != 3):
            print("******* Overlay: Does not work on fullscreen MWO ******")

    if (constants.overlay != 1):
        return
    bbox = win32gui.GetWindowRect(hwnd)
    time.sleep(0.2)
    width = bbox[2] - bbox[0]
    height = bbox[3] - bbox[1]
    if (height < 10 or width < 10):
        if (constants.debugOutputConsole == 1):
            print("Overlay: height/width < 10, aborting")
        return

    hwndCv = findWindow(constants.overlayTitle)
    cv2.resizeWindow(constants.overlayTitle, width, height)

    wndLongEx = win32gui.GetWindowLong(hwndCv, win32con.GWL_EXSTYLE)
    additionalStyle = win32con.WS_EX_TOPMOST | win32con.WS_EX_TRANSPARENT | win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED | win32con.WS_EX_NOACTIVATE
    wndLongEx = wndLongEx | additionalStyle
    wndLongStyle = win32con.WS_VISIBLE | win32con.WS_POPUP
    win32gui.SetWindowLong(hwndCv, win32con.GWL_EXSTYLE, wndLongEx)
    win32gui.SetWindowLong(hwndCv, win32con.GWL_STYLE, wndLongStyle)
    win32gui.SetWindowPos(hwndCv, -1, bbox[0], bbox[1], width, height, 0)
    winxpgui.SetLayeredWindowAttributes(hwndCv, win32api.RGB(0, 0, 0), 255,
                                        win32con.LWA_COLORKEY)
    if (constants.debugOutputConsole == 1):
        print("Overlay: set visible")

    cv2.imshow(constants.overlayTitle, imgOverlay)
    cv2.waitKey(1)
コード例 #10
0
    hwnd, win32con.GWL_EXSTYLE,
    win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
    | win32con.WS_EX_LAYERED)

active = True
while True:
    if active:
        win32gui.ShowWindow(hwnd, win32con.SW_SHOWMAXIMIZED)
    else:
        win32gui.ShowWindow(hwnd, win32con.SW_SHOWMINIMIZED)

    for i in range(1, 256):
        if win32api.GetAsyncKeyState(i):
            if chr(i) == "q" or chr(i) == "Q":
                winxpgui.SetLayeredWindowAttributes(hwnd,
                                                    win32api.RGB(0, 0, 0), 255,
                                                    win32con.LWA_ALPHA)
                active = True
            elif chr(i) == "a" or chr(i) == "A":
                winxpgui.SetLayeredWindowAttributes(hwnd,
                                                    win32api.RGB(0, 0, 0), 200,
                                                    win32con.LWA_ALPHA)
                active = True
            elif chr(i) == "z" or chr(i) == "Z":
                winxpgui.SetLayeredWindowAttributes(hwnd,
                                                    win32api.RGB(0, 0, 0), 0,
                                                    win32con.LWA_ALPHA)
                active = False

    time.sleep(0.01)