Running pre-commit

This commit is contained in:
Jérome Eertmans
2022-07-12 17:28:14 +02:00
parent 8081617e29
commit da0972ef43
6 changed files with 30 additions and 29 deletions

View File

@ -1,2 +1,2 @@
from .slide import Slide, ThreeDSlide
from .__version__ import __version__ from .__version__ import __version__
from .slide import Slide, ThreeDSlide

View File

@ -1,4 +1,5 @@
import click import click
from .defaults import CONFIG_PATH from .defaults import CONFIG_PATH

View File

@ -3,7 +3,7 @@ from click_default_group import DefaultGroup
from . import __version__ from . import __version__
from .present import present from .present import present
from .wizard import wizard, init from .wizard import init, wizard
@click.group(cls=DefaultGroup, default="present", default_if_no_args=True) @click.group(cls=DefaultGroup, default="present", default_if_no_args=True)

View File

@ -9,9 +9,9 @@ import click
import cv2 import cv2
import numpy as np import numpy as np
from .commons import config_path_option
from .config import Config from .config import Config
from .defaults import CONFIG_PATH, FOLDER_PATH from .defaults import CONFIG_PATH, FOLDER_PATH
from .commons import config_path_option
class State(Enum): class State(Enum):
@ -42,7 +42,7 @@ class Presentation:
self.lastframe = [] self.lastframe = []
self.caps = [None for _ in self.files] self.caps = [None for _ in self.files]
self.reset() self.reset()
self.add_last_slide() self.add_last_slide()
def add_last_slide(self): def add_last_slide(self):
@ -62,14 +62,14 @@ class Presentation:
self.load_this_cap(0) self.load_this_cap(0)
self.current_slide_i = 0 self.current_slide_i = 0
self.slides[-1]["terminated"] = False self.slides[-1]["terminated"] = False
def next(self): def next(self):
if self.current_slide["type"] == "last": if self.current_slide["type"] == "last":
self.current_slide["terminated"] = True self.current_slide["terminated"] = True
else: else:
self.current_slide_i = min(len(self.slides) - 1, self.current_slide_i + 1) self.current_slide_i = min(len(self.slides) - 1, self.current_slide_i + 1)
self.rewind_slide() self.rewind_slide()
def prev(self): def prev(self):
self.current_slide_i = max(0, self.current_slide_i - 1) self.current_slide_i = max(0, self.current_slide_i - 1)
self.rewind_slide() self.rewind_slide()
@ -77,7 +77,7 @@ class Presentation:
def rewind_slide(self): def rewind_slide(self):
self.current_animation = self.current_slide["start_animation"] self.current_animation = self.current_slide["start_animation"]
self.current_cap.set(cv2.CAP_PROP_POS_FRAMES, 0) self.current_cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
def load_this_cap(self,cap_number): def load_this_cap(self,cap_number):
if self.caps[cap_number] == None: if self.caps[cap_number] == None:
# unload other caps # unload other caps
@ -91,7 +91,7 @@ class Presentation:
@property @property
def current_slide(self): def current_slide(self):
return self.slides[self.current_slide_i] return self.slides[self.current_slide_i]
@property @property
def current_cap(self): def current_cap(self):
self.load_this_cap(self.current_animation) self.load_this_cap(self.current_animation)
@ -143,7 +143,7 @@ class Presentation:
self.load_this_cap(self.current_animation) self.load_this_cap(self.current_animation)
# Reset video to position zero if it has been played before # Reset video to position zero if it has been played before
self.current_cap.set(cv2.CAP_PROP_POS_FRAMES, 0) self.current_cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
return self.lastframe, state return self.lastframe, state
@ -163,11 +163,11 @@ class Display:
if fullscreen: if fullscreen:
cv2.namedWindow("Video", cv2.WND_PROP_FULLSCREEN) cv2.namedWindow("Video", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("Video", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) cv2.setWindowProperty("Video", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
@property @property
def current_presentation(self): def current_presentation(self):
return self.presentations[self.current_presentation_i] return self.presentations[self.current_presentation_i]
def run(self): def run(self):
while True: while True:
self.lastframe, self.state = self.current_presentation.update_state(self.state) self.lastframe, self.state = self.current_presentation.update_state(self.state)
@ -184,11 +184,11 @@ class Display:
self.handle_key() self.handle_key()
self.show_video() self.show_video()
self.show_info() self.show_info()
def show_video(self): def show_video(self):
self.lag = now() - self.last_time self.lag = now() - self.last_time
self.last_time = now() self.last_time = now()
cv2.imshow("Video", self.lastframe) cv2.imshow("Video", self.lastframe)
def show_info(self): def show_info(self):
info = np.zeros((130, 420), np.uint8) info = np.zeros((130, 420), np.uint8)
@ -230,11 +230,11 @@ class Display:
) )
cv2.imshow("Info", info) cv2.imshow("Info", info)
def handle_key(self): def handle_key(self):
sleep_time = math.ceil(1000/self.current_presentation.fps) sleep_time = math.ceil(1000/self.current_presentation.fps)
key = cv2.waitKeyEx(fix_time(sleep_time - self.lag)) key = cv2.waitKeyEx(fix_time(sleep_time - self.lag))
if self.config.QUIT.match(key): if self.config.QUIT.match(key):
self.quit() self.quit()
elif self.state == State.PLAYING and self.config.PLAY_PAUSE.match(key): elif self.state == State.PLAYING and self.config.PLAY_PAUSE.match(key):
@ -258,7 +258,7 @@ class Display:
self.current_presentation.rewind_slide() self.current_presentation.rewind_slide()
self.state = State.PLAYING self.state = State.PLAYING
def quit(self): def quit(self):
cv2.destroyAllWindows() cv2.destroyAllWindows()
sys.exit() sys.exit()

