Skip to content
This repository was archived by the owner on Apr 26, 2023. It is now read-only.

Commit 2691574

Browse files
committed
D3DShot update from python/typeshed#8652
1 parent 77e3eb3 commit 2691574

20 files changed

+256
-368
lines changed

scripts/requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ bandit
1313
flake8>=5 # flake8-pyi deprecation warnings
1414
flake8-builtins
1515
flake8-bugbear
16+
flake8-class-attributes-order
1617
flake8-comprehensions>=3.8 # flake8 5 support
1718
flake8-datetimez
1819
flake8-isort>=4.2 # flake8 5 support

src/AutoSplit.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@
3535
# Needed when compiled, along with the custom hook-requests PyInstaller hook
3636
os.environ["REQUESTS_CA_BUNDLE"] = certifi.where()
3737
myappid = f"Toufool.AutoSplit.v{AUTOSPLIT_VERSION}"
38+
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
3839

3940

4041
class AutoSplit(QMainWindow, design.Ui_MainWindow): # pylint: disable=too-many-instance-attributes
41-
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
42-
4342
# Parse command line args
4443
is_auto_controlled = "--auto-controlled" in sys.argv
4544

src/capture_method/DesktopDuplicationCaptureMethod.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import ctypes
44
import ctypes.wintypes
5+
from typing import cast
56

67
import cv2
78
import d3dshot
@@ -34,5 +35,6 @@ def get_frame(self):
3435
top = selection["y"] + offset_y + top_bounds
3536
right = selection["width"] + left
3637
bottom = selection["height"] + top
37-
screenshot = desktop_duplication.screenshot((left, top, right, bottom))
38+
screenshot = cast(cv2.Mat, desktop_duplication.screenshot((left, top, right, bottom))) # with cast
39+
3840
return cv2.cvtColor(screenshot, cv2.COLOR_RGBA2BGRA), False

typings/d3dshot/__init__.pyi

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
""" # noqa: Y021
2-
This type stub file was generated by pyright.
3-
"""
1+
from d3dshot.capture_output import CaptureOutputs as CaptureOutputs
2+
from d3dshot.d3dshot import D3DShot as D3DShot
43

5-
from d3dshot.d3dshot import D3DShot
4+
pil_is_available: bool
5+
numpy_is_available: bool
6+
pytorch_is_available: bool
7+
pytorch_gpu_is_available: bool
8+
capture_output_mapping: dict[str, CaptureOutputs]
9+
capture_outputs: list[str]
610

7-
pil_is_available = ...
8-
numpy_is_available = ...
9-
pytorch_is_available = ...
10-
pytorch_gpu_is_available = ...
11-
capture_output_mapping = ...
12-
capture_outputs = ...
1311

14-
15-
def determine_available_capture_outputs() -> list:
16-
...
17-
18-
19-
def create(capture_output=..., frame_buffer_size=...) -> D3DShot:
20-
...
12+
def determine_available_capture_outputs() -> list[CaptureOutputs]: ...
13+
def create(capture_output: str = ..., frame_buffer_size: int = ...) -> D3DShot: ...

typings/d3dshot/capture_output.pyi

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,35 @@
1-
""" # noqa: Y021
2-
This type stub file was generated by pyright.
3-
"""
41
import enum
52
from typing import Any
63

7-
from numpy import uint8
8-
from numpy.typing import NDArray
9-
from PIL import Image
4+
from _typeshed import Incomplete
5+
from PIL.Image import Image
6+
from typing_extensions import TypeAlias
107

11-
#
8+
Frame: TypeAlias = Any
9+
# Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor
10+
Pointer: TypeAlias = Incomplete
1211

1312

1413
class CaptureOutputs(enum.Enum):
15-
PIL = ...
16-
NUMPY = ...
17-
NUMPY_FLOAT = ...
18-
PYTORCH = ...
19-
PYTORCH_FLOAT = ...
20-
PYTORCH_GPU = ...
21-
PYTORCH_FLOAT_GPU = ...
14+
PIL: int
15+
NUMPY: int
16+
NUMPY_FLOAT: int
17+
PYTORCH: int
18+
PYTORCH_FLOAT: int
19+
PYTORCH_GPU: int
20+
PYTORCH_FLOAT_GPU: int
2221

2322

2423
class CaptureOutputError(BaseException):
2524
...
2625

2726

