From 93be1ebd29cc3bc9d8f7e4ff51289c3625fd9e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Fri, 24 Nov 2023 12:03:39 +0100 Subject: [PATCH 1/6] feat(lib): enhance notes support TODO: fix keyboard inputs and window order with `present`. --- manim_slides/config.py | 12 ++++++++++++ manim_slides/convert.py | 3 +++ manim_slides/present/player.py | 8 ++++---- manim_slides/render.py | 2 +- manim_slides/slide/base.py | 8 ++++++-- manim_slides/templates/revealjs.html | 5 +++-- 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/manim_slides/config.py b/manim_slides/config.py index dd3e3921..d9e4475e 100644 --- a/manim_slides/config.py +++ b/manim_slides/config.py @@ -3,6 +3,7 @@ from functools import wraps from inspect import Parameter, signature from pathlib import Path +from textwrap import dedent from typing import Any, Callable, Dict, List, Optional, Set, Tuple import rtoml @@ -145,6 +146,7 @@ class BaseSlideConfig(BaseModel): # type: ignore playback_rate: float = 1.0 reversed_playback_rate: float = 1.0 notes: str = "" + dedent_notes: bool = True @classmethod def wrapper(cls, arg_name: str) -> Callable[..., Any]: @@ -188,6 +190,16 @@ def __wrapper__(*args: Any, **kwargs: Any) -> Any: # noqa: N807 return _wrapper_ + @model_validator(mode="after") + @classmethod + def apply_dedent_notes( + cls, base_slide_config: "BaseSlideConfig" + ) -> "BaseSlideConfig": + if base_slide_config.dedent_notes: + base_slide_config.notes = dedent(base_slide_config.notes) + + return base_slide_config + class PreSlideConfig(BaseSlideConfig): """Slide config to be used prior to rendering.""" diff --git a/manim_slides/convert.py b/manim_slides/convert.py index da18c872..c000d40e 100644 --- a/manim_slides/convert.py +++ b/manim_slides/convert.py @@ -557,6 +557,9 @@ def save_first_image_from_video_file(file: Path) -> Optional[str]: poster_frame_image=poster_frame_image, mime_type=mime_type, ) + if slide_config.notes != "": + slide.notes_slide.notes_text_frame.text = slide_config.notes + if self.auto_play_media: auto_play_media(movie, loop=slide_config.loop) diff --git a/manim_slides/present/player.py b/manim_slides/present/player.py index 52d22bb0..2b0e1879 100644 --- a/manim_slides/present/player.py +++ b/manim_slides/present/player.py @@ -5,7 +5,7 @@ from PySide6.QtGui import QCloseEvent, QIcon, QKeyEvent, QScreen from PySide6.QtMultimedia import QMediaPlayer from PySide6.QtMultimediaWidgets import QVideoWidget -from PySide6.QtWidgets import QDialog, QGridLayout, QLabel, QMainWindow, QVBoxLayout +from PySide6.QtWidgets import QDialog, QGridLayout, QLabel, QMainWindow, QVBoxLayout, QTextEdit from ..config import Config, PresentationConfig, SlideConfig from ..logger import logger @@ -23,8 +23,8 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: notes_layout = QVBoxLayout() self.scene_label = QLabel() self.slide_label = QLabel() - self.slide_notes = QLabel("") - self.slide_notes.setWordWrap(True) + self.slide_notes = QTextEdit() + self.slide_notes.setReadOnly(True) labels_layout.addWidget(QLabel("Scene:"), 1, 1) labels_layout.addWidget(QLabel("Slide:"), 2, 1) @@ -320,7 +320,7 @@ def slide_changed_callback(self) -> None: index = self.current_slide_index count = self.current_slides_count self.info.slide_label.setText(f"{index+1:4d}/{count:4 None: super().show() diff --git a/manim_slides/render.py b/manim_slides/render.py index 1fc3f387..37a5e56a 100644 --- a/manim_slides/render.py +++ b/manim_slides/render.py @@ -43,7 +43,7 @@ def render(ce: bool, gl: bool, args: Tuple[str, ...]) -> None: """ Render SCENE(s) from the input FILE, using the specified renderer. - Use 'manim-slides render --help' to see help information for + Use ``manim-slides render --help`` to see help information for a the specified renderer. """ if ce and gl: diff --git a/manim_slides/slide/base.py b/manim_slides/slide/base.py index 5f5ca63a..88c2af19 100644 --- a/manim_slides/slide/base.py +++ b/manim_slides/slide/base.py @@ -289,10 +289,14 @@ def next_slide( Note that this is only supported by ``manim-slides present``. :param notes: - Presenter notes, in HTML format. + Presenter notes, in Markdown format. + + Note that PowerPoint does not support Markdown. Note that this is only supported by ``manim-slides present`` - and ``manim-slides convert --to=html``. + and ``manim-slides convert --to=html/pptx``. + :param dedent_notes: + If set, apply :func:`textwrap.dedent` to notes. :param kwargs: Keyword arguments to be passed to :meth:`Scene.next_section`, diff --git a/manim_slides/templates/revealjs.html b/manim_slides/templates/revealjs.html index 7d357af0..80d0ca70 100644 --- a/manim_slides/templates/revealjs.html +++ b/manim_slides/templates/revealjs.html @@ -41,7 +41,7 @@ data-autoslide="{{ get_duration_ms(slide_config.file) }}" {%- endif -%}> {% if slide_config.notes != "" -%} - + {%- endif %} {%- endfor -%} @@ -54,6 +54,7 @@ {% if has_notes -%} + {%- endif -%} @@ -61,7 +62,7 @@