-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Added stubs for D3DShot #8652
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
Merged
Merged
Added stubs for D3DShot #8652
Changes from 36 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
31cc811
Added stubs for D3DShot
Avasam 6e08d8d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 04f783c
Added missing requires
Avasam 797bfc9
Merge branch 'D3DShot' of https://github.com/Avasam/typeshed into D3D…
Avasam f72704e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 85c4c95
Fixed missing Unknowns
Avasam ba31840
Merge branch 'D3DShot' of https://github.com/Avasam/typeshed into D3D…
Avasam 642d58b
Unused imports
Avasam b7793e8
Try fixing missing pillow types
Avasam 84fc12a
stubtest
Avasam 41cf5bc
Merge branch 'master' of https://github.com/python/typeshed into D3DShot
Avasam d346403
Filled in all ctypes
Avasam c197b15
Completed all _Pointer
Avasam 3ba9918
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c17309b
Unused _STDMETHOD
Avasam 84562f0
Merge branch 'D3DShot' of https://github.com/Avasam/typeshed into D3D…
Avasam 97934a4
os.name check
Avasam 73db85c
TypedDict from typing_extensions
Avasam cd79554
Update some types
Avasam e0b7e67
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 66ba404
skip instead of allowlist
Avasam a0fc98f
Merge branch 'D3DShot' of https://github.com/Avasam/typeshed into D3D…
Avasam c4d4439
Merge branch 'master' of https://github.com/python/typeshed into D3DShot
Avasam a166c59
PR review fixes
Avasam d03956d
Merge branch 'master' of https://github.com/python/typeshed into D3DShot
Avasam 1d7734c
Some PR comments, about comments
Avasam 041c2f3
Missed self arg
Avasam ba15101
_Pointer
Avasam df2ec92
Remove nt check comment
Avasam b16a70f
More PR comments and a few more completions
Avasam 628a00e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e444cc1
Liskov substitution principle
Avasam 24dea69
PR comments and __
Avasam dbd298b
Added comment for display init
Avasam 1488687
Comments and Iterable
Avasam 42b5119
`immediatley` -> `immediately`
AlexWaygood c99d4c8
oops typo
Avasam b842dff
Merge branch 'D3DShot' of https://github.com/Avasam/typeshed into D3D…
Avasam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: ... |
5 changes: 5 additions & 0 deletions
5
stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: ... |
3 changes: 3 additions & 0 deletions
3
stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): ... |
3 changes: 3 additions & 0 deletions
3
stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): ... |
3 changes: 3 additions & 0 deletions
3
stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: ... |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.