From 9132a5c6762a1b8948ab9fdb7db2f3de8c3eddae Mon Sep 17 00:00:00 2001 From: Moliman Date: Sat, 24 Aug 2019 03:17:02 -0400 Subject: [PATCH 1/7] Treeshold, pause and mask can be detected in file without app config --- res/design.ui | 62 +++++---------------------------------------- src/AutoSplit.py | 66 ++++++++++++++++-------------------------------- src/design.py | 26 +++---------------- 3 files changed, 32 insertions(+), 122 deletions(-) diff --git a/res/design.ui b/res/design.ui index 67327d01..a79e4610 100644 --- a/res/design.ui +++ b/res/design.ui @@ -141,11 +141,12 @@ 10 374 91 - 16 + 21 - Similarity threshold + Similarity threshold +Default value @@ -237,11 +238,12 @@ 10 420 111 - 16 + 21 - Pause time (seconds) + Pause time (seconds) +Default value @@ -1029,56 +1031,6 @@ 10.000000000000000 - - - true - - - - 10 - 435 - 121 - 17 - - - - - - - Custom pause times - - - false - - - false - - - - - true - - - - 10 - 390 - 111 - 17 - - - - - - - Custom thresholds - - - false - - - false - - @@ -1168,8 +1120,6 @@ yLabel comparisonmethodComboBox pauseDoubleSpinBox - custompausetimesCheckBox - customthresholdsCheckBox comparisonmethodLabel alignregionButton diff --git a/src/AutoSplit.py b/src/AutoSplit.py index ac0ec62b..e605a2a5 100644 --- a/src/AutoSplit.py +++ b/src/AutoSplit.py @@ -686,18 +686,6 @@ def autoSplitter(self): # file format that is supported self.imageTypeError() return - - if self.custompausetimesCheckBox.isChecked() and split_parser.pause_from_filename(image) is None: - # Error, this file doesn't have a pause, but the checkbox was - # selected for unique pause times - self.customPauseError() - return - - if self.customthresholdsCheckBox.isChecked() and split_parser.threshold_from_filename(image) is None: - # Error, this file doesn't have a threshold, but the checkbox - # was selected for unique thresholds - self.customThresholdError() - return if self.splitLineEdit.text() == '': self.splitHotkeyError() @@ -756,7 +744,7 @@ def autoSplitter(self): # if flagged as a mask, capture with nearest neighbor interpolation. else don't so that # threshold settings on versions below 1.2.0 aren't messed up - if (self.flags & 0x02 == 0x02): + if (self.imageHaveTransparency): capture = cv2.resize(capture, (self.RESIZE_WIDTH, self.RESIZE_HEIGHT), interpolation=cv2.INTER_NEAREST) else: capture = cv2.resize(capture, (self.RESIZE_WIDTH, self.RESIZE_HEIGHT)) @@ -766,17 +754,17 @@ def autoSplitter(self): # calculate similarity if self.comparisonmethodComboBox.currentIndex() == 0: - if (self.flags & 0x02 == 0x02): + if (self.imageHaveTransparency): self.similarity = compare.compare_l2_norm_masked(self.split_image, capture, self.mask) else: self.similarity = compare.compare_l2_norm(self.split_image, capture) elif self.comparisonmethodComboBox.currentIndex() == 1: - if (self.flags & 0x02 == 0x02): + if (self.imageHaveTransparency): self.similarity = compare.compare_histograms_masked(self.split_image, capture, self.mask) else: self.similarity = compare.compare_histograms(self.split_image, capture) elif self.comparisonmethodComboBox.currentIndex() == 2: - if (self.flags & 0x02 == 0x02): + if (self.imageHaveTransparency): self.similarity = compare.compare_phash_masked(self.split_image, capture, self.mask) else: self.similarity = compare.compare_phash(self.split_image, capture) @@ -907,10 +895,11 @@ def updateSplitImage(self): # get flags self.flags = split_parser.flags_from_filename(split_image_file) + self.imageHaveTransparency = self.checkIfImageHaveTransparency() or self.flags & 0x02 #set current split image in UI # if flagged as mask, transform transparency into UI's gray BG color - if (self.flags & 0x02 == 0x02): + if (self.imageHaveTransparency): self.split_image_display = cv2.imread(self.split_image_path, cv2.IMREAD_UNCHANGED) transparent_mask = self.split_image_display[:, :, 3] == 0 self.split_image_display[transparent_mask] = [240, 240, 240, 255] @@ -929,7 +918,7 @@ def updateSplitImage(self): self.currentsplitimagefileLabel.setText(split_image_file) # if theres a mask flag, create a mask - if (self.flags & 0x02 == 0x02): + if (self.imageHaveTransparency): # create mask based on resized, nearest neighbor interpolated split image self.split_image = cv2.imread(self.split_image_path, cv2.IMREAD_UNCHANGED) @@ -946,16 +935,26 @@ def updateSplitImage(self): split_image = cv2.imread(self.split_image_path, cv2.IMREAD_COLOR) self.split_image = cv2.resize(split_image, (self.RESIZE_WIDTH, self.RESIZE_HEIGHT)) - # If the unique parameters are selected, go ahead and set the spinboxes to those values - if self.custompausetimesCheckBox.isChecked(): - self.pauseDoubleSpinBox.setValue(split_parser.pause_from_filename(split_image_file)) + # Override default values if they have been specified on the file + pause = split_parser.pause_from_filename(split_image_file) + if pause != None: + self.pauseDoubleSpinBox.setValue(pause) + else: + self.pauseDoubleSpinBox.setValue(self.pause) - if self.customthresholdsCheckBox.isChecked(): - self.similaritythresholdDoubleSpinBox.setValue(split_parser.threshold_from_filename(split_image_file)) + threshold = split_parser.threshold_from_filename(split_image_file) + if threshold != None: + self.similaritythresholdDoubleSpinBox.setValue(threshold) + else: + self.similaritythresholdDoubleSpinBox.setValue(self.similarity_threshold) self.similarity = 0 self.highest_similarity = 0.001 + def checkIfImageHaveTransparency(self): + source = cv2.imread(self.split_image_path, cv2.IMREAD_UNCHANGED) + return source.shape[2] == 4 + # Error messages def splitImageDirectoryError(self): @@ -1035,16 +1034,6 @@ def saveSettings(self): self.undo_split_key = str(self.undosplitLineEdit.text()) self.hwnd_title = win32gui.GetWindowText(self.hwnd) - if self.custompausetimesCheckBox.isChecked(): - self.custom_pause_times_setting = 1 - else: - self.custom_pause_times_setting = 0 - - if self.customthresholdsCheckBox.isChecked(): - self.custom_thresholds_setting = 1 - else: - self.custom_thresholds_setting = 0 - #save settings to settings.pkl with open('settings.pkl', 'wb') as f: @@ -1071,17 +1060,6 @@ def loadSettings(self): self.comparisonmethodComboBox.setCurrentIndex(self.comparison_index) self.hwnd = win32gui.FindWindow(None, self.hwnd_title) - # set custom checkbox's accordingly - if self.custom_pause_times_setting == 1: - self.custompausetimesCheckBox.setChecked(True) - else: - self.custompausetimesCheckBox.setChecked(False) - - if self.custom_thresholds_setting == 1: - self.customthresholdsCheckBox.setChecked(True) - else: - self.customthresholdsCheckBox.setChecked(False) - # try to set hotkeys from when user last closed the window try: self.splitLineEdit.setText(str(self.split_key)) diff --git a/src/design.py b/src/design.py index d368f0da..9deba016 100644 --- a/src/design.py +++ b/src/design.py @@ -65,7 +65,7 @@ def setupUi(self, MainWindow): self.selectregionButton.setFocusPolicy(QtCore.Qt.NoFocus) self.selectregionButton.setObjectName(_fromUtf8("selectregionButton")) self.similaritythresholdLabel = QtGui.QLabel(self.centralwidget) - self.similaritythresholdLabel.setGeometry(QtCore.QRect(10, 374, 91, 16)) + self.similaritythresholdLabel.setGeometry(QtCore.QRect(10, 374, 91, 22)) self.similaritythresholdLabel.setObjectName(_fromUtf8("similaritythresholdLabel")) self.similaritythresholdDoubleSpinBox = QtGui.QDoubleSpinBox(self.centralwidget) self.similaritythresholdDoubleSpinBox.setGeometry(QtCore.QRect(160, 379, 64, 22)) @@ -90,7 +90,7 @@ def setupUi(self, MainWindow): self.skipsplitButton.setFocusPolicy(QtCore.Qt.NoFocus) self.skipsplitButton.setObjectName(_fromUtf8("skipsplitButton")) self.pauseLabel = QtGui.QLabel(self.centralwidget) - self.pauseLabel.setGeometry(QtCore.QRect(10, 420, 111, 16)) + self.pauseLabel.setGeometry(QtCore.QRect(10, 420, 111, 22)) self.pauseLabel.setObjectName(_fromUtf8("pauseLabel")) self.checkfpsButton = QtGui.QPushButton(self.centralwidget) self.checkfpsButton.setGeometry(QtCore.QRect(5, 201, 51, 21)) @@ -316,20 +316,6 @@ def setupUi(self, MainWindow): self.pauseDoubleSpinBox.setSingleStep(1.0) self.pauseDoubleSpinBox.setProperty("value", 10.0) self.pauseDoubleSpinBox.setObjectName(_fromUtf8("pauseDoubleSpinBox")) - self.custompausetimesCheckBox = QtGui.QCheckBox(self.centralwidget) - self.custompausetimesCheckBox.setEnabled(True) - self.custompausetimesCheckBox.setGeometry(QtCore.QRect(10, 435, 121, 17)) - self.custompausetimesCheckBox.setWhatsThis(_fromUtf8("")) - self.custompausetimesCheckBox.setChecked(False) - self.custompausetimesCheckBox.setTristate(False) - self.custompausetimesCheckBox.setObjectName(_fromUtf8("custompausetimesCheckBox")) - self.customthresholdsCheckBox = QtGui.QCheckBox(self.centralwidget) - self.customthresholdsCheckBox.setEnabled(True) - self.customthresholdsCheckBox.setGeometry(QtCore.QRect(10, 390, 111, 17)) - self.customthresholdsCheckBox.setWhatsThis(_fromUtf8("")) - self.customthresholdsCheckBox.setChecked(False) - self.customthresholdsCheckBox.setTristate(False) - self.customthresholdsCheckBox.setObjectName(_fromUtf8("customthresholdsCheckBox")) self.comparisonmethodLabel = QtGui.QLabel(self.centralwidget) self.comparisonmethodLabel.setGeometry(QtCore.QRect(10, 300, 101, 16)) self.comparisonmethodLabel.setObjectName(_fromUtf8("comparisonmethodLabel")) @@ -397,8 +383,6 @@ def setupUi(self, MainWindow): self.yLabel.raise_() self.comparisonmethodComboBox.raise_() self.pauseDoubleSpinBox.raise_() - self.custompausetimesCheckBox.raise_() - self.customthresholdsCheckBox.raise_() self.comparisonmethodLabel.raise_() self.alignregionButton.raise_() MainWindow.setCentralWidget(self.centralwidget) @@ -426,12 +410,12 @@ def retranslateUi(self, MainWindow): self.xLabel.setText(_translate("MainWindow", "X", None)) self.liveimageCheckBox.setText(_translate("MainWindow", "Live Capture Region", None)) self.selectregionButton.setText(_translate("MainWindow", "Select Region", None)) - self.similaritythresholdLabel.setText(_translate("MainWindow", "Similarity threshold", None)) + self.similaritythresholdLabel.setText(_translate("MainWindow", "Similarity threshold\nDefault value", None)) self.startautosplitterButton.setText(_translate("MainWindow", "Start Auto Splitter", None)) self.resetButton.setText(_translate("MainWindow", "Reset", None)) self.undosplitButton.setText(_translate("MainWindow", "Undo Split", None)) self.skipsplitButton.setText(_translate("MainWindow", "Skip Split", None)) - self.pauseLabel.setText(_translate("MainWindow", "Pause time (seconds)", None)) + self.pauseLabel.setText(_translate("MainWindow", "Pause time (seconds)\nDefault value", None)) self.checkfpsButton.setText(_translate("MainWindow", "Max FPS", None)) self.fpsLabel.setText(_translate("MainWindow", "FPS", None)) self.showlivesimilarityCheckBox.setText(_translate("MainWindow", "Show live similarity", None)) @@ -455,8 +439,6 @@ def retranslateUi(self, MainWindow): self.comparisonmethodComboBox.setItemText(0, _translate("MainWindow", "L2 Norm", None)) self.comparisonmethodComboBox.setItemText(1, _translate("MainWindow", "Histograms", None)) self.comparisonmethodComboBox.setItemText(2, _translate("MainWindow", "pHash", None)) - self.custompausetimesCheckBox.setText(_translate("MainWindow", "Custom pause times", None)) - self.customthresholdsCheckBox.setText(_translate("MainWindow", "Custom thresholds", None)) self.comparisonmethodLabel.setText(_translate("MainWindow", "Comparison Method", None)) self.alignregionButton.setText(_translate("MainWindow", "Align Region", None)) self.menuHelp.setTitle(_translate("MainWindow", "Help", None)) From e9ddf64c4aa5f50e3e5b99eaf060d2ca2fb47492 Mon Sep 17 00:00:00 2001 From: Moliman Date: Sat, 24 Aug 2019 03:22:31 -0400 Subject: [PATCH 2/7] Remove remaining of the check box --- src/AutoSplit.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/AutoSplit.py b/src/AutoSplit.py index e605a2a5..b7158934 100644 --- a/src/AutoSplit.py +++ b/src/AutoSplit.py @@ -702,8 +702,6 @@ def autoSplitter(self): self.setresethotkeyButton.setEnabled(False) self.setskipsplithotkeyButton.setEnabled(False) self.setundosplithotkeyButton.setEnabled(False) - self.custompausetimesCheckBox.setEnabled(False) - self.customthresholdsCheckBox.setEnabled(False) self.split_image_number = 0 @@ -735,8 +733,6 @@ def autoSplitter(self): self.setresethotkeyButton.setEnabled(True) self.setskipsplithotkeyButton.setEnabled(True) self.setundosplithotkeyButton.setEnabled(True) - self.custompausetimesCheckBox.setEnabled(True) - self.customthresholdsCheckBox.setEnabled(True) return # grab screenshot of capture region @@ -859,8 +855,6 @@ def autoSplitter(self): self.setresethotkeyButton.setEnabled(True) self.setskipsplithotkeyButton.setEnabled(True) self.setundosplithotkeyButton.setEnabled(True) - self.custompausetimesCheckBox.setEnabled(True) - self.customthresholdsCheckBox.setEnabled(True) return # check for skip/undo split: if self.split_image_number != pause_split_image_number: @@ -883,8 +877,6 @@ def autoSplitter(self): self.setresethotkeyButton.setEnabled(True) self.setskipsplithotkeyButton.setEnabled(True) self.setundosplithotkeyButton.setEnabled(True) - self.custompausetimesCheckBox.setEnabled(True) - self.customthresholdsCheckBox.setEnabled(True) QtGui.QApplication.processEvents() def updateSplitImage(self): From f2a332f86b96bb3a5314a728dee4b08ac88083b0 Mon Sep 17 00:00:00 2001 From: Moliman Date: Wed, 28 Aug 2019 14:39:58 -0400 Subject: [PATCH 3/7] Fix a bug that prevent reload a saved config --- src/AutoSplit.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/AutoSplit.py b/src/AutoSplit.py index b7158934..cd35822a 100644 --- a/src/AutoSplit.py +++ b/src/AutoSplit.py @@ -1025,6 +1025,8 @@ def saveSettings(self): self.skip_split_key = str(self.skipsplitLineEdit.text()) self.undo_split_key = str(self.undosplitLineEdit.text()) self.hwnd_title = win32gui.GetWindowText(self.hwnd) + self.custom_pause_times_setting = 0.90 + self.custom_thresholds_setting = 0.10 #save settings to settings.pkl From b64994f220e022a88c648d920c586703dc1a7a3a Mon Sep 17 00:00:00 2001 From: Moliman Date: Tue, 3 Sep 2019 14:32:17 -0400 Subject: [PATCH 4/7] Prevent default value to be override --- src/AutoSplit.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/AutoSplit.py b/src/AutoSplit.py index cd35822a..ee8c86b0 100644 --- a/src/AutoSplit.py +++ b/src/AutoSplit.py @@ -927,18 +927,14 @@ def updateSplitImage(self): split_image = cv2.imread(self.split_image_path, cv2.IMREAD_COLOR) self.split_image = cv2.resize(split_image, (self.RESIZE_WIDTH, self.RESIZE_HEIGHT)) - # Override default values if they have been specified on the file + # Override values if they have been specified on the file pause = split_parser.pause_from_filename(split_image_file) if pause != None: - self.pauseDoubleSpinBox.setValue(pause) - else: - self.pauseDoubleSpinBox.setValue(self.pause) + self.pause = pause threshold = split_parser.threshold_from_filename(split_image_file) if threshold != None: - self.similaritythresholdDoubleSpinBox.setValue(threshold) - else: - self.similaritythresholdDoubleSpinBox.setValue(self.similarity_threshold) + self.threshold = threshold self.similarity = 0 self.highest_similarity = 0.001 From 119efbe5b7b410c3ef9a0aa8b65d8ca5832d8973 Mon Sep 17 00:00:00 2001 From: Moliman Date: Thu, 5 Sep 2019 19:51:59 -0400 Subject: [PATCH 5/7] Hopping to make it work this time --- src/AutoSplit.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/AutoSplit.py b/src/AutoSplit.py index ee8c86b0..d55fff8b 100644 --- a/src/AutoSplit.py +++ b/src/AutoSplit.py @@ -714,7 +714,7 @@ def autoSplitter(self): # second while loop: stays in this loop until similarity threshold is met start = time.time() - while self.similarity < self.similaritythresholdDoubleSpinBox.value(): + while self.similarity < self.similarity_threshold: # reset if the set screen region window was closed if win32gui.GetWindowText(self.hwnd) == '': self.reset() @@ -837,7 +837,7 @@ def autoSplitter(self): # I have a pause loop here so that it can check if the user presses skip split, undo split, or reset here. # This should probably eventually be a signal... but it works pause_start_time = time.time() - while time.time() - pause_start_time < self.pauseDoubleSpinBox.value(): + while time.time() - pause_start_time < self.pause: # check for reset if win32gui.GetWindowText(self.hwnd) == '': self.reset() @@ -934,7 +934,7 @@ def updateSplitImage(self): threshold = split_parser.threshold_from_filename(split_image_file) if threshold != None: - self.threshold = threshold + self.similarity_threshold = threshold self.similarity = 0 self.highest_similarity = 0.001 @@ -1021,23 +1021,19 @@ def saveSettings(self): self.skip_split_key = str(self.skipsplitLineEdit.text()) self.undo_split_key = str(self.undosplitLineEdit.text()) self.hwnd_title = win32gui.GetWindowText(self.hwnd) - self.custom_pause_times_setting = 0.90 - self.custom_thresholds_setting = 0.10 #save settings to settings.pkl with open('settings.pkl', 'wb') as f: pickle.dump( [self.split_image_directory, self.similarity_threshold, self.comparison_index, self.pause, self.fps_limit, self.split_key, - self.reset_key, self.skip_split_key, self.undo_split_key, self.x, self.y, self.width, self.height, self.hwnd_title, - self.custom_pause_times_setting, self.custom_thresholds_setting], f) + self.reset_key, self.skip_split_key, self.undo_split_key, self.x, self.y, self.width, self.height, self.hwnd_title], f) def loadSettings(self): try: with open('settings.pkl', 'rb') as f: [self.split_image_directory, self.similarity_threshold, self.comparison_index, self.pause, self.fps_limit, self.split_key, - self.reset_key, self.skip_split_key, self.undo_split_key, self.x, self.y, self.width, self.height, self.hwnd_title, - self.custom_pause_times_setting, self.custom_thresholds_setting] = pickle.load(f) + self.reset_key, self.skip_split_key, self.undo_split_key, self.x, self.y, self.width, self.height, self.hwnd_title] = pickle.load(f) self.split_image_directory = str(self.split_image_directory) self.splitimagefolderLineEdit.setText(self.split_image_directory) self.similaritythresholdDoubleSpinBox.setValue(self.similarity_threshold) From ba8dbd93e01f073a0998eed4be37c47a998463ab Mon Sep 17 00:00:00 2001 From: Moliman Date: Thu, 5 Sep 2019 19:53:13 -0400 Subject: [PATCH 6/7] Revert some unintented change on this branch --- src/AutoSplit.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/AutoSplit.py b/src/AutoSplit.py index d55fff8b..b4919032 100644 --- a/src/AutoSplit.py +++ b/src/AutoSplit.py @@ -1021,19 +1021,23 @@ def saveSettings(self): self.skip_split_key = str(self.skipsplitLineEdit.text()) self.undo_split_key = str(self.undosplitLineEdit.text()) self.hwnd_title = win32gui.GetWindowText(self.hwnd) + self.custom_pause_times_setting = 0.90 + self.custom_thresholds_setting = 0.10 #save settings to settings.pkl with open('settings.pkl', 'wb') as f: pickle.dump( [self.split_image_directory, self.similarity_threshold, self.comparison_index, self.pause, self.fps_limit, self.split_key, - self.reset_key, self.skip_split_key, self.undo_split_key, self.x, self.y, self.width, self.height, self.hwnd_title], f) + self.reset_key, self.skip_split_key, self.undo_split_key, self.x, self.y, self.width, self.height, self.hwnd_title, + self.custom_pause_times_setting, self.custom_thresholds_setting], f) def loadSettings(self): try: with open('settings.pkl', 'rb') as f: [self.split_image_directory, self.similarity_threshold, self.comparison_index, self.pause, self.fps_limit, self.split_key, - self.reset_key, self.skip_split_key, self.undo_split_key, self.x, self.y, self.width, self.height, self.hwnd_title] = pickle.load(f) + self.reset_key, self.skip_split_key, self.undo_split_key, self.x, self.y, self.width, self.height, self.hwnd_title, + self.custom_pause_times_setting, self.custom_thresholds_setting] = pickle.load(f) self.split_image_directory = str(self.split_image_directory) self.splitimagefolderLineEdit.setText(self.split_image_directory) self.similaritythresholdDoubleSpinBox.setValue(self.similarity_threshold) From 4405d98dcd6b46390805d9917a50a1b5bde2b143 Mon Sep 17 00:00:00 2001 From: Moliman Date: Wed, 11 Sep 2019 20:52:30 -0400 Subject: [PATCH 7/7] Bug fix with default pause and threshold value Default value couldn't be used anymore once a file value was used --- src/AutoSplit.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/AutoSplit.py b/src/AutoSplit.py index b4919032..36370c56 100644 --- a/src/AutoSplit.py +++ b/src/AutoSplit.py @@ -931,10 +931,14 @@ def updateSplitImage(self): pause = split_parser.pause_from_filename(split_image_file) if pause != None: self.pause = pause + else: + self.pause = self.pauseDoubleSpinBox.value() threshold = split_parser.threshold_from_filename(split_image_file) if threshold != None: self.similarity_threshold = threshold + else: + self.similarity_threshold = self.similaritythresholdDoubleSpinBox.value() self.similarity = 0 self.highest_similarity = 0.001