@@ -98,6 +98,7 @@ class AutoSplit(QMainWindow, design.Ui_MainWindow):
98
98
split_image_directory = ""
99
99
hwnd = 0
100
100
"""Window Handle used for Capture Region"""
101
+ window_text = ""
101
102
selection = Rect ()
102
103
last_saved_settings : list [Union [str , float , int , bool ]] = []
103
104
save_settings_file_path = ""
@@ -116,13 +117,11 @@ class AutoSplit(QMainWindow, design.Ui_MainWindow):
116
117
check_start_image_timestamp = 0.0
117
118
118
119
# Define all other attributes
119
- setting_check_for_updates_on_open : QtCore .QSettings
120
120
start_image_split_below_threshold : bool
121
121
waiting_for_split_delay : bool
122
122
split_below_threshold : bool
123
123
run_start_time : float
124
124
similarity : float
125
- split_delay : float
126
125
start_image : Optional [AutoSplitImage ] = None
127
126
reset_image : Optional [AutoSplitImage ] = None
128
127
split_images : list [AutoSplitImage ] = []
@@ -138,7 +137,7 @@ def __init__(self, parent: Optional[QWidget] = None):
138
137
139
138
self .setupUi (self )
140
139
141
- settings .load_pyqt_settings (self )
140
+ settings .load_check_for_updates_on_open (self )
142
141
143
142
# close all processes when closing window
144
143
self .action_view_help .triggered .connect (view_help )
@@ -255,18 +254,17 @@ def check_live_image(self):
255
254
256
255
def __live_image_function (self ):
257
256
try :
258
- window_text = win32gui .GetWindowText (self .hwnd )
259
- self .capture_region_window_label .setText (window_text )
260
- if not window_text :
257
+ self .capture_region_window_label .setText (self .window_text )
258
+ if not self .window_text :
261
259
self .timer_live_image .stop ()
262
260
self .live_image .clear ()
263
261
if self .live_image_function_on_open :
264
262
self .live_image_function_on_open = False
265
263
return
266
-
267
264
# Set live image in UI
268
- capture = capture_region (self .hwnd , self .selection , self .force_print_window_checkbox .isChecked ())
269
- set_ui_image (self .live_image , capture , False )
265
+ if self .hwnd :
266
+ capture = capture_region (self .hwnd , self .selection , self .force_print_window_checkbox .isChecked ())
267
+ set_ui_image (self .live_image , capture , False )
270
268
271
269
except AttributeError :
272
270
pass
@@ -376,7 +374,7 @@ def __start_image_function(self):
376
374
self .start_image_label .setText (f"{ START_IMAGE_TEXT } : started" )
377
375
send_command (self , "start" )
378
376
379
- QtTest .QTest .qWait (1 / self .fps_limit_spinbox .value ()) # type: ignore
377
+ QtTest .QTest .qWait (int ( 1 / self .fps_limit_spinbox .value () )) # type: ignore
380
378
self .start_auto_splitter ()
381
379
382
380
# update x, y, width, height when spinbox values are changed
@@ -554,10 +552,10 @@ def __auto_splitter(self):
554
552
current_group : list [int ] = []
555
553
self .split_groups .append (current_group )
556
554
557
- for i , image in enumerate (self .split_images ):
555
+ for i , image in enumerate (self .split_images_and_loop_number ):
558
556
current_group .append (i )
559
557
560
- if not image .check_flag (DUMMY_FLAG ) and i < len (self .split_images ) - 1 :
558
+ if not image [ 0 ] .check_flag (DUMMY_FLAG ) and i < len (self .split_images_and_loop_number ) - 1 :
561
559
current_group = []
562
560
self .split_groups .append (current_group )
563
561
self .gui_changes_on_start ()
@@ -654,16 +652,16 @@ def __auto_splitter(self):
654
652
if not self .split_image .check_flag (DUMMY_FLAG ):
655
653
# If it's a delayed split, check if the delay has passed
656
654
# Otherwise calculate the split time for the key press
657
- if self .split_delay > 0 and not self .waiting_for_split_delay :
658
- split_time = int (round (time () * 1000 ) + self .split_delay )
655
+ split_delay = self .split_image .delay / 1000
656
+ if split_delay > 0 and not self .waiting_for_split_delay :
657
+ split_time = round (time () + split_delay * 1000 )
659
658
self .waiting_for_split_delay = True
660
659
self .undo_split_button .setEnabled (False )
661
660
self .skip_split_button .setEnabled (False )
662
661
self .current_split_image_file_label .setText (" " )
663
662
664
663
# check for reset while delayed and display a counter of the remaining split delay time
665
664
delay_start_time = time ()
666
- split_delay = self .split_delay / 1000
667
665
while time () - delay_start_time < split_delay :
668
666
delay_time_left = round (split_delay - (time () - delay_start_time ), 1 )
669
667
self .current_split_image .setText (f"Delayed Split: { delay_time_left } sec remaining" )
@@ -711,8 +709,6 @@ def __auto_splitter(self):
711
709
# Also updates the current split image text, counting down the time until the next split image
712
710
pause_time = self .split_image .get_pause_time (self )
713
711
if pause_time > 0 :
714
- self .current_split_image_file_label .setText (" " )
715
- self .image_loop_label .setText ("Image Loop: -" )
716
712
pause_start_time = time ()
717
713
while time () - pause_start_time < pause_time :
718
714
pause_time_left = round (pause_time - (time () - pause_start_time ), 1 )
@@ -788,6 +784,17 @@ def __get_capture_for_comparison(self):
788
784
Grab capture region and resize for comparison
789
785
"""
790
786
capture = capture_region (self .hwnd , self .selection , self .force_print_window_checkbox .isChecked ())
787
+
788
+ # This most likely means we lost capture (ie the captured window was closed, crashed, etc.)
789
+ if capture is None :
790
+ # Try to recover by using the window name
791
+ self .live_image .setText ("Trying to recover window..." )
792
+ # https://github.com/kaluluosi/pywin32-stubs/issues/7
793
+ hwnd = win32gui .FindWindow (None , self .window_text ) # type: ignore
794
+ # Don't fallback to desktop
795
+ if hwnd :
796
+ self .hwnd = hwnd
797
+ capture = capture_region (self .hwnd , self .selection , self .force_print_window_checkbox .isChecked ())
791
798
return None if capture is None else cv2 .resize (capture , COMPARISON_RESIZE , interpolation = cv2 .INTER_NEAREST )
792
799
793
800
def __reset_if_should (self , capture : Optional [cv2 .ndarray ]):
@@ -872,7 +879,7 @@ def exit_program():
872
879
873
880
if warning is QMessageBox .StandardButton .Yes :
874
881
# TODO: Don't close if user cancelled the save
875
- self .save_settings_as ()
882
+ settings .save_settings_as (self )
876
883
exit_program ()
877
884
if warning is QMessageBox .StandardButton .No :
878
885
exit_program ()
@@ -902,7 +909,6 @@ def main():
902
909
if FROZEN :
903
910
error_messages .exception_traceback (message , exception )
904
911
else :
905
- print (message )
906
912
traceback .print_exception (type (exception ), exception , exception .__traceback__ )
907
913
sys .exit (1 )
908
914
0 commit comments