Merge pull request #24061 from VadimLevin:dev/vlevin/python-typing-highgui-refinement

feat: add highgui functions to typing stubs
pull/24062/head
Alexander Smorkalov 2 years ago committed by GitHub
commit 91749a284b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 89
      modules/python/src2/typing_stubs_generation/api_refinement.py
  2. 3
      modules/python/src2/typing_stubs_generation/nodes/__init__.py

@ -6,12 +6,14 @@ from typing import cast, Sequence, Callable, Iterable
from .nodes import (NamespaceNode, FunctionNode, OptionalTypeNode, TypeNode,
ClassProperty, PrimitiveTypeNode, ASTNodeTypeNode,
AggregatedTypeNode)
AggregatedTypeNode, CallableTypeNode, AnyTypeNode,
TupleTypeNode, UnionTypeNode)
from .ast_utils import (find_function_node, SymbolName,
for_each_function_overload)
def apply_manual_api_refinement(root: NamespaceNode) -> None:
refine_highgui_module(root)
refine_cuda_module(root)
export_matrix_type_constants(root)
# Export OpenCV exception class
@ -105,6 +107,91 @@ def refine_cuda_module(root: NamespaceNode) -> None:
fix_namespace_usage_scope(ns)
def refine_highgui_module(root: NamespaceNode) -> None:
# Check if library is built with enabled highgui module
if "destroyAllWindows" not in root.functions:
return
"""
def createTrackbar(trackbarName: str,
windowName: str,
value: int,
count: int,
onChange: Callable[[int], None]) -> None: ...
"""
root.add_function(
"createTrackbar",
[
FunctionNode.Arg("trackbarName", PrimitiveTypeNode.str_()),
FunctionNode.Arg("windowName", PrimitiveTypeNode.str_()),
FunctionNode.Arg("value", PrimitiveTypeNode.int_()),
FunctionNode.Arg("count", PrimitiveTypeNode.int_()),
FunctionNode.Arg("onChange",
CallableTypeNode("TrackbarCallback",
PrimitiveTypeNode.int_("int"))),
]
)
"""
def createButton(buttonName: str,
onChange: Callable[[tuple[int] | tuple[int, Any]], None],
userData: Any | None = ...,
buttonType: int = ...,
initialButtonState: int = ...) -> None: ...
"""
root.add_function(
"createButton",
[
FunctionNode.Arg("buttonName", PrimitiveTypeNode.str_()),
FunctionNode.Arg(
"onChange",
CallableTypeNode(
"ButtonCallback",
UnionTypeNode(
"onButtonChangeCallbackData",
[
TupleTypeNode("onButtonChangeCallbackData",
[PrimitiveTypeNode.int_(), ]),
TupleTypeNode("onButtonChangeCallbackData",
[PrimitiveTypeNode.int_(),
AnyTypeNode("void*")])
]
)
)),
FunctionNode.Arg("userData",
OptionalTypeNode(AnyTypeNode("void*")),
default_value="None"),
FunctionNode.Arg("buttonType", PrimitiveTypeNode.int_(),
default_value="0"),
FunctionNode.Arg("initialButtonState", PrimitiveTypeNode.int_(),
default_value="0")
]
)
"""
def setMouseCallback(
windowName: str,
onMouse: Callback[[int, int, int, int, Any | None], None],
param: Any | None = ...
) -> None: ...
"""
root.add_function(
"setMouseCallback",
[
FunctionNode.Arg("windowName", PrimitiveTypeNode.str_()),
FunctionNode.Arg(
"onMouse",
CallableTypeNode("MouseCallback", [
PrimitiveTypeNode.int_(),
PrimitiveTypeNode.int_(),
PrimitiveTypeNode.int_(),
PrimitiveTypeNode.int_(),
OptionalTypeNode(AnyTypeNode("void*"))
])
),
FunctionNode.Arg("param", OptionalTypeNode(AnyTypeNode("void*")),
default_value="None")
]
)
def _trim_class_name_from_argument_types(
overloads: Iterable[FunctionNode.Overload],
class_name: str

@ -7,5 +7,6 @@ from .constant_node import ConstantNode
from .type_node import (
TypeNode, OptionalTypeNode, UnionTypeNode, NoneTypeNode, TupleTypeNode,
ASTNodeTypeNode, AliasTypeNode, SequenceTypeNode, AnyTypeNode,
AggregatedTypeNode, NDArrayTypeNode, AliasRefTypeNode, PrimitiveTypeNode
AggregatedTypeNode, NDArrayTypeNode, AliasRefTypeNode, PrimitiveTypeNode,
CallableTypeNode,
)

Loading…
Cancel
Save