44import cv2
55
66from funscript_editor .utils .logging import setup_logging
7- from funscript_editor .ui .funscript_editor_window import FunscriptEditorWindow
8- from funscript_editor .algorithms .funscriptgenerator import FunscriptGenerator , FunscriptGeneratorParameter
7+ from funscript_editor .algorithms .funscriptgenerator import FunscriptGeneratorThread , FunscriptGeneratorParameter
98from funscript_editor .data .funscript import Funscript
109
1110from PyQt5 import QtCore , QtGui , QtWidgets
1211
1312
14- class MinimalFunscriptGenerator (QtWidgets .QMainWindow ):
13+ class FunscriptGeneratorWindow (QtWidgets .QMainWindow ):
1514 """ Class to Generate a funscript with minimal UI
1615
1716 Note:
@@ -21,22 +20,24 @@ class MinimalFunscriptGenerator(QtWidgets.QMainWindow):
2120 video_file (str): path to video file
2221 start_time (float): start position in video (timestamp in milliseconds)
2322 end_time (float): end position in video (timestamp in milliseconds) use -1.0 for video end.
24- output_file (str): csv output file path
23+ output_file (str, Funscript ): csv output file path (Optional you can pass a funscript object where to store the result)
2524 """
2625
2726 def __init__ (self ,
2827 video_file : str ,
2928 start_time : float ,
3029 end_time : float ,
3130 output_file : str ):
32- super (MinimalFunscriptGenerator , self ).__init__ ()
31+ super (FunscriptGeneratorWindow , self ).__init__ ()
3332
34- if os .path .isdir (output_file ):
35- self .__show_message ("The output TempFile path must be a file not a folder" , error = True )
36- sys .exit ()
33+ if not isinstance (output_file , Funscript ):
34+ output_file = os .path .abspath (output_file )
35+ if os .path .isdir (output_file ):
36+ self .__show_message ("The output TempFile path must be a file not a folder" , error = True )
37+ sys .exit ()
3738
38- if os .path .exists (output_file ):
39- os .remove (output_file )
39+ if os .path .exists (output_file ):
40+ os .remove (output_file )
4041
4142 if video_file is None or video_file == "" :
4243 self .__show_message ("Video file was not specified! " \
@@ -53,7 +54,7 @@ def __init__(self,
5354 cap .release ()
5455
5556 self .funscript = Funscript (fps )
56- self .output_file = os . path . abspath ( output_file )
57+ self .output_file = output_file
5758
5859 if False :
5960 reply = QtWidgets .QMessageBox .question (None , 'Generate Funscript ' , \
@@ -72,7 +73,7 @@ def __init__(self,
7273
7374 self .__logger .info ("Set End Time to Frame Number %d" , end_frame )
7475
75- self .funscript_generator = FunscriptGenerator (
76+ self .funscript_generator = FunscriptGeneratorThread (
7677 FunscriptGeneratorParameter (
7778 video_path = video_file ,
7879 start_frame = start_frame ,
@@ -81,11 +82,12 @@ def __init__(self,
8182 ),
8283 self .funscript )
8384 self .funscript_generator .funscriptCompleted .connect (self .__funscript_generated )
84- self .funscript_generator .processStatus .connect (self .__status_changed )
8585
8686
8787 __logger = logging .getLogger (__name__ )
8888
89+ funscriptCompleted = QtCore .pyqtSignal (object , str , bool )
90+
8991
9092 def __show_message (self , message :str , error : bool = False ) -> None :
9193 if error : self .__logger .error (message )
@@ -98,17 +100,18 @@ def __show_message(self, message :str, error: bool = False) -> None:
98100
99101
100102 def __funscript_generated (self , funscript , msg , success ) -> None :
101- os .makedirs (os .path .dirname (self .output_file ), exist_ok = True )
102- with open (self .output_file , 'w' ) as f :
103- f .write ('at;pos\n ' )
103+ if isinstance (self .output_file , Funscript ):
104104 for item in funscript .get_actions ():
105- f .write ('{at};{pos}\n ' .format (at = item ['at' ], pos = item ['pos' ]))
106- if not success : self .__show_message (msg , error = True )
107- sys .exit ()
108-
109-
110- def __status_changed (self , frame ) -> None :
111- pass
105+ self .output_file .add_action (item ['pos' ], item ['at' ])
106+ self .funscriptCompleted .emit (self .output_file , msg , success )
107+ else :
108+ os .makedirs (os .path .dirname (self .output_file ), exist_ok = True )
109+ with open (self .output_file , 'w' ) as f :
110+ f .write ('at;pos\n ' )
111+ for item in funscript .get_actions ():
112+ f .write ('{at};{pos}\n ' .format (at = item ['at' ], pos = item ['pos' ]))
113+ if not success : self .__show_message (msg , error = True )
114+ sys .exit ()
112115
113116
114117 def run (self ) -> None :
0 commit comments