Skip to content

Commit

Permalink
Fix #114, try to load Start Image on browse & load settings, don't al…
Browse files Browse the repository at this point in the history
…low a start image to load if hotkeys are not set.
  • Loading branch information
Toufool committed Nov 28, 2021
1 parent 0d6ccf6 commit 3cb2aa6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/AutoSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,6 @@ def run(self):
self.hwnd_title = ''
self.rect = ctypes.wintypes.RECT()

# Last loaded settings and last successful loaded settings file path to None until we try to load them
self.last_loaded_settings = None
self.last_successfully_loaded_settings_file_path = None

if not self.is_auto_controlled:
self.loadSettings(load_settings_on_open=True)

# Automatic timer start
self.timerStartImage = QtCore.QTimer()
self.timerStartImage.timeout.connect(self.startImageFunction)
Expand All @@ -222,8 +215,12 @@ def run(self):
self.highest_similarity = 0.0
self.check_start_image_timestamp = 0.0

# Try to load start image
self.loadStartImage()
# Last loaded settings and last successful loaded settings file path to None until we try to load them
self.last_loaded_settings = None
self.last_successfully_loaded_settings_file_path = None

if not self.is_auto_controlled:
self.loadSettings(load_settings_on_open=True)

# FUNCTIONS

Expand All @@ -243,6 +240,7 @@ def browse(self):
# set the split image folder line to the directory text
self.split_image_directory = new_split_image_directory
self.splitimagefolderLineEdit.setText(f"{new_split_image_directory}/")
self.loadStartImage()

def checkLiveImage(self):
if self.liveimageCheckBox.isChecked():
Expand Down Expand Up @@ -302,6 +300,10 @@ def loadStartImage(self, started_by_button=False, wait_for_delay=True):
error_messages.noKeywordImageError('start_auto_splitter')
return

if self.start_image_name is not None and (not self.splitLineEdit.text() or not self.resetLineEdit.text() or not self.pausehotkeyLineEdit.text()) and not self.is_auto_controlled:
error_messages.loadStartImageError()
return

self.split_image_filenames = os.listdir(self.split_image_directory)
self.split_image_number = 0
self.start_image_mask = None
Expand Down Expand Up @@ -346,8 +348,7 @@ def loadStartImage(self, started_by_button=False, wait_for_delay=True):
QtWidgets.QApplication.processEvents()

def startImageFunction(self):
if time.time() < self.check_start_image_timestamp \
or (not self.splitLineEdit.text() and not self.is_auto_controlled):
if time.time() < self.check_start_image_timestamp:
pause_time_left = "{:.1f}".format(self.check_start_image_timestamp - time.time())
self.currentSplitImage.setText(f'None\n (Paused before loading Start Image).\n {pause_time_left} sec remaining')
return
Expand Down
2 changes: 2 additions & 0 deletions src/error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def tooManySettingsFilesOnOpenError():
def checkForUpdatesError():
setTextMessage("An error occurred while attempting to check for updates. Please check your connection.")

def loadStartImageError():
setTextMessage("Start Image found, but cannot be loaded unless Start, Reset, and Pause hotkeys are set. Please set these hotkeys, and then click the Reload Start Image button.")

def stdinLostError():
setTextMessage("stdin not supported or lost, external control like LiveSplit integration will not work.")
Expand Down
1 change: 1 addition & 0 deletions src/settings_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,4 @@ def loadSettings(self: AutoSplit, load_settings_on_open: bool = False, load_sett

self.last_successfully_loaded_settings_file_path = self.load_settings_file_path
self.checkLiveImage()
self.loadStartImage()

1 comment on commit 3cb2aa6

@Toufool
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also fixes #119

Please sign in to comment.