@@ -21,18 +21,25 @@ class State(Enum):
2121 END = 3
2222
2323 def __str__ (self ):
24- if self .value == 0 : return "Playing"
25- if self .value == 1 : return "Paused"
26- if self .value == 2 : return "Wait"
27- if self .value == 3 : return "End"
24+ if self .value == 0 :
25+ return "Playing"
26+ if self .value == 1 :
27+ return "Paused"
28+ if self .value == 2 :
29+ return "Wait"
30+ if self .value == 3 :
31+ return "End"
2832 return "..."
2933
34+
3035def now ():
3136 return round (time .time () * 1000 )
3237
38+
3339def fix_time (x ):
3440 return x if x > 0 else 1
3541
42+
3643class Presentation :
3744 def __init__ (self , config , last_frame_next : bool = False ):
3845 self .last_frame_next = last_frame_next
@@ -48,14 +55,15 @@ def __init__(self, config, last_frame_next: bool = False):
4855 def add_last_slide (self ):
4956 last_slide_end = self .slides [- 1 ]["end_animation" ]
5057 last_animation = len (self .files )
51- self .slides .append (dict (
52- start_animation = last_slide_end ,
53- end_animation = last_animation ,
54- type = "last" ,
55- number = len (self .slides ) + 1 ,
56- terminated = False
57- ))
58-
58+ self .slides .append (
59+ dict (
60+ start_animation = last_slide_end ,
61+ end_animation = last_animation ,
62+ type = "last" ,
63+ number = len (self .slides ) + 1 ,
64+ terminated = False ,
65+ )
66+ )
5967
6068 def reset (self ):
6169 self .current_animation = 0
@@ -78,7 +86,7 @@ def rewind_slide(self):
7886 self .current_animation = self .current_slide ["start_animation" ]
7987 self .current_cap .set (cv2 .CAP_PROP_POS_FRAMES , 0 )
8088
81- def load_this_cap (self ,cap_number ):
89+ def load_this_cap (self , cap_number ):
8290 if self .caps [cap_number ] == None :
8391 # unload other caps
8492 for i in range (len (self .caps )):
@@ -135,7 +143,10 @@ def update_state(self, state):
135143 self .rewind_slide ()
136144 elif self .current_slide ["type" ] == "last" :
137145 self .current_slide ["terminated" ] = True
138- elif self .current_slide ["type" ] == "last" and self .current_slide ["end_animation" ] == self .current_animation :
146+ elif (
147+ self .current_slide ["type" ] == "last"
148+ and self .current_slide ["end_animation" ] == self .current_animation
149+ ):
139150 state = State .WAIT
140151 else :
141152 # Play next video!
@@ -162,15 +173,19 @@ def __init__(self, presentations, config, start_paused=False, fullscreen=False):
162173
163174 if fullscreen :
164175 cv2 .namedWindow ("Video" , cv2 .WND_PROP_FULLSCREEN )
165- cv2 .setWindowProperty ("Video" , cv2 .WND_PROP_FULLSCREEN , cv2 .WINDOW_FULLSCREEN )
176+ cv2 .setWindowProperty (
177+ "Video" , cv2 .WND_PROP_FULLSCREEN , cv2 .WINDOW_FULLSCREEN
178+ )
166179
167180 @property
168181 def current_presentation (self ):
169182 return self .presentations [self .current_presentation_i ]
170183
171184 def run (self ):
172185 while True :
173- self .lastframe , self .state = self .current_presentation .update_state (self .state )
186+ self .lastframe , self .state = self .current_presentation .update_state (
187+ self .state
188+ )
174189 if self .state == State .PLAYING or self .state == State .PAUSED :
175190 if self .start_paused :
176191 self .state = State .PAUSED
@@ -200,39 +215,34 @@ def show_info(self):
200215 info ,
201216 f"Animation: { self .current_presentation .current_animation } " ,
202217 (grid_x [0 ], grid_y [0 ]),
203- * font_args
204- )
205- cv2 .putText (
206- info ,
207- f"State: { self .state } " ,
208- (grid_x [1 ], grid_y [0 ]),
209- * font_args
218+ * font_args ,
210219 )
220+ cv2 .putText (info , f"State: { self .state } " , (grid_x [1 ], grid_y [0 ]), * font_args )
211221
212222 cv2 .putText (
213223 info ,
214224 f"Slide { self .current_presentation .current_slide ['number' ]} /{ len (self .current_presentation .slides )} " ,
215225 (grid_x [0 ], grid_y [1 ]),
216- * font_args
226+ * font_args ,
217227 )
218228 cv2 .putText (
219229 info ,
220230 f"Slide Type: { self .current_presentation .current_slide ['type' ]} " ,
221231 (grid_x [1 ], grid_y [1 ]),
222- * font_args
232+ * font_args ,
223233 )
224234
225235 cv2 .putText (
226236 info ,
227237 f"Scene { self .current_presentation_i + 1 } /{ len (self .presentations )} " ,
228- ((grid_x [0 ]+ grid_x [1 ])// 2 , grid_y [2 ]),
229- * font_args
238+ ((grid_x [0 ] + grid_x [1 ]) // 2 , grid_y [2 ]),
239+ * font_args ,
230240 )
231241
232242 cv2 .imshow ("Info" , info )
233243
234244 def handle_key (self ):
235- sleep_time = math .ceil (1000 / self .current_presentation .fps )
245+ sleep_time = math .ceil (1000 / self .current_presentation .fps )
236246 key = cv2 .waitKeyEx (fix_time (sleep_time - self .lag ))
237247
238248 if self .config .QUIT .match (key ):
@@ -241,7 +251,9 @@ def handle_key(self):
241251 self .state = State .PAUSED
242252 elif self .state == State .PAUSED and self .config .PLAY_PAUSE .match (key ):
243253 self .state = State .PLAYING
244- elif self .state == State .WAIT and (self .config .CONTINUE .match (key ) or self .config .PLAY_PAUSE .match (key )):
254+ elif self .state == State .WAIT and (
255+ self .config .CONTINUE .match (key ) or self .config .PLAY_PAUSE .match (key )
256+ ):
245257 self .current_presentation .next ()
246258 self .state = State .PLAYING
247259 elif self .state == State .PLAYING and self .config .CONTINUE .match (key ):
@@ -258,7 +270,6 @@ def handle_key(self):
258270 self .current_presentation .rewind_slide ()
259271 self .state = State .PLAYING
260272
261-
262273 def quit (self ):
263274 cv2 .destroyAllWindows ()
264275 sys .exit ()
@@ -267,10 +278,19 @@ def quit(self):
267278@click .command ()
268279@click .argument ("scenes" , nargs = - 1 )
269280@config_path_option
270- @click .option ("--folder" , default = FOLDER_PATH , type = click .Path (exists = True , file_okay = False ), help = "Set slides folder." )
281+ @click .option (
282+ "--folder" ,
283+ default = FOLDER_PATH ,
284+ type = click .Path (exists = True , file_okay = False ),
285+ help = "Set slides folder." ,
286+ )
271287@click .option ("--start-paused" , is_flag = True , help = "Start paused." )
272288@click .option ("--fullscreen" , is_flag = True , help = "Fullscreen mode." )
273- @click .option ("--last-frame-next" , is_flag = True , help = "Show the next animation first frame as last frame (hack)." )
289+ @click .option (
290+ "--last-frame-next" ,
291+ is_flag = True ,
292+ help = "Show the next animation first frame as last frame (hack)." ,
293+ )
274294@click .help_option ("-h" , "--help" )
275295def present (scenes , config_path , folder , start_paused , fullscreen , last_frame_next ):
276296 """Present the different scenes"""
@@ -279,7 +299,9 @@ def present(scenes, config_path, folder, start_paused, fullscreen, last_frame_ne
279299 for scene in scenes :
280300 config_file = os .path .join (folder , f"{ scene } .json" )
281301 if not os .path .exists (config_file ):
282- raise Exception (f"File { config_file } does not exist, check the scene name and make sure to use Slide as your scene base class" )
302+ raise Exception (
303+ f"File { config_file } does not exist, check the scene name and make sure to use Slide as your scene base class"
304+ )
283305 config = json .load (open (config_file ))
284306 presentations .append (Presentation (config , last_frame_next = last_frame_next ))
285307
@@ -288,5 +310,7 @@ def present(scenes, config_path, folder, start_paused, fullscreen, last_frame_ne
288310 else :
289311 config = Config ()
290312
291- display = Display (presentations , config = config , start_paused = start_paused , fullscreen = fullscreen )
313+ display = Display (
314+ presentations , config = config , start_paused = start_paused , fullscreen = fullscreen
315+ )
292316 display .run ()
0 commit comments