Skip to content

Commit ab3e35e

Browse files
committed
Add method to flash a given window
1 parent 129e63a commit ab3e35e

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

casement/enums.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from enum import Enum
2+
3+
4+
class FlashTimes(Enum):
5+
"""Windows flags for casement.utils.flashWindow().
6+
7+
https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-flashwinfo
8+
"""
9+
10+
"'Stop flashing. The system restores the window to its original state.'"
11+
FLASHW_STOP = 0
12+
"Flash the window caption."
13+
FLASHW_CAPTION = 0x00000001
14+
"Flash the taskbar button."
15+
FLASHW_TRAY = 0x00000002
16+
"""Flash both the window caption and taskbar button. This is equivalent
17+
to setting the ``FLASHW_CAPTION | FLASHW_TRAY flags``."""
18+
FLASHW_ALL = 0x00000003
19+
"Flash continuously, until the ``FLASHW_STOP`` flag is set."
20+
FLASHW_TIMER = 0x00000004
21+
"Flash continuously until the window comes to the foreground."
22+
FLASHW_TIMERNOFG = 0x0000000C

casement/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import ctypes
2+
from .enums import FlashTimes
3+
4+
5+
def flash_window(hwnd, dw_flags=None, count=1, timeout=0):
6+
"""Flashes the application depending on the os.
7+
8+
On Windows this calls FlashWindowEx. See
9+
https://msdn.microsoft.com/en-us/library/ms679348(v=vs.85).aspx for documentation.
10+
11+
Args:
12+
hwnd (int or None): Flash this hwnd id.
13+
dw_flags (casement.enums.FlashTimes): A enum value used to control the
14+
flashing behavior. See
15+
https://msdn.microsoft.com/en-us/library/ms679348(v=vs.85).aspx for more
16+
details. Defaults to FLASHW_TIMERNOFG.
17+
count (int): The number of times to flash the window. Defaults to 1.
18+
timeout (int): The rate at which the window is to be flashed in
19+
milliseconds. if zero is passed, the default cursor blink rate is used.
20+
"""
21+
22+
if dw_flags is None:
23+
dw_flags = FlashTimes.FLASHW_TIMERNOFG
24+
25+
ctypes.windll.user32.FlashWindow(hwnd, int(dw_flags.value), count, timeout)

0 commit comments

Comments
 (0)