Skip to content

Commit

Permalink
Add method to flash a given window
Browse files Browse the repository at this point in the history
  • Loading branch information
MHendricks committed Aug 5, 2022
1 parent 129e63a commit ab3e35e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
22 changes: 22 additions & 0 deletions casement/enums.py
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions casement/utils.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit ab3e35e

Please sign in to comment.