From 97cc5f385f0d0995c8e06be3aad5a857075362af Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 9 Mar 2024 00:37:04 -0500 Subject: [PATCH 1/2] wip, create CaptureMethodSignal --- src/capture_method/__init__.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/capture_method/__init__.py b/src/capture_method/__init__.py index 0e26596e..cd96562b 100644 --- a/src/capture_method/__init__.py +++ b/src/capture_method/__init__.py @@ -4,11 +4,14 @@ import os import sys from collections import OrderedDict +from collections.abc import Callable from dataclasses import dataclass from enum import Enum, EnumMeta, auto, unique from itertools import starmap from typing import TYPE_CHECKING, TypedDict, cast +from cv2.typing import MatLike +from PySide6 import QtCore from typing_extensions import Never, override from capture_method.CaptureMethodBase import CaptureMethodBase @@ -253,3 +256,27 @@ async def get_camera_info(index: int, device_name: str): in await asyncio.gather(*starmap(get_camera_info, enumerate(named_video_inputs))) if camera_info is not None ] + + +class CaptureMethodSignal(QtCore.QObject): + """Made to look like a `QtCore.SignalInstance`, but with safe `connect`/`disconnect` methods.""" + + __frame_signal = QtCore.Signal(object) + + def subscribe_to_new_frame(self, slot: Callable[[MatLike | None], object]): + try: + return self.__frame_signal.connect(slot, QtCore.Qt.ConnectionType.UniqueConnection) + except RuntimeError: + pass + + def unsubscribe_from_new_frame(self, slot: Callable[[MatLike | None], object]): + try: + self.__frame_signal.disconnect(slot) + except RuntimeError: + pass + + def _push_new_frame_to_subscribers(self, __frame: MatLike | None): + return self.__frame_signal.emit(__frame) + + def __init__(self): + super().__init__() From f16b2250814755f26ccdc913a8403821a947df49 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 20 Oct 2024 19:54:44 -0400 Subject: [PATCH 2/2] Use PEP 570 syntax for positional-only arguments --- src/capture_method/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/capture_method/__init__.py b/src/capture_method/__init__.py index c9679a62..110d2a9b 100644 --- a/src/capture_method/__init__.py +++ b/src/capture_method/__init__.py @@ -243,8 +243,8 @@ def unsubscribe_from_new_frame(self, slot: Callable[[MatLike | None], object]): except RuntimeError: pass - def _push_new_frame_to_subscribers(self, __frame: MatLike | None): - return self.__frame_signal.emit(__frame) + def _push_new_frame_to_subscribers(self, frame: MatLike | None, /): + return self.__frame_signal.emit(frame) def __init__(self): super().__init__()