2827
class CaptureOutput:
29-
def __init__(self, backend=...) -> None:
30-
...
31-
32-
def process(self, pointer, pitch, size, width, height, region,
33-
rotation) -> Image | NDArray | NDArray[uint8] | Any:
34-
...
35-
36-
def to_pil(self, frame) -> Image:
37-
...
38-
39-
def stack(self, frames, stack_dimension) -> NDArray:
40-
...
28+
backend: CaptureOutput
29+
def __init__(self, backend: CaptureOutputs = ...) -> None: ...
30+
31+
def process(
32+
self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int
33+
) -> Frame: ...
34+
def to_pil(self, frame: Frame) -> Image: ...
35+
def stack(self, frames: list[Frame], stack_dimension) -> Frame: ...

typings/d3dshot/capture_outputs/__init__.pyi

Whitespace-only changes.
Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
""" # noqa: Y021
2-
This type stub file was generated by pyright.
3-
"""
1+
import numpy as np
2+
import numpy.typing as npt
3+
from _typeshed import Incomplete
4+
from d3dshot.capture_output import CaptureOutput as CaptureOutput
5+
from PIL.Image import Image
6+
from typing_extensions import TypeAlias
47

5-
from d3dshot.capture_output import CaptureOutput
6-
from numpy import uint8
7-
from numpy.typing import NDArray
8-
from PIL import Image
9-
10-
#
8+
Pointer: TypeAlias = Incomplete
9+
NDArray: TypeAlias = npt.NDArray[np.int32]
1110

1211

1312
class NumpyCaptureOutput(CaptureOutput):
14-
def __init__(self) -> None:
15-
...
16-
17-
def process(self, pointer, pitch, size, width, height, region,
18-
rotation) -> NDArray | NDArray[uint8]:
19-
...
20-
21-
def to_pil(self, frame) -> Image:
22-
...
13+
def __init__(self) -> None: ...
2314

24-
def stack(self, frames, stack_dimension) -> NDArray:
25-
...
15+
def process(
16+
self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int
17+
) -> NDArray: ...
18+
def to_pil(self, frame: NDArray) -> Image: ...
19+
def stack(self, frames: list[NDArray] | NDArray, stack_dimension: int) -> NDArray: ...
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
""" # noqa: Y021
2-
This type stub file was generated by pyright.
3-
"""
1+
import numpy as np
2+
import numpy.typing as npt
3+
from _typeshed import Incomplete
4+
from d3dshot.capture_output import CaptureOutput as CaptureOutput
5+
from PIL.Image import Image
6+
from typing_extensions import TypeAlias
47

5-
from typing import Any
8+
Pointer: TypeAlias = Incomplete
9+
NDArray: TypeAlias = npt.NDArray[np.float32]
610

7-
from d3dshot.capture_outputs.numpy_capture_output import NumpyCaptureOutput
8-
from PIL import Image
911

10-
#
12+
class NumpyFloatCaptureOutput(CaptureOutput):
13+
def __init__(self) -> None: ...
1114

12-
13-
class NumpyFloatCaptureOutput(NumpyCaptureOutput):
14-
def process(self, pointer, pitch, size, width, height, region, rotation) -> Any:
15-
...
16-
17-
def to_pil(self, frame) -> Image:
18-
...
15+
def process(
16+
self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int
17+
) -> NDArray: ...
18+
def to_pil(self, frame: NDArray) -> Image: ...
19+
def stack(self, frames: list[NDArray] | NDArray, stack_dimension: int) -> NDArray: ...
Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
""" # noqa: Y021
2-
This type stub file was generated by pyright.
3-
"""
1+
from _typeshed import Incomplete
2+
from d3dshot.capture_output import CaptureOutput as CaptureOutput
3+
from PIL.Image import Image
4+
from typing_extensions import TypeAlias
45

5-
from d3dshot.capture_output import CaptureOutput
6-
from PIL import Image
7-
8-
#
6+
Pointer: TypeAlias = Incomplete
97

108

119
class PILCaptureOutput(CaptureOutput):
12-
def __init__(self) -> None:
13-
...
14-
15-
def process(self, pointer, pitch, size, width, height, region, rotation) -> Image:
16-
...
17-
18-
def to_pil(self, frame):
19-
...
10+
def __init__(self) -> None: ...
2011

21-
def stack(self, frames, stack_dimension):
22-
...
12+
def process(
13+
self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int
14+
) -> Image: ...
15+
def to_pil(self, frame: Image) -> Image: ...
16+
def stack(self, frames: list[Image], stack_dimension: int) -> list[Image]: ...
Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
""" # noqa: Y021
2-
This type stub file was generated by pyright.
3-
"""
1+
import torch
2+
from _typeshed import Incomplete
3+
from d3dshot.capture_output import CaptureOutput as CaptureOutput
4+
from PIL.Image import Image
5+
from typing_extensions import TypeAlias
46

