From eb3cbd0e9c368dd7371b1595fe63274331cfb174 Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 2 Feb 2023 19:56:56 -0500 Subject: [PATCH] Disable Capture device: dropdown when Capture method: is not Video Capture Device Fix issue with programatically setting capture_device_combobox index --- src/menu_bar.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/menu_bar.py b/src/menu_bar.py index 27467e4c..df01fd40 100644 --- a/src/menu_bar.py +++ b/src/menu_bar.py @@ -144,8 +144,24 @@ def get_capture_device_index(self, capture_device_id: int): except ValueError: return 0 + def __enable_capture_device_if_its_selected_method( + self, selected_capture_method: str | CaptureMethodEnum | None = None, + ): + if selected_capture_method is None: + selected_capture_method = self.autosplit.settings_dict["capture_method"] + is_video_capture_device = selected_capture_method == CaptureMethodEnum.VIDEO_CAPTURE_DEVICE + self.capture_device_combobox.setEnabled(is_video_capture_device) + if is_video_capture_device: + self.capture_device_combobox.setCurrentIndex( + self.get_capture_device_index(self.autosplit.settings_dict["capture_device_id"]), + ) + else: + self.capture_device_combobox.setPlaceholderText('Select "Video Capture Device" above') + self.capture_device_combobox.setCurrentIndex(-1) + def __capture_method_changed(self): selected_capture_method = CAPTURE_METHODS.get_method_by_index(self.capture_method_combobox.currentIndex()) + self.__enable_capture_device_if_its_selected_method(selected_capture_method) change_capture_method(selected_capture_method, self.autosplit) return selected_capture_method @@ -157,6 +173,7 @@ def __capture_device_changed(self): self.autosplit.settings_dict["capture_device_name"] = capture_device.name self.autosplit.settings_dict["capture_device_id"] = capture_device.device_id if self.autosplit.settings_dict["capture_method"] == CaptureMethodEnum.VIDEO_CAPTURE_DEVICE: + # Re-initializes the VideoCaptureDeviceCaptureMethod change_capture_method(CaptureMethodEnum.VIDEO_CAPTURE_DEVICE, self.autosplit) @fire_and_forget @@ -171,10 +188,7 @@ def __set_all_capture_devices(self): + (" (occupied)" if device.occupied else "") for device in self.__video_capture_devices ]) - self.capture_device_combobox.setEnabled(True) - self.capture_device_combobox.setCurrentIndex( - self.get_capture_device_index(self.autosplit.settings_dict["capture_device_id"]), - ) + self.__enable_capture_device_if_its_selected_method() else: self.capture_device_combobox.setPlaceholderText("No device found.") @@ -263,9 +277,8 @@ def hotkey_connect(hotkey: Hotkey): self.capture_method_combobox.setCurrentIndex( CAPTURE_METHODS.get_index(autosplit.settings_dict["capture_method"]), ) - self.capture_device_combobox.currentIndexChanged.connect( - lambda: self.__set_value("capture_device_id", self.__capture_device_changed()), - ) + # No self.capture_device_combobox.setCurrentIndex + # It'll set itself asynchronously in self.__set_all_capture_devices() # Image Settings self.default_comparison_method.setCurrentIndex(autosplit.settings_dict["default_comparison_method"])