@@ -21,24 +21,33 @@ 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
3946 self .slides = config ["slides" ]
4047 self .files = config ["files" ]
4148
49+ print (self .slides )
50+
4251 self .lastframe = []
4352
4453 self .caps = [None for _ in self .files ]
@@ -48,14 +57,15 @@ def __init__(self, config, last_frame_next: bool = False):
4857 def add_last_slide (self ):
4958 last_slide_end = self .slides [- 1 ]["end_animation" ]
5059 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-
60+ self .slides .append (
61+ dict (
62+ start_animation = last_slide_end ,
63+ end_animation = last_animation ,
64+ type = "last" ,
65+ number = len (self .slides ) + 1 ,
66+ terminated = False ,
67+ )
68+ )
5969
6070 def reset (self ):
6171 self .current_animation = 0
@@ -78,7 +88,7 @@ def rewind_slide(self):
7888 self .current_animation = self .current_slide ["start_animation" ]
7989 self .current_cap .set (cv2 .CAP_PROP_POS_FRAMES , 0 )
8090
81- def load_this_cap (self ,cap_number ):
91+ def load_this_cap (self , cap_number ):
8292 if self .caps [cap_number ] == None :
8393 # unload other caps
8494 for i in range (len (self .caps )):
@@ -135,7 +145,10 @@ def update_state(self, state):
135145 self .rewind_slide ()
136146 elif self .current_slide ["type" ] == "last" :
137147 self .current_slide ["terminated" ] = True
138- elif self .current_slide ["type" ] == "last" and self .current_slide ["end_animation" ] == self .current_animation :
148+ elif (
149+ self .current_slide ["type" ] == "last"
150+ and self .current_slide ["end_animation" ] == self .current_animation
151+ ):
139152 state = State .WAIT
140153 else :
141154 # Play next video!
@@ -162,15 +175,19 @@ def __init__(self, presentations, config, start_paused=False, fullscreen=False):
162175
163176 if fullscreen :
164177 cv2 .namedWindow ("Video" , cv2 .WND_PROP_FULLSCREEN )
165- cv2 .setWindowProperty ("Video" , cv2 .WND_PROP_FULLSCREEN , cv2 .WINDOW_FULLSCREEN )
178+ cv2 .setWindowProperty (
179+ "Video" , cv2 .WND_PROP_FULLSCREEN , cv2 .WINDOW_FULLSCREEN
180+ )
166181
167182 @property
168183 def current_presentation (self ):
169184 return self .presentations [self .current_presentation_i ]
170185
171186 def run (self ):
172187 while True :
173- self .lastframe , self .state = self .current_presentation .update_state (self .state )
188+ self .lastframe , self .state = self .current_presentation .update_state (
189+ self .state
190+ )
174191 if self .state == State .PLAYING or self .state == State .PAUSED :
175192 if self .start_paused :
176193 self .state = State .PAUSED
@@ -200,39 +217,34 @@ def show_info(self):
200217 info ,
201218 f"Animation: { self .current_presentation .current_animation } " ,
202219 (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
220+ * font_args ,
210221 )
222+ cv2 .putText (info , f"State: { self .state } " , (grid_x [1 ], grid_y [0 ]), * font_args )
211223
212224 cv2 .putText (
213225 info ,
214226 f"Slide { self .current_presentation .current_slide ['number' ]} /{ len (self .current_presentation .slides )} " ,
215227 (grid_x [0 ], grid_y [1 ]),
216- * font_args
228+ * font_args ,
217229 )
218230 cv2 .putText (
219231 info ,
220232 f"Slide Type: { self .current_presentation .current_slide ['type' ]} " ,
221233 (grid_x [1 ], grid_y [1 ]),
222- * font_args
234+ * font_args ,
223235 )
224236
225237 cv2 .putText (
226238 info ,
227239 f"Scene { self .current_presentation_i + 1 } /{ len (self .presentations )} " ,
228- ((grid_x [0 ]+ grid_x [1 ])// 2 , grid_y [2 ]),
229- * font_args
240+ ((grid_x [0 ] + grid_x [1 ]) // 2 , grid_y [2 ]),
241+ * font_args ,
230242 )
231243
232244 cv2 .imshow ("Info" , info )
233245
234246 def handle_key (self ):
235- sleep_time = math .ceil (1000 / self .current_presentation .fps )
247+ sleep_time = math .ceil (1000 / self .current_presentation .fps )
236248 key = cv2 .waitKeyEx (fix_time (sleep_time - self .lag ))
237249
238250 if self .config .QUIT .match (key ):
@@ -241,7 +253,9 @@ def handle_key(self):
241253 self .state = State .PAUSED
242254 elif self .state == State .PAUSED and self .config .PLAY_PAUSE .match (key ):
243255 self .state = State .PLAYING
244- elif self .state == State .WAIT and (self .config .CONTINUE .match (key ) or self .config .PLAY_PAUSE .match (key )):
256+ elif self .state == State .WAIT and (
257+ self .config .CONTINUE .match (key ) or self .config .PLAY_PAUSE .match (key )
258+ ):
245259 self .current_presentation .next ()
246260 self .state = State .PLAYING
247261 elif self .state == State .PLAYING and self .config .CONTINUE .match (key ):
@@ -258,7 +272,6 @@ def handle_key(self):
258272 self .current_presentation .rewind_slide ()
259273 self .state = State .PLAYING
260274
261-
262275 def quit (self ):
263276 cv2 .destroyAllWindows ()
264277 sys .exit ()
@@ -267,10 +280,19 @@ def quit(self):
267280@click .command ()
268281@click .argument ("scenes" , nargs = - 1 )
269282@config_path_option
270- @click .option ("--folder" , default = FOLDER_PATH , type = click .Path (exists = True , file_okay = False ), help = "Set slides folder." )
283+ @click .option (
284+ "--folder" ,
285+ default = FOLDER_PATH ,
286+ type = click .Path (exists = True , file_okay = False ),
287+ help = "Set slides folder." ,
288+ )
271289@click .option ("--start-paused" , is_flag = True , help = "Start paused." )
272290@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)." )
291+ @click .option (
292+ "--last-frame-next" ,
293+ is_flag = True ,
294+ help = "Show the next animation first frame as last frame (hack)." ,
295+ )
274296@click .help_option ("-h" , "--help" )
275297def present (scenes , config_path , folder , start_paused , fullscreen , last_frame_next ):
276298 """Present the different scenes"""
@@ -279,7 +301,9 @@ def present(scenes, config_path, folder, start_paused, fullscreen, last_frame_ne
279301 for scene in scenes :
280302 config_file = os .path .join (folder , f"{ scene } .json" )
281303 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" )
304+ raise Exception (
305+ f"File { config_file } does not exist, check the scene name and make sure to use Slide as your scene base class"
306+ )
283307 config = json .load (open (config_file ))
284308 presentations .append (Presentation (config , last_frame_next = last_frame_next ))
285309
@@ -288,5 +312,7 @@ def present(scenes, config_path, folder, start_paused, fullscreen, last_frame_ne
288312 else :
289313 config = Config ()
290314
291- display = Display (presentations , config = config , start_paused = start_paused , fullscreen = fullscreen )
315+ display = Display (
316+ presentations , config = config , start_paused = start_paused , fullscreen = fullscreen
317+ )
292318 display .run ()
0 commit comments