5-
from d3dshot.capture_output import CaptureOutput
6-
from PIL import Image
7-
8-
#
7+
Pointer: TypeAlias = Incomplete
98

109

1110
class PytorchCaptureOutput(CaptureOutput):
12-
def __init__(self) -> None:
13-
...
14-
15-
def process(self, pointer, pitch, size, width, height, region, rotation):
16-
...
17-
18-
def to_pil(self, frame) -> Image:
19-
...
11+
def __init__(self) -> None: ...
2012

21-
def stack(self, frames, stack_dimension):
22-
...
13+
def process(
14+
self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int
15+
) -> torch.Tensor: ...
16+
def to_pil(self, frame: torch.Tensor) -> Image: ...
17+
def stack(self, frames: list[torch.Tensor], stack_dimension: int) -> torch.Tensor: ...
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
""" # noqa: Y021
2-
This type stub file was generated by pyright.
3-
"""
1+
import torch
2+
from _typeshed import Incomplete
3+
from d3dshot.capture_output import CaptureOutput as CaptureOutput
4+
from PIL.Image import Image
5+
from typing_extensions import TypeAlias
46

5-
from d3dshot.capture_outputs.pytorch_capture_output import PytorchCaptureOutput
6-
from PIL import Image
7+
Pointer: TypeAlias = Incomplete
78

8-
#
99

10+
class PytorchFloatCaptureOutput(CaptureOutput):
11+
def __init__(self) -> None: ...
1012

11-
class PytorchFloatCaptureOutput(PytorchCaptureOutput):
12-
def process(self, pointer, pitch, size, width, height, region, rotation):
13-
...
14-
15-
def to_pil(self, frame) -> Image:
16-
...
13+
def process(
14+
self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int
15+
) -> torch.Tensor: ...
16+
def to_pil(self, frame: torch.Tensor) -> Image: ...
17+
def stack(self, frames: list[torch.Tensor], stack_dimension: int) -> torch.Tensor: ...
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
""" # noqa: Y021
2-
This type stub file was generated by pyright.
3-
"""
1+
import torch
2+
from _typeshed import Incomplete
3+
from d3dshot.capture_output import CaptureOutput as CaptureOutput
4+
from PIL.Image import Image
5+
from typing_extensions import TypeAlias
46

5-
from d3dshot.capture_outputs.pytorch_gpu_capture_output import PytorchGPUCaptureOutput
6-
from PIL import Image
7+
Pointer: TypeAlias = Incomplete
78

8-
#
99

10+
class PytorchFloatGPUCaptureOutput(CaptureOutput):
11+
device: Incomplete
12+
def __init__(self) -> None: ...
1013

11-
class PytorchFloatGPUCaptureOutput(PytorchGPUCaptureOutput):
12-
def process(self, pointer, pitch, size, width, height, region, rotation):
13-
...
14-
15-
def to_pil(self, frame) -> Image:
16-
...
14+
def process(
15+
self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int
16+
) -> torch.Tensor: ...
17+
def to_pil(self, frame: torch.Tensor) -> Image: ...
18+
def stack(self, frames: list[torch.Tensor], stack_dimension: int) -> torch.Tensor: ...
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
""" # noqa: Y021
2-
This type stub file was generated by pyright.
3-
"""
1+
import torch
2+
from _typeshed import Incomplete
3+
from d3dshot.capture_output import CaptureOutput as CaptureOutput
4+
from PIL.Image import Image
5+
from typing_extensions import TypeAlias
46

5-
from d3dshot.capture_outputs.pytorch_capture_output import PytorchCaptureOutput
6-
from PIL import Image
7+
Pointer: TypeAlias = Incomplete
78

8-
#
99

10+
class PytorchGPUCaptureOutput(CaptureOutput):
11+
device: torch.device
12+
def __init__(self) -> None: ...
1013

11-
class PytorchGPUCaptureOutput(PytorchCaptureOutput):
12-
def __init__(self) -> None:
13-
...
14-
15-
def process(self, pointer, pitch, size, width, height, region, rotation):
16-
...
17-
18-
def to_pil(self, frame) -> Image:
19-
...
14+
def process(
15+
self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int
16+
) -> torch.Tensor: ...
17+
def to_pil(self, frame: torch.Tensor) -> Image: ...
18+
def stack(self, frames: list[torch.Tensor], stack_dimension: int): ...

0 commit comments

Comments
 (0)