Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MikeTheWatchGuy/233911fa1fc3cb6f028086a4209e6519 to your computer and use it in GitHub Desktop.
Save MikeTheWatchGuy/233911fa1fc3cb6f028086a4209e6519 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment