From fc12c49a345d5bea1a766f8b09c2630e4ee22a2c Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 27 Nov 2021 23:54:19 -0500 Subject: [PATCH] Fix #110 offer manual override for PrintWindow Also fixed the capture region not getting cleared visually on settigns load Added captured window title --- res/design.ui | 46 ++++++++++++++++++++++++++++++++++++------ src/AutoSplit.py | 14 +++++++------ src/capture_windows.py | 4 ++-- src/design.py | 20 ++++++++++++++---- src/resources_rc.py | 4 ++-- src/screen_region.py | 2 +- src/settings_file.py | 18 ++++++++++++----- 7 files changed, 82 insertions(+), 26 deletions(-) diff --git a/res/design.ui b/res/design.ui index 1e74b9d8..af4e7559 100644 --- a/res/design.ui +++ b/res/design.ui @@ -615,7 +615,7 @@ 450 - 50 + 38 102 16 @@ -705,7 +705,7 @@ 200 - 50 + 38 82 16 @@ -759,7 +759,7 @@ 380 - 270 + 50 241 20 @@ -1076,10 +1076,10 @@ - 120 + 440 270 - 241 - 16 + 181 + 20 @@ -1112,6 +1112,38 @@ + + + + 120 + 50 + 241 + 20 + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + true + + + + 120 + 270 + 221 + 20 + + + + Force Full Content Rendering (slower) + + splitimagefolderLabel splitimagefolderLineEdit browseButton @@ -1178,6 +1210,8 @@ startImageLabel currentsimilaritythresholdLabel currentsimilaritythresholdnumberLabel + captureregionwindowLabel + forcePrintWindowCheckBox diff --git a/src/AutoSplit.py b/src/AutoSplit.py index c39b101e..092b4662 100644 --- a/src/AutoSplit.py +++ b/src/AutoSplit.py @@ -246,16 +246,18 @@ def checkLiveImage(self): def liveImageFunction(self): try: - if win32gui.GetWindowText(self.hwnd) == '': + windowText = win32gui.GetWindowText(self.hwnd) + self.captureregionwindowLabel.setText(windowText) + if not windowText: self.timerLiveImage.stop() + self.liveImage.clear() if self.live_image_function_on_open: self.live_image_function_on_open = False else: - self.liveImage.clear() error_messages.regionError() return - capture = capture_windows.capture_region(self.hwnd, self.rect) + capture = capture_windows.capture_region(self.hwnd, self.rect, self.forcePrintWindowCheckBox.isChecked()) capture = cv2.resize(capture, DISPLAY_RESIZE) capture = cv2.cvtColor(capture, cv2.COLOR_BGRA2RGB) @@ -449,7 +451,7 @@ def takeScreenshot(self): i = i + 1 # grab screenshot of capture region - capture = capture_windows.capture_region(self.hwnd, self.rect) + capture = capture_windows.capture_region(self.hwnd, self.rect, self.forcePrintWindowCheckBox.isChecked()) capture = cv2.cvtColor(capture, cv2.COLOR_BGRA2BGR) # save and open image @@ -482,7 +484,7 @@ def checkFPS(self): t0 = time.time() while count < 10: - capture = capture_windows.capture_region(self.hwnd, self.rect) + capture = capture_windows.capture_region(self.hwnd, self.rect, self.forcePrintWindowCheckBox.isChecked()) capture = cv2.resize(capture, COMPARISON_RESIZE) capture = cv2.cvtColor(capture, cv2.COLOR_BGRA2RGB) @@ -990,7 +992,7 @@ def compareImage(self, image, mask, capture): def getCaptureForComparison(self): # grab screenshot of capture region - capture = capture_windows.capture_region(self.hwnd, self.rect) + capture = capture_windows.capture_region(self.hwnd, self.rect, self.forcePrintWindowCheckBox.isChecked()) # Capture with nearest neighbor interpolation only if the split image has transparency to support older setups if self.imageHasTransparency: capture = cv2.resize(capture, COMPARISON_RESIZE, interpolation=cv2.INTER_NEAREST) diff --git a/src/capture_windows.py b/src/capture_windows.py index 15a7dfee..1046a11c 100644 --- a/src/capture_windows.py +++ b/src/capture_windows.py @@ -18,7 +18,7 @@ is_windows_11 = version.parse(platform.version()) >= version.parse("10.0.22000") -def capture_region(hwnd: int, rect: RECT): +def capture_region(hwnd: int, rect: RECT, forcePrintWindow: bool): """ Captures an image of the region for a window matching the given parameters of the bounding box @@ -30,7 +30,7 @@ def capture_region(hwnd: int, rect: RECT): # Windows 11 has some jank, and we're not ready to fully investigate it # for now let's ensure it works at the cost of performance - is_accelerated_window = is_windows_11 or accelerated_windows.get(hwnd) + is_accelerated_window = forcePrintWindow or is_windows_11 or accelerated_windows.get(hwnd) # The window type is not yet known, let's find out! if is_accelerated_window is None: diff --git a/src/design.py b/src/design.py index 28f0990c..a05a79c3 100644 --- a/src/design.py +++ b/src/design.py @@ -183,7 +183,7 @@ def setupUi(self, MainWindow): self.currentSplitImage.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter) self.currentSplitImage.setObjectName("currentSplitImage") self.currentsplitimageLabel = QtWidgets.QLabel(self.centralwidget) - self.currentsplitimageLabel.setGeometry(QtCore.QRect(450, 50, 102, 16)) + self.currentsplitimageLabel.setGeometry(QtCore.QRect(450, 38, 102, 16)) self.currentsplitimageLabel.setObjectName("currentsplitimageLabel") self.widthLabel = QtWidgets.QLabel(self.centralwidget) self.widthLabel.setGeometry(QtCore.QRect(12, 185, 33, 16)) @@ -208,7 +208,7 @@ def setupUi(self, MainWindow): self.heightSpinBox.setProperty("value", 480) self.heightSpinBox.setObjectName("heightSpinBox") self.captureregionLabel = QtWidgets.QLabel(self.centralwidget) - self.captureregionLabel.setGeometry(QtCore.QRect(200, 50, 82, 16)) + self.captureregionLabel.setGeometry(QtCore.QRect(200, 38, 82, 16)) self.captureregionLabel.setObjectName("captureregionLabel") self.fpslimitLabel = QtWidgets.QLabel(self.centralwidget) self.fpslimitLabel.setGeometry(QtCore.QRect(8, 252, 51, 16)) @@ -223,7 +223,7 @@ def setupUi(self, MainWindow): self.fpslimitSpinBox.setProperty("value", 60.0) self.fpslimitSpinBox.setObjectName("fpslimitSpinBox") self.currentsplitimagefileLabel = QtWidgets.QLabel(self.centralwidget) - self.currentsplitimagefileLabel.setGeometry(QtCore.QRect(380, 270, 241, 20)) + self.currentsplitimagefileLabel.setGeometry(QtCore.QRect(380, 50, 241, 20)) self.currentsplitimagefileLabel.setText("") self.currentsplitimagefileLabel.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter) self.currentsplitimagefileLabel.setObjectName("currentsplitimagefileLabel") @@ -309,7 +309,7 @@ def setupUi(self, MainWindow): self.startImageReloadButton.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus) self.startImageReloadButton.setObjectName("startImageReloadButton") self.startImageLabel = QtWidgets.QLabel(self.centralwidget) - self.startImageLabel.setGeometry(QtCore.QRect(120, 270, 241, 16)) + self.startImageLabel.setGeometry(QtCore.QRect(440, 270, 181, 20)) self.startImageLabel.setObjectName("startImageLabel") self.currentsimilaritythresholdLabel = QtWidgets.QLabel(self.centralwidget) self.currentsimilaritythresholdLabel.setGeometry(QtCore.QRect(7, 380, 151, 16)) @@ -318,6 +318,15 @@ def setupUi(self, MainWindow): self.currentsimilaritythresholdnumberLabel.setGeometry(QtCore.QRect(171, 380, 46, 16)) self.currentsimilaritythresholdnumberLabel.setText("") self.currentsimilaritythresholdnumberLabel.setObjectName("currentsimilaritythresholdnumberLabel") + self.captureregionwindowLabel = QtWidgets.QLabel(self.centralwidget) + self.captureregionwindowLabel.setGeometry(QtCore.QRect(120, 50, 241, 20)) + self.captureregionwindowLabel.setText("") + self.captureregionwindowLabel.setAlignment(QtCore.Qt.AlignmentFlag.AlignLeading|QtCore.Qt.AlignmentFlag.AlignLeft|QtCore.Qt.AlignmentFlag.AlignVCenter) + self.captureregionwindowLabel.setObjectName("captureregionwindowLabel") + self.forcePrintWindowCheckBox = QtWidgets.QCheckBox(self.centralwidget) + self.forcePrintWindowCheckBox.setEnabled(True) + self.forcePrintWindowCheckBox.setGeometry(QtCore.QRect(120, 270, 221, 20)) + self.forcePrintWindowCheckBox.setObjectName("forcePrintWindowCheckBox") self.splitimagefolderLabel.raise_() self.splitimagefolderLineEdit.raise_() self.browseButton.raise_() @@ -384,6 +393,8 @@ def setupUi(self, MainWindow): self.startImageLabel.raise_() self.currentsimilaritythresholdLabel.raise_() self.currentsimilaritythresholdnumberLabel.raise_() + self.captureregionwindowLabel.raise_() + self.forcePrintWindowCheckBox.raise_() MainWindow.setCentralWidget(self.centralwidget) self.menuBar = QtWidgets.QMenuBar(MainWindow) self.menuBar.setGeometry(QtCore.QRect(0, 0, 632, 22)) @@ -490,6 +501,7 @@ def retranslateUi(self, MainWindow): self.startImageReloadButton.setText(_translate("MainWindow", "Reload Start Image")) self.startImageLabel.setText(_translate("MainWindow", "Start image:")) self.currentsimilaritythresholdLabel.setText(_translate("MainWindow", "Current similarity threshold:")) + self.forcePrintWindowCheckBox.setText(_translate("MainWindow", "Force Full Content Rendering (slower)")) self.menuHelp.setTitle(_translate("MainWindow", "Help")) self.menuFile.setTitle(_translate("MainWindow", "File")) self.actionView_Help.setText(_translate("MainWindow", "View Help")) diff --git a/src/resources_rc.py b/src/resources_rc.py index 4f7f7b54..b216c056 100644 --- a/src/resources_rc.py +++ b/src/resources_rc.py @@ -2297,9 +2297,9 @@ \x00\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x02\ \x00\x00\x00\x00\x00\x00\x00\x00\ \x00\x00\x00D\x00\x00\x00\x00\x00\x01\x00\x00\x0a\x91\ -\x00\x00\x01}N\xa9\xa5H\ +\x00\x00\x01}d\x84\xa44\ \x00\x00\x00\x18\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\ -\x00\x00\x01}N\xa9\xa5\x04\ +\x00\x00\x01}d\x84\xa4\x0b\ " def qInitResources(): diff --git a/src/screen_region.py b/src/screen_region.py index a43178d0..95ac988e 100644 --- a/src/screen_region.py +++ b/src/screen_region.py @@ -150,7 +150,7 @@ def alignRegion(self: AutoSplit): # Obtaining the capture of a region which contains the # subregion being searched for to align the image. - capture = capture_windows.capture_region(self.hwnd, self.rect) + capture = capture_windows.capture_region(self.hwnd, self.rect, self.forcePrintWindowCheckBox.isChecked()) capture = cv2.cvtColor(capture, cv2.COLOR_BGRA2BGR) # Obtain the best matching point for the template within the diff --git a/src/settings_file.py b/src/settings_file.py index 26f15b2d..ee8830eb 100644 --- a/src/settings_file.py +++ b/src/settings_file.py @@ -71,7 +71,8 @@ def haveSettingsChanged(self: AutoSplit): 0, self.group_dummy_splits_undo_skip_setting, self.loop_setting, - self.auto_start_on_reset_setting] + self.auto_start_on_reset_setting, + self.forcePrintWindowCheckBox.isChecked()] # One small caveat in this: if you load a settings file from an old version, but dont change settings, # the current save settings and last load settings will have different # of elements and it will ask @@ -104,7 +105,8 @@ def saveSettings(self: AutoSplit): 0, self.group_dummy_splits_undo_skip_setting, self.loop_setting, - self.auto_start_on_reset_setting] + self.auto_start_on_reset_setting, + self.forcePrintWindowCheckBox.isChecked()] # save settings to a .pkl file with open(self.last_successfully_loaded_settings_file_path, 'wb') as f: pickle.dump(self.last_saved_settings, f) @@ -143,7 +145,8 @@ def saveSettingsAs(self: AutoSplit): 0, self.group_dummy_splits_undo_skip_setting, self.loop_setting, - self.auto_start_on_reset_setting] + self.auto_start_on_reset_setting, + self.forcePrintWindowCheckBox.isChecked()] # save settings to a .pkl file with open(self.save_settings_file_path, 'wb') as f: @@ -198,7 +201,10 @@ def loadSettings(self: AutoSplit, load_settings_on_open: bool = False, load_sett settings.insert(9, '') settings.insert(20, 0) # v1.5 settings - elif settings_count != 20: + if settings_count == 20: + settings.insert(21, False) + # v1.6.X settings + elif settings_count != 21: if not load_settings_from_livesplit: error_messages.invalidSettingsError() return @@ -222,7 +228,9 @@ def loadSettings(self: AutoSplit, load_settings_on_open: bool = False, load_sett _, self.group_dummy_splits_undo_skip_setting, self.loop_setting, - self.auto_start_on_reset_setting] = settings + self.auto_start_on_reset_setting, + forcePrintWindowCheckBox] = settings + self.forcePrintWindowCheckBox.setChecked(forcePrintWindowCheckBox) except (FileNotFoundError, MemoryError, pickle.UnpicklingError): # HACK / Workaround: Executing the error QMessageBox from the auto-controlled Worker Thread makes it hangs. # I don't like this solution as we should probably ensure the Worker works nicely with PyQt instead,