diff --git a/casement/enums.py b/casement/enums.py new file mode 100644 index 0000000..f301e79 --- /dev/null +++ b/casement/enums.py @@ -0,0 +1,22 @@ +from enum import Enum + + +class FlashTimes(Enum): + """Windows flags for casement.utils.flashWindow(). + + https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-flashwinfo + """ + + "'Stop flashing. The system restores the window to its original state.'" + FLASHW_STOP = 0 + "Flash the window caption." + FLASHW_CAPTION = 0x00000001 + "Flash the taskbar button." + FLASHW_TRAY = 0x00000002 + """Flash both the window caption and taskbar button. This is equivalent + to setting the ``FLASHW_CAPTION | FLASHW_TRAY flags``.""" + FLASHW_ALL = 0x00000003 + "Flash continuously, until the ``FLASHW_STOP`` flag is set." + FLASHW_TIMER = 0x00000004 + "Flash continuously until the window comes to the foreground." + FLASHW_TIMERNOFG = 0x0000000C diff --git a/casement/utils.py b/casement/utils.py new file mode 100644 index 0000000..d04f02f --- /dev/null +++ b/casement/utils.py @@ -0,0 +1,25 @@ +import ctypes +from .enums import FlashTimes + + +def flash_window(hwnd, dw_flags=None, count=1, timeout=0): + """Flashes the application depending on the os. + + On Windows this calls FlashWindowEx. See + https://msdn.microsoft.com/en-us/library/ms679348(v=vs.85).aspx for documentation. + + Args: + hwnd (int or None): Flash this hwnd id. + dw_flags (casement.enums.FlashTimes): A enum value used to control the + flashing behavior. See + https://msdn.microsoft.com/en-us/library/ms679348(v=vs.85).aspx for more + details. Defaults to FLASHW_TIMERNOFG. + count (int): The number of times to flash the window. Defaults to 1. + timeout (int): The rate at which the window is to be flashed in + milliseconds. if zero is passed, the default cursor blink rate is used. + """ + + if dw_flags is None: + dw_flags = FlashTimes.FLASHW_TIMERNOFG + + ctypes.windll.user32.FlashWindow(hwnd, int(dw_flags.value), count, timeout)