Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 6 additions & 56 deletions res/design.ui
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@
<x>10</x>
<y>374</y>
<width>91</width>
<height>16</height>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Similarity threshold</string>
<string>Similarity threshold
Default value</string>
</property>
</widget>
<widget class="QDoubleSpinBox" name="similaritythresholdDoubleSpinBox">
Expand Down Expand Up @@ -237,11 +238,12 @@
<x>10</x>
<y>420</y>
<width>111</width>
<height>16</height>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Pause time (seconds)</string>
<string>Pause time (seconds)
Default value</string>
</property>
</widget>
<widget class="QPushButton" name="checkfpsButton">
Expand Down Expand Up @@ -1029,56 +1031,6 @@
<double>10.000000000000000</double>
</property>
</widget>
<widget class="QCheckBox" name="custompausetimesCheckBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>10</x>
<y>435</y>
<width>121</width>
<height>17</height>
</rect>
</property>
<property name="whatsThis">
<string/>
</property>
<property name="text">
<string>Custom pause times</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="tristate">
<bool>false</bool>
</property>
</widget>
<widget class="QCheckBox" name="customthresholdsCheckBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>10</x>
<y>390</y>
<width>111</width>
<height>17</height>
</rect>
</property>
<property name="whatsThis">
<string/>
</property>
<property name="text">
<string>Custom thresholds</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="tristate">
<bool>false</bool>
</property>
</widget>
<widget class="QLabel" name="comparisonmethodLabel">
<property name="geometry">
<rect>
Expand Down Expand Up @@ -1168,8 +1120,6 @@
<zorder>yLabel</zorder>
<zorder>comparisonmethodComboBox</zorder>
<zorder>pauseDoubleSpinBox</zorder>
<zorder>custompausetimesCheckBox</zorder>
<zorder>customthresholdsCheckBox</zorder>
<zorder>comparisonmethodLabel</zorder>
<zorder>alignregionButton</zorder>
</widget>
Expand Down
80 changes: 26 additions & 54 deletions src/AutoSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -714,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
Expand All @@ -728,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()
Expand All @@ -747,16 +733,14 @@ 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
capture = capture_windows.capture_region(self.hwnd, self.rect)

# 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))
Expand All @@ -766,17 +750,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)
Expand Down Expand Up @@ -853,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()
Expand All @@ -871,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:
Expand All @@ -895,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):
Expand All @@ -907,10 +887,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]
Expand All @@ -929,7 +910,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)
Expand All @@ -946,16 +927,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 values if they have been specified on the file
pause = split_parser.pause_from_filename(split_image_file)
if pause != None:
self.pause = pause
else:
self.pause = self.pauseDoubleSpinBox.value()

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.similarity_threshold = threshold
else:
self.similarity_threshold = self.similaritythresholdDoubleSpinBox.value()

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):
Expand Down Expand Up @@ -1034,16 +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)

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
self.custom_pause_times_setting = 0.90
self.custom_thresholds_setting = 0.10


#save settings to settings.pkl
Expand Down Expand Up @@ -1071,17 +1054,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))
Expand Down
26 changes: 4 additions & 22 deletions src/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down