Skip to content

Instantly share code, notes, and snippets.

@tshirtman
Last active May 2, 2021 18:52
Show Gist options
  • Save tshirtman/791495591bd3a7a3f8807211b220233b to your computer and use it in GitHub Desktop.
Save tshirtman/791495591bd3a7a3f8807211b220233b to your computer and use it in GitHub Desktop.
windows specific whole application opacity management
def _get_opacity(self):
if platform == 'win':
try:
return winxpgui.GetLayeredWindowAttributes(HWND)[1] / 255.
except Exception as e:
Logger.error(
'failed to get opacity: {}'.format(e))
else:
Logger.warning(
'window get opacity not implemented on {}'.format(platform))
return 1
def _set_opacity(self, value):
if platform == 'win':
win32gui.SetWindowLong(
HWND, win32con.GWL_EXSTYLE,
win32gui.GetWindowLong(
HWND, win32con.GWL_EXSTYLE) | win32con.WS_EX_LAYERED)
winxpgui.SetLayeredWindowAttributes(
HWND, win32api.RGB(0, 0, 0), max(1, int(value * 255)),
win32con.LWA_ALPHA)
return True
else:
Logger.error(
'window set opacity not implemented on {}'.format(platform)
)
opacity = AliasProperty(_get_opacity, _set_opacity)
@tshirtman
Copy link
Author

tshirtman commented Dec 3, 2018

to get window handle (HWND)

    def _win_find_hwnd(self, *args):
        global HWND
        HWND = win32gui.FindWindow(None, NAME)
        Logger.debug('FindWindow returned {}'.format(HWND))
        if not HWND:
            Clock.schedule_once(self._win_find_hwnd, .01)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment