Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added stubs for D3DShot #8652

Merged
merged 38 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
31cc811
Added stubs for D3DShot
Avasam Aug 30, 2022
6e08d8d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 30, 2022
04f783c
Added missing requires
Avasam Aug 30, 2022
797bfc9
Merge branch 'D3DShot' of https://github.com/Avasam/typeshed into D3D…
Avasam Aug 30, 2022
f72704e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 30, 2022
85c4c95
Fixed missing Unknowns
Avasam Aug 31, 2022
ba31840
Merge branch 'D3DShot' of https://github.com/Avasam/typeshed into D3D…
Avasam Aug 31, 2022
642d58b
Unused imports
Avasam Aug 31, 2022
b7793e8
Try fixing missing pillow types
Avasam Aug 31, 2022
84fc12a
stubtest
Avasam Aug 31, 2022
41cf5bc
Merge branch 'master' of https://github.com/python/typeshed into D3DShot
Avasam Sep 4, 2022
d346403
Filled in all ctypes
Avasam Sep 4, 2022
c197b15
Completed all _Pointer
Avasam Sep 4, 2022
3ba9918
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 4, 2022
c17309b
Unused _STDMETHOD
Avasam Sep 4, 2022
84562f0
Merge branch 'D3DShot' of https://github.com/Avasam/typeshed into D3D…
Avasam Sep 4, 2022
97934a4
os.name check
Avasam Sep 5, 2022
73db85c
TypedDict from typing_extensions
Avasam Sep 5, 2022
cd79554
Update some types
Avasam Sep 5, 2022
e0b7e67
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 5, 2022
66ba404
skip instead of allowlist
Avasam Sep 5, 2022
a0fc98f
Merge branch 'D3DShot' of https://github.com/Avasam/typeshed into D3D…
Avasam Sep 5, 2022
c4d4439
Merge branch 'master' of https://github.com/python/typeshed into D3DShot
Avasam Sep 5, 2022
a166c59
PR review fixes
Avasam Sep 6, 2022
d03956d
Merge branch 'master' of https://github.com/python/typeshed into D3DShot
Avasam Sep 11, 2022
1d7734c
Some PR comments, about comments
Avasam Sep 11, 2022
041c2f3
Missed self arg
Avasam Sep 11, 2022
ba15101
_Pointer
Avasam Sep 11, 2022
df2ec92
Remove nt check comment
Avasam Sep 11, 2022
b16a70f
More PR comments and a few more completions
Avasam Sep 12, 2022
628a00e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 12, 2022
e444cc1
Liskov substitution principle
Avasam Sep 12, 2022
24dea69
PR comments and __
Avasam Sep 12, 2022
dbd298b
Added comment for display init
Avasam Sep 12, 2022
1488687
Comments and Iterable
Avasam Sep 12, 2022
42b5119
`immediatley` -> `immediately`
AlexWaygood Sep 12, 2022
c99d4c8
oops typo
Avasam Sep 12, 2022
b842dff
Merge branch 'D3DShot' of https://github.com/Avasam/typeshed into D3D…
Avasam Sep 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions stubs/D3DShot/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version = "0.1.*"
requires = ["types-Pillow"]

[tool.stubtest]
# The library only works on Windows; we currently only run stubtest on Ubuntu for third-party stubs in CI.
# See #8660
skip = true
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 12 additions & 0 deletions stubs/D3DShot/d3dshot/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from d3dshot.capture_output import CaptureOutputs as CaptureOutputs
from d3dshot.d3dshot import D3DShot as D3DShot

pil_is_available: bool
numpy_is_available: bool
pytorch_is_available: bool
pytorch_gpu_is_available: bool
capture_output_mapping: dict[str, CaptureOutputs]
capture_outputs: list[str]

def determine_available_capture_outputs() -> list[CaptureOutputs]: ...
def create(capture_output: str = ..., frame_buffer_size: int = ...) -> D3DShot: ...
44 changes: 44 additions & 0 deletions stubs/D3DShot/d3dshot/capture_output.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import enum
from _typeshed import Incomplete
from collections.abc import Sequence
from ctypes import _CVoidConstPLike
from typing_extensions import Literal, TypeAlias

from PIL import Image

_Frame: TypeAlias = Image.Image | Incomplete
# TODO: Complete types once we can import non-types dependencies
# See: #5768
# from torch import Tensor
# from comtypes import IUnknown
# import numpy.typing as npt
# _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | Tensor

class CaptureOutputs(enum.Enum):
PIL: int
NUMPY: int
NUMPY_FLOAT: int
PYTORCH: int
PYTORCH_FLOAT: int
PYTORCH_GPU: int
PYTORCH_FLOAT_GPU: int

class CaptureOutputError(BaseException): ...

# All CaptureOutput methods just reference the backend. Making this both a base class and a wrapper.
class CaptureOutput:
# `backend` is a subclass of CaptureOutput based on the CaptureOutputs enum passed to __init__
backend: CaptureOutput
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self, backend: CaptureOutputs = ...) -> None: ...
def process(
self,
pointer: _CVoidConstPLike,
pitch: int,
size: int,
width: int,
height: int,
region: tuple[int, int, int, int],
rotation: int,
) -> _Frame: ...
def to_pil(self, frame: _Frame) -> Image.Image: ...
def stack(self, frames: Sequence[_Frame], stack_dimension: Literal["first", "last"]) -> _Frame: ...
Empty file.
29 changes: 29 additions & 0 deletions stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from _typeshed import Incomplete
from collections.abc import Sequence
from ctypes import _CVoidConstPLike
from typing_extensions import Literal, TypeAlias

from d3dshot.capture_output import CaptureOutput
from PIL import Image

# TODO: Complete types once we can import non-types dependencies
# See: #5768
# import numpy as np
# import numpy.typing as npt
# _NDArray: TypeAlias = npt.NDArray[np.int32]
_NDArray: TypeAlias = Incomplete

class NumpyCaptureOutput(CaptureOutput):
def __init__(self) -> None: ...
def process(
self,
pointer: _CVoidConstPLike,
pitch: int,
size: int,
width: int,
height: int,
region: tuple[int, int, int, int],
rotation: int,
) -> _NDArray: ...
def to_pil(self, frame: _NDArray) -> Image.Image: ...
def stack(self, frames: Sequence[_NDArray] | _NDArray, stack_dimension: Literal["first", "last"]) -> _NDArray: ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from d3dshot.capture_outputs.numpy_capture_output import NumpyCaptureOutput

# TODO: Once we can import non-types dependencies, this CaptureOutput should be float based
# See: #5768
class NumpyFloatCaptureOutput(NumpyCaptureOutput): ...
25 changes: 25 additions & 0 deletions stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from collections.abc import Sequence
from ctypes import _CVoidConstPLike
from typing import TypeVar
from typing_extensions import TypeAlias

from d3dshot.capture_output import CaptureOutput
from PIL import Image

_Unused: TypeAlias = object
_ImageT = TypeVar("_ImageT", bound=Image.Image)

class PILCaptureOutput(CaptureOutput):
def __init__(self) -> None: ...
def process(
self,
pointer: _CVoidConstPLike,
pitch: int,
size: int,
width: int,
height: int,
region: tuple[int, int, int, int],
rotation: int,
) -> Image.Image: ...
def to_pil(self, frame: _ImageT) -> _ImageT: ...
def stack(self, frames: Sequence[_ImageT], stack_dimension: _Unused) -> Sequence[_ImageT]: ...
27 changes: 27 additions & 0 deletions stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from _typeshed import Incomplete
from collections.abc import Sequence
from ctypes import _CVoidConstPLike
from typing_extensions import Literal, TypeAlias

from d3dshot.capture_output import CaptureOutput
from PIL import Image

# TODO: Complete types once we can import non-types dependencies
# See: https://github.com/python/typeshed/issues/5768
# from torch import Tensor
_Tensor: TypeAlias = Incomplete

class PytorchCaptureOutput(CaptureOutput):
def __init__(self) -> None: ...
def process(
self,
pointer: _CVoidConstPLike,
pitch: int,
size: int,
width: int,
height: int,
region: tuple[int, int, int, int],
rotation: int,
) -> _Tensor: ...
def to_pil(self, frame: _Tensor) -> Image.Image: ...
def stack(self, frames: Sequence[_Tensor], stack_dimension: Literal["first", "last"]) -> _Tensor: ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from d3dshot.capture_outputs.pytorch_capture_output import PytorchCaptureOutput

class PytorchFloatCaptureOutput(PytorchCaptureOutput): ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from d3dshot.capture_outputs.pytorch_gpu_capture_output import PytorchGPUCaptureOutput

class PytorchFloatGPUCaptureOutput(PytorchGPUCaptureOutput): ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from d3dshot.capture_outputs.pytorch_capture_output import PytorchCaptureOutput

class PytorchGPUCaptureOutput(PytorchCaptureOutput): ...
45 changes: 45 additions & 0 deletions stubs/D3DShot/d3dshot/d3dshot.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from collections import deque
from collections.abc import Iterable

from d3dshot.capture_output import CaptureOutput as CaptureOutput, CaptureOutputs as CaptureOutputs, _Frame
from d3dshot.display import Display as Display

class Singleton(type): ...

class D3DShot(metaclass=Singleton):
displays: list[Display]
display: Display
capture_output: CaptureOutput
frame_buffer_size: int
frame_buffer: deque[_Frame]
previous_screenshot: _Frame | None
region: tuple[int, int, int, int] | None

def __init__(
self,
capture_output: CaptureOutputs = ...,
frame_buffer_size: int = ...,
pil_is_available: bool = ...,
numpy_is_available: bool = ...,
pytorch_is_available: bool = ...,
pytorch_gpu_is_available: bool = ...,
) -> None: ...
@property
def is_capturing(self) -> bool: ...
def get_latest_frame(self) -> _Frame | None: ...
def get_frame(self, frame_index: int) -> _Frame | None: ...
def get_frames(self, frame_indices: Iterable[int]) -> list[_Frame]: ...
def get_frame_stack(self, frame_indices: Iterable[int], stack_dimension: str | None = ...) -> _Frame: ...
def screenshot(self, region: tuple[int, int, int, int] | None = ...) -> _Frame | None: ...
def screenshot_to_disk(
self, directory: str | None = ..., file_name: str | None = ..., region: tuple[int, int, int, int] | None = ...
) -> str: ...
def frame_buffer_to_disk(self, directory: str | None = ...) -> None: ...
def capture(self, target_fps: int = ..., region: tuple[int, int, int, int] | None = ...) -> bool: ...
def screenshot_every(self, interval: float, region: tuple[int, int, int, int] | None = ...) -> bool: ...
def screenshot_to_disk_every(
self, interval: float, directory: str | None = ..., region: tuple[int, int, int, int] | None = ...
) -> bool: ...
def stop(self) -> bool: ...
def benchmark(self) -> None: ...
def detect_displays(self) -> None: ...
49 changes: 49 additions & 0 deletions stubs/D3DShot/d3dshot/display.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from ctypes import _Pointer
from typing_extensions import TypedDict

from d3dshot.dll import _ProcessFunc, _ProcessFuncRegionArg, _ProcessFuncReturn
from d3dshot.dll.d3d import ID3D11Device, ID3D11DeviceContext
from d3dshot.dll.dxgi import IDXGIAdapter, IDXGIOutput1, IDXGIOutputDuplication

class _PositionDict(TypedDict):
left: int
top: int
right: int
bottom: int

class Display:
name: str
adapter_name: str
resolution: tuple[int, int]
position: _PositionDict
rotation: int
scale_factor: float
is_primary: bool
hmonitor: int
dxgi_output: IDXGIOutput1 | None
dxgi_adapter: _Pointer[IDXGIAdapter] | None
# Note that Display.d3d_device and Display.d3d_device_context can never be None.
# Despite initially being set to None in __init__,
# they're always immediately set in _initialize_dxgi_output_duplication()
d3d_device: ID3D11Device
d3d_device_context: ID3D11DeviceContext
dxgi_output_duplication: _Pointer[IDXGIOutputDuplication]

def __init__(
self,
name: str | None = ...,
adapter_name: str | None = ...,
resolution: tuple[int, int] | None = ...,
position: _PositionDict | None = ...,
rotation: int | None = ...,
scale_factor: float | None = ...,
is_primary: bool = ...,
hmonitor: int | None = ...,
dxgi_output: IDXGIOutput1 | None = ...,
dxgi_adapter: _Pointer[IDXGIAdapter] | None = ...,
) -> None: ...
def capture(
self, process_func: _ProcessFunc[_ProcessFuncRegionArg, _ProcessFuncReturn] | None, region: _ProcessFuncRegionArg = ...
) -> _ProcessFuncReturn: ...
@classmethod
def discover_displays(cls) -> list[Display]: ...
28 changes: 28 additions & 0 deletions stubs/D3DShot/d3dshot/dll/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys
from _typeshed import Incomplete
from collections.abc import Callable
from ctypes import _CData, c_ulong
from ctypes.wintypes import PFLOAT
from typing import TypeVar
from typing_extensions import TypeAlias

from d3dshot.capture_output import _Frame

_ProcessFuncRegionArg = TypeVar("_ProcessFuncRegionArg", tuple[int, int, int, int], None)
_ProcessFuncReturn = TypeVar("_ProcessFuncReturn", _Frame, None)
# The _ProcessFunc alias is used in multiple submodules
_ProcessFunc: TypeAlias = Callable[[PFLOAT, int, int, int, int, _ProcessFuncRegionArg, int], _ProcessFuncReturn] # noqa: Y047
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved

if sys.platform == "win32":
from ctypes import HRESULT

_HRESULT: TypeAlias = HRESULT
else:
_HRESULT: TypeAlias = Incomplete

# TODO: Use comtypes.IUnknown once we can import non-types dependencies
# See: #5768
class _IUnknown(_CData):
def QueryInterface(self, interface: type, iid: _CData | None = ...) -> _HRESULT: ...
def AddRef(self) -> c_ulong: ...
def Release(self) -> c_ulong: ...
Loading