Last active
May 2, 2021 18:52
-
-
Save tshirtman/791495591bd3a7a3f8807211b220233b to your computer and use it in GitHub Desktop.
windows specific whole application opacity management
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to get window handle (HWND)