Replies: 1 comment
-
Even developers who do not use By defining # pywinauto/controls/uiawrapper.py
...
from typing import TYPE_CHECKING
...
if TYPE_CHECKING:
from typing import Iterator, List, Optional, overload
from typing_extensions import Literal, TypeAlias, TypedDict, Unpack
class _ChildrenConditions(TypedDict, total=False):
process: Optional[int]
class_name: Optional[str]
name: Optional[str]
content_only: Optional[bool]
_ChKw: TypeAlias = _ChildrenConditions
class _DescendantsConditions(TypedDict, total=False):
depth: Optional[int]
_DeKw: TypeAlias = _DescendantsConditions
_WindowTypeStr: TypeAlias = Literal["Window"]
_ButtonTypeStr: TypeAlias = Literal["Button", "CheckBox", "RadioButton"]
_ComboBoxTypeStr: TypeAlias = Literal["ComboBox"]
_EditTypeStr: TypeAlias = Literal["Edit"]
_TabControlTypeStr: TypeAlias = Literal["Tab"]
_SliderTypeStr: TypeAlias = Literal["Slider"]
_HeaderTypeStr: TypeAlias = Literal["Header"]
_HeaderItemTypeStr: TypeAlias = Literal["HeaderItem"]
_ListItemTypeStr: TypeAlias = Literal["DataItem", "ListItem"]
_ListViewTypeStr: TypeAlias = Literal["DataGrid", "List", "Table"]
_MenuItemTypeStr: TypeAlias = Literal["MenuItem"]
_MenuTypeStr: TypeAlias = Literal["MenuBar", "Menu"]
_TooltipTypeStr: TypeAlias = Literal["ToolTip"]
_ToolbarTypeStr: TypeAlias = Literal["ToolBar"]
_TreeItemTypeStr: TypeAlias = Literal["TreeItem"]
_TreeViewTypeStr: TypeAlias = Literal["Tree"]
_StaticTypeStr: TypeAlias = Literal["Text"]
_UndefinedTypeStr: TypeAlias = Literal[
"AppBar", "Calendar", "Custom", "Document", "Group", "Hyperlink",
"Image", "Pane", "ProgressBar", "ScrollBar", "SemanticZoom",
"Separator", "Spinner", "SplitButton", "StatusBar", "TabItem",
"Text", "Thumb", "TitleBar",
]
from pywinauto.controls import uia_controls as _uia_ctrls
...
@six.add_metaclass(UiaMeta)
class UIAWrapper(WinBaseWrapper):
if TYPE_CHECKING:
# children
@overload # type: ignore
def children(self, *, control_type: Optional[int] = ..., **kwargs: Unpack[_ChKw]) -> List["UIAWrapper"]: ... # type: ignore # noqa: E501 E704
@overload
def children(self, *, control_type: _WindowTypeStr, **kwargs: Unpack[_ChKw]) -> List[_uia_ctrls.WindowWrapper]: ... # noqa: E501 E704
@overload
def children(self, *, control_type: _ButtonTypeStr, **kwargs: Unpack[_ChKw]) -> List[_uia_ctrls.ButtonWrapper]: ... # noqa: E501 E704
@overload
def children(self, *, control_type: _ComboBoxTypeStr, **kwargs: Unpack[_ChKw]) -> List[_uia_ctrls.ComboBoxWrapper]: ... # noqa: E501 E704
@overload
def children(self, *, control_type: _EditTypeStr, **kwargs: Unpack[_ChKw]) -> List[_uia_ctrls.EditWrapper]: ... # noqa: E501 E704
@overload
def children(self, *, control_type: _TabControlTypeStr, **kwargs: Unpack[_ChKw]) -> List[_uia_ctrls.TabControlWrapper]: ... # noqa: E501 E704
@overload
def children(self, *, control_type: _SliderTypeStr, **kwargs: Unpack[_ChKw]) -> List[_uia_ctrls.SliderWrapper]: ... # noqa: E501 E704
@overload
def children(self, *, control_type: _HeaderTypeStr, **kwargs: Unpack[_ChKw]) -> List[_uia_ctrls.HeaderWrapper]: ... # noqa: E501 E704
@overload
def children(self, *, control_type: _HeaderItemTypeStr, **kwargs: Unpack[_ChKw]) -> List[_uia_ctrls.HeaderItemWrapper]: ... # noqa: E501 E704
@overload
def children(self, *, control_type: _ListItemTypeStr, **kwargs: Unpack[_ChKw]) -> List[_uia_ctrls.ListItemWrapper]: ... # noqa: E501 E704
@overload
def children(self, *, control_type: _ListViewTypeStr, **kwargs: Unpack[_ChKw]) -> List[_uia_ctrls.ListViewWrapper]: ... # noqa: E501 E704
@overload
def children(self, *, control_type: _MenuItemTypeStr, **kwargs: Unpack[_ChKw]) -> List[_uia_ctrls.MenuItemWrapper]: ... # noqa: E501 E704
@overload
def children(self, *, control_type: _MenuTypeStr, **kwargs: Unpack[_ChKw]) -> List[_uia_ctrls.MenuWrapper]: ... # noqa: E501 E704
@overload
def children(self, *, control_type: _TooltipTypeStr, **kwargs: Unpack[_ChKw]) -> List[_uia_ctrls.TooltipWrapper]: ... # noqa: E501 E704
@overload
def children(self, *, control_type: _ToolbarTypeStr, **kwargs: Unpack[_ChKw]) -> List[_uia_ctrls.ToolbarWrapper]: ... # noqa: E501 E704
@overload
def children(self, *, control_type: _TreeItemTypeStr, **kwargs: Unpack[_ChKw]) -> List[_uia_ctrls.TreeItemWrapper]: ... # noqa: E501 E704
@overload
def children(self, *, control_type: _TreeViewTypeStr, **kwargs: Unpack[_ChKw]) -> List[_uia_ctrls.TreeViewWrapper]: ... # noqa: E501 E704
@overload
def children(self, *, control_type: _StaticTypeStr, **kwargs: Unpack[_ChKw]) -> List[_uia_ctrls.StaticWrapper]: ... # noqa: E501 E704
@overload
def children(self, *, control_type: _UndefinedTypeStr, **kwargs: Unpack[_ChKw]) -> List["UIAWrapper"]: ... # noqa: E501 E704
# # iter_children
# @overload # type: ignore
# def iter_children(self, *, control_type: Optional[int] = ..., **kwargs: Unpack[_ChKw]) -> Iterator["UIAWrapper"]: ... # type: ignore # noqa: E501 E704
# ...
# @overload
# def iter_children(self, *, control_type: _UndefinedTypeStr, **kwargs: Unpack[_ChKw]) -> Iterator["UIAWrapper"]: ... # noqa: E501 E704
# # descendants
# @overload # type: ignore
# def descendants(self, *, control_type: Optional[int] = ..., **kwargs: Unpack[_DeKw]) -> List["UIAWrapper"]: ... # type: ignore # noqa: E501 E704
# ...
# @overload
# def descendants(self, *, control_type: _UndefinedTypeStr, **kwargs: Unpack[_DeKw]) -> List["UIAWrapper"]: ... # noqa: E501 E704
# # iter_descendants
# @overload # type: ignore
# def iter_descendants(self, *, control_type: Optional[int] = ..., **kwargs: Unpack[_DeKw]) -> Iterator["UIAWrapper"]: ... # type: ignore # noqa: E501 E704
# ...
# @overload
# def iter_descendants(self, *, control_type: _UndefinedTypeStr, **kwargs: Unpack[_DeKw]) -> Iterator["UIAWrapper"]: ... # noqa: E501 E704
...
... # simple usecases...
root = UIAWrapper(UIAElementInfo())
root.children() # List[UIAWrapper]
root.children(control_type="Button") # List[ButtonWrapper]
root.children(control_type="DataGrid") # List[ListViewWrapper]
root.children(control_type="List") # List[ListViewWrapper]
root.children(control_type="Table") # List[ListViewWrapper]
root.children(control_type="Custom") # List[UIAWrapper]
root.children(process=1234) # List[UIAWrapper]
root.children(process=None) # List[UIAWrapper]
root.children(control_type="Spam") # Invalid
root.children(foo=...) # Invalid |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Before my summer vacation, I'd like to share my proposal.
Lately, I've been providing responses like "That method is only available in
FooWrapper
, not in theBarWrapper
you're using" for recent discussions and issues.I think that part of the reasons are it's not always clear what backend one is using and what wrapper classes are available for it.
With type annotations, during development using an IDE, we can refer to types from tooltips and use "jump to the definition".
For example, adding type annotations to
BackEnd
,WindowSpecification
andDesktop
would make it easy to understand what each method ofDesktop
.Of course, I'm aware that there are ongoing challenges with
pywinauto
and there are more prioritized tasks ahead.However, I believe introducing type annotations will undoubtedly make this package more user and developer friendly.
Once the "next version" is released, I think I'll be able to dedicate resources to type annotations.
Any opinions would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions