Skip to content

Commit 5c30c4f

Browse files
committed
Add visible() function and isVisible property for controls
1 parent ea03a1a commit 5c30c4f

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

helper/WinDialog/controls/__control_template.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from ctypes.wintypes import DWORD, WORD, SHORT
33
from ..win_helper import (
44
WindowStyle as WS,
5-
EnableWindow, IsWindowEnabled
5+
EnableWindow, IsWindowEnabled,
6+
ShowWindow, ShowWindowCommands as SWC, IsWindowVisible,
67
)
78

89
from dataclasses import dataclass, field
@@ -29,6 +30,8 @@ class Control:
2930
registeredNotifications (Dict): A dictionary of registered notification messages and their associated handlers.
3031
isEnabled (bool): Indicates the state of the control.
3132
Returns True if the control is enabled, False otherwise
33+
isVisible (bool): Indicates the visible state of the control.
34+
Returns True if the control is visible, False otherwise
3235
3336
Methods:
3437
create(self) -> bytearray:
@@ -37,6 +40,9 @@ class Control:
3740
enable(self, state: bool) -> None:
3841
Enables or disables a control.
3942
43+
visible(self, state: bool) -> None:
44+
Makes a control visible or invisible.
45+
4046
4147
Note:
4248
Do not instantiate this class directly. It should be subclassed by specific controls.
@@ -101,3 +107,23 @@ def enable(self, state: bool):
101107
def isEnabled(self) -> bool :
102108
return bool(IsWindowEnabled(self.hwnd))
103109

110+
def visible(self, state: bool):
111+
'''
112+
Makes a control visible or invisible.
113+
114+
Args:
115+
state (bool): Indicates whether to make the window visible or invisible.
116+
If this parameter is True, the window will be made visible (shown).
117+
If the parameter is False, the window will be made invisible (hidden).
118+
119+
Returns:
120+
None
121+
122+
'''
123+
ShowWindow(self.hwnd, SWC.SHOW if state else SWC.HIDE)
124+
return self.isVisible
125+
126+
@property
127+
def isVisible(self) -> bool :
128+
return bool(IsWindowVisible(self.hwnd))
129+

helper/WinDialog/win_helper/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@
180180
IsWindowEnabled.restype = BOOL
181181
IsWindowEnabled.argtypes = [HWND]
182182

183+
IsWindowVisible = user32.IsWindowVisible
184+
IsWindowVisible.restype = BOOL
185+
IsWindowVisible.argtypes = [HWND]
186+
183187
class SWP(IntEnum):
184188
NOSIZE = 0x0001 #
185189
NOMOVE = 0x0002 #
@@ -591,4 +595,4 @@ class WINDOWPOS(Structure):
591595
("cy", INT),
592596
("flags", UINT),
593597
]
594-
LPWINDOWPOS = POINTER(WINDOWPOS)
598+
LPWINDOWPOS = POINTER(WINDOWPOS)

0 commit comments

Comments
 (0)