99import cv2
1010import numpy as np
1111
12+ from .commons import config_path_option
1213from .config import Config
1314from .defaults import CONFIG_PATH , FOLDER_PATH
14- from .commons import config_path_option
1515
1616
1717class State (Enum ):
@@ -42,7 +42,7 @@ def __init__(self, config, last_frame_next: bool = False):
4242 self .lastframe = []
4343
4444 self .caps = [None for _ in self .files ]
45- self .reset ()
45+ self .reset ()
4646 self .add_last_slide ()
4747
4848 def add_last_slide (self ):
@@ -62,22 +62,22 @@ def reset(self):
6262 self .load_this_cap (0 )
6363 self .current_slide_i = 0
6464 self .slides [- 1 ]["terminated" ] = False
65-
65+
6666 def next (self ):
6767 if self .current_slide ["type" ] == "last" :
6868 self .current_slide ["terminated" ] = True
6969 else :
7070 self .current_slide_i = min (len (self .slides ) - 1 , self .current_slide_i + 1 )
7171 self .rewind_slide ()
72-
72+
7373 def prev (self ):
7474 self .current_slide_i = max (0 , self .current_slide_i - 1 )
7575 self .rewind_slide ()
7676
7777 def rewind_slide (self ):
7878 self .current_animation = self .current_slide ["start_animation" ]
7979 self .current_cap .set (cv2 .CAP_PROP_POS_FRAMES , 0 )
80-
80+
8181 def load_this_cap (self ,cap_number ):
8282 if self .caps [cap_number ] == None :
8383 # unload other caps
@@ -91,7 +91,7 @@ def load_this_cap(self,cap_number):
9191 @property
9292 def current_slide (self ):
9393 return self .slides [self .current_slide_i ]
94-
94+
9595 @property
9696 def current_cap (self ):
9797 self .load_this_cap (self .current_animation )
@@ -143,7 +143,7 @@ def update_state(self, state):
143143 self .load_this_cap (self .current_animation )
144144 # Reset video to position zero if it has been played before
145145 self .current_cap .set (cv2 .CAP_PROP_POS_FRAMES , 0 )
146-
146+
147147 return self .lastframe , state
148148
149149
@@ -163,11 +163,11 @@ def __init__(self, presentations, config, start_paused=False, fullscreen=False):
163163 if fullscreen :
164164 cv2 .namedWindow ("Video" , cv2 .WND_PROP_FULLSCREEN )
165165 cv2 .setWindowProperty ("Video" , cv2 .WND_PROP_FULLSCREEN , cv2 .WINDOW_FULLSCREEN )
166-
166+
167167 @property
168168 def current_presentation (self ):
169169 return self .presentations [self .current_presentation_i ]
170-
170+
171171 def run (self ):
172172 while True :
173173 self .lastframe , self .state = self .current_presentation .update_state (self .state )
@@ -184,11 +184,11 @@ def run(self):
184184 self .handle_key ()
185185 self .show_video ()
186186 self .show_info ()
187-
187+
188188 def show_video (self ):
189189 self .lag = now () - self .last_time
190190 self .last_time = now ()
191- cv2 .imshow ("Video" , self .lastframe )
191+ cv2 .imshow ("Video" , self .lastframe )
192192
193193 def show_info (self ):
194194 info = np .zeros ((130 , 420 ), np .uint8 )
@@ -230,11 +230,11 @@ def show_info(self):
230230 )
231231
232232 cv2 .imshow ("Info" , info )
233-
233+
234234 def handle_key (self ):
235235 sleep_time = math .ceil (1000 / self .current_presentation .fps )
236236 key = cv2 .waitKeyEx (fix_time (sleep_time - self .lag ))
237-
237+
238238 if self .config .QUIT .match (key ):
239239 self .quit ()
240240 elif self .state == State .PLAYING and self .config .PLAY_PAUSE .match (key ):
@@ -258,7 +258,7 @@ def handle_key(self):
258258 self .current_presentation .rewind_slide ()
259259 self .state = State .PLAYING
260260
261-
261+
262262 def quit (self ):
263263 cv2 .destroyAllWindows ()
264264 sys .exit ()
0 commit comments