View File

@ -20,7 +20,7 @@ class Slide(Scene):
def play(self, *args, **kwargs): def play(self, *args, **kwargs):
super(Slide, self).play(*args, **kwargs) super(Slide, self).play(*args, **kwargs)
self.current_animation += 1 self.current_animation += 1
def pause(self): def pause(self):
self.slides.append(dict( self.slides.append(dict(
type="slide", type="slide",
@ -30,11 +30,11 @@ class Slide(Scene):
)) ))
self.current_slide += 1 self.current_slide += 1
self.pause_start_animation = self.current_animation self.pause_start_animation = self.current_animation
def start_loop(self): def start_loop(self):
assert self.loop_start_animation is None, "You cannot nest loops" assert self.loop_start_animation is None, "You cannot nest loops"
self.loop_start_animation = self.current_animation self.loop_start_animation = self.current_animation
def end_loop(self): def end_loop(self):
assert self.loop_start_animation is not None, "You have to start a loop before ending it" assert self.loop_start_animation is not None, "You have to start a loop before ending it"
self.slides.append(dict( self.slides.append(dict(
@ -46,32 +46,32 @@ class Slide(Scene):
self.current_slide += 1 self.current_slide += 1
self.loop_start_animation = None self.loop_start_animation = None
self.pause_start_animation = self.current_animation self.pause_start_animation = self.current_animation
def render(self, *args, **kwargs): def render(self, *args, **kwargs):
# We need to disable the caching limit since we rely on intermidiate files # We need to disable the caching limit since we rely on intermidiate files
max_files_cached = config["max_files_cached"] max_files_cached = config["max_files_cached"]
config["max_files_cached"] = float("inf") config["max_files_cached"] = float("inf")
super(Slide, self).render(*args, **kwargs) super(Slide, self).render(*args, **kwargs)
config["max_files_cached"] = max_files_cached config["max_files_cached"] = max_files_cached
if not os.path.exists(self.output_folder): if not os.path.exists(self.output_folder):
os.mkdir(self.output_folder) os.mkdir(self.output_folder)
files_folder = os.path.join(self.output_folder, "files") files_folder = os.path.join(self.output_folder, "files")
if not os.path.exists(files_folder): if not os.path.exists(files_folder):
os.mkdir(files_folder) os.mkdir(files_folder)
scene_name = type(self).__name__ scene_name = type(self).__name__
scene_files_folder = os.path.join(files_folder, scene_name) scene_files_folder = os.path.join(files_folder, scene_name)
if os.path.exists(scene_files_folder): if os.path.exists(scene_files_folder):
shutil.rmtree(scene_files_folder) shutil.rmtree(scene_files_folder)
if not os.path.exists(scene_files_folder): if not os.path.exists(scene_files_folder):
os.mkdir(scene_files_folder) os.mkdir(scene_files_folder)
files = list() files = list()
for src_file in self.renderer.file_writer.partial_movie_files: for src_file in self.renderer.file_writer.partial_movie_files:
dst_file = os.path.join(scene_files_folder, os.path.basename(src_file)) dst_file = os.path.join(scene_files_folder, os.path.basename(src_file))

View File

@ -5,8 +5,8 @@ import click
import cv2 import cv2
import numpy as np import numpy as np
from .config import Config
from .commons import config_options from .commons import config_options
from .config import Config
from .defaults import CONFIG_PATH from .defaults import CONFIG_PATH
@ -37,7 +37,7 @@ def _init(config_path, force, merge, skip_interactive=False):
if os.path.exists(config_path): if os.path.exists(config_path):
click.secho(f"The `{CONFIG_PATH}` configuration file exists") click.secho(f"The `{CONFIG_PATH}` configuration file exists")
if not force and not merge: if not force and not merge:
choice = click.prompt("Do you want to continue and (o)verwrite / (m)erge it, or (q)uit?", type=click.Choice(["o", "m", "q"], case_sensitive=False)) choice = click.prompt("Do you want to continue and (o)verwrite / (m)erge it, or (q)uit?", type=click.Choice(["o", "m", "q"], case_sensitive=False))