Skip to content

Commit b759d1e

Browse files
author
arch
committed
remove exception at programm close
1 parent e75c9fd commit b759d1e

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

funscript_editor/algorithms/funscriptgenerator.py

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -958,39 +958,44 @@ def create_funscript(self, idx_dict: dict) -> None:
958958

959959
def run(self) -> None:
960960
""" The Funscript Generator Thread Function """
961-
if self.params.direction == 'd' and not self.params.track_men:
962-
self.finished("Tracking with 'd' and no men tracker is not implemented!", False)
963-
return
964-
965-
if self.video_info.fps < 31.0 and self.params.skip_frames > 0:
966-
self.logger.warning("The Video has less than 30 frames per seconds and you have set skip_frames to %d "\
967-
+ "this can lead to inaccuracies when predicting the changepoint positions! (consider to set skip_frames to 0)" \
968-
, self.params.skip_frames)
969-
970-
if self.params.raw_output:
971-
self.logger.warning("Raw output is enabled!")
972-
973-
# NOTE: score['y'] and score['x'] should have the same number size so it should be enouth to check one score length
974-
with Listener(on_press=self.on_key_press) as listener:
975-
status = self.tracking()
976-
977-
if self.params.use_kalman_filter:
978-
self.apply_kalman_filter()
979-
980-
if len(self.score['y']) >= HYPERPARAMETER['min_frames']:
981-
self.logger.info("Scale score")
982-
self.scale_score(status, direction=self.params.direction)
983-
984-
if len(self.score['y']) < HYPERPARAMETER['min_frames']:
985-
self.finished(status + ' -> Tracking time insufficient', False)
986-
return
987-
988-
idx_dict = self.determin_change_points()
989-
990-
if False:
991-
idx_list = [x for k in ['min', 'max'] for x in idx_dict[k]]
992-
idx_list.sort()
993-
self.plot_y_score('debug.png', idx_list)
994-
995-
self.create_funscript(idx_dict)
996-
self.finished(status, True)
961+
try:
962+
if self.params.direction == 'd' and not self.params.track_men:
963+
self.finished("Tracking with 'd' and no men tracker is not implemented!", False)
964+
return
965+
966+
if self.video_info.fps < 31.0 and self.params.skip_frames > 0:
967+
self.logger.warning("The Video has less than 30 frames per seconds and you have set skip_frames to %d "\
968+
+ "this can lead to inaccuracies when predicting the changepoint positions! (consider to set skip_frames to 0)" \
969+
, self.params.skip_frames)
970+
971+
if self.params.raw_output:
972+
self.logger.warning("Raw output is enabled!")
973+
974+
# NOTE: score['y'] and score['x'] should have the same number size so it should be enouth to check one score length
975+
with Listener(on_press=self.on_key_press) as listener:
976+
status = self.tracking()
977+
978+
if self.params.use_kalman_filter:
979+
self.apply_kalman_filter()
980+
981+
if len(self.score['y']) >= HYPERPARAMETER['min_frames']:
982+
self.logger.info("Scale score")
983+
self.scale_score(status, direction=self.params.direction)
984+
985+
if len(self.score['y']) < HYPERPARAMETER['min_frames']:
986+
self.finished(status + ' -> Tracking time insufficient', False)
987+
return
988+
989+
idx_dict = self.determin_change_points()
990+
991+
if False:
992+
idx_list = [x for k in ['min', 'max'] for x in idx_dict[k]]
993+
idx_list.sort()
994+
self.plot_y_score('debug.png', idx_list)
995+
996+
self.create_funscript(idx_dict)
997+
self.finished(status, True)
998+
except Exception as ex:
999+
self.logger.critical("The program crashed due to a fatal error. " \
1000+
+ "Please open an issue on github with the corresponding log file and application configuration", exc_info=ex)
1001+
self.finished("The program crashed due to a fatal error", False)

funscript_editor/ui/minimal.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def __init__(self,
3232
super(MinimalFunscriptGenerator, self).__init__()
3333

3434
if os.path.isdir(output_file):
35-
self.__logger.error("The output TempFile path must be a file not a folder")
36-
self.__show_message("The output TempFile path must be a file not a folder")
35+
self.__show_message("The output TempFile path must be a file not a folder", error=True)
3736
sys.exit()
3837

3938
if os.path.exists(output_file):
@@ -51,17 +50,15 @@ def __init__(self,
5150
'Do you want to generate the funscript actions by tracking features in the Video? ',
5251
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No)
5352
if reply != QtWidgets.QMessageBox.Yes:
54-
logging.info('abort')
53+
logging.info('Abort Funscript Generator')
5554
sys.exit()
5655

5756
if video_file is None or video_file == "":
58-
self.__logger.error("Video file was not specified!")
59-
self.__show_message("Video file was not specified!")
57+
self.__show_message("Video file was not specified!", error=True)
6058
sys.exit()
6159

6260
if not os.path.exists(video_file):
63-
self.__logger.error("Video file not found: %s", video_file)
64-
self.__show_message("Video file not found ({})".format(video_file))
61+
self.__show_message("Video file not found ({})".format(video_file), error=True)
6562
sys.exit()
6663

6764
reply = QtWidgets.QMessageBox.question(None, 'Track Men', 'Do you want to track the Men? ',
@@ -88,11 +85,13 @@ def __init__(self,
8885
__logger = logging.getLogger(__name__)
8986

9087

91-
def __show_message(self, message :str) -> None:
88+
def __show_message(self, message :str, error: bool = False) -> None:
89+
if error: self.__logger.error(message)
90+
else: self.__logger.info(message)
9291
msg = QtWidgets.QMessageBox()
9392
msg.setIcon(QtWidgets.QMessageBox.Information)
9493
msg.setText(message+' ')
95-
msg.setWindowTitle("Funscript Generator Info")
94+
msg.setWindowTitle("Funscript Generator " + str("Error" if error else "Info"))
9695
msg.exec_()
9796

9897

@@ -102,8 +101,7 @@ def __funscript_generated(self, funscript, msg, success) -> None:
102101
f.write('at;pos\n')
103102
for item in funscript.get_actions():
104103
f.write('{at};{pos}\n'.format(at=item['at'], pos=item['pos']))
105-
logging.info('Completed with status message: "%s"', msg)
106-
if not success: self.__show_message(msg)
104+
if not success: self.__show_message(msg, error=True)
107105
sys.exit()
108106

109107

funscript_editor/ui/video_player.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,6 @@ def send_mouse_pos(self, x :int, y :int) -> None:
551551

552552
def run(self) -> None:
553553
""" Video Player Thread Function """
554-
self.player.wait_until_playing()
555554
while not self.quit:
556555
try:
557556
time.sleep(0.01)
@@ -561,5 +560,3 @@ def run(self) -> None:
561560
self.__logger.info("quit video player")
562561
self.player.terminate()
563562

564-
565-

0 commit comments

Comments
 (0)