mirror of
https://github.com/jeertmans/manim-slides.git
synced 2025-08-06 14:19:52 +08:00
feat(cli): add resize mode option (#59)
This adds a new option that allows to control how the video is going to be scaled. By default, we now use a smooth rescaling, but fast mode with no interpolation can be used (previously default).
This commit is contained in:
@ -148,3 +148,6 @@ class PresentationConfig(BaseModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_CONFIG = Config()
|
||||||
|
@ -16,7 +16,7 @@ from PyQt5.QtWidgets import QApplication, QGridLayout, QLabel, QWidget
|
|||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
from .commons import config_path_option, verbosity_option
|
from .commons import config_path_option, verbosity_option
|
||||||
from .config import Config, PresentationConfig, SlideConfig, SlideType
|
from .config import DEFAULT_CONFIG, Config, PresentationConfig, SlideConfig, SlideType
|
||||||
from .defaults import FOLDER_PATH
|
from .defaults import FOLDER_PATH
|
||||||
from .manim import logger
|
from .manim import logger
|
||||||
|
|
||||||
@ -33,6 +33,11 @@ ASPECT_RATIO_MODES = {
|
|||||||
"keep": Qt.KeepAspectRatio,
|
"keep": Qt.KeepAspectRatio,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RESIZE_MODES = {
|
||||||
|
"fast": Qt.FastTransformation,
|
||||||
|
"smooth": Qt.SmoothTransformation,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@unique
|
@unique
|
||||||
class State(IntEnum):
|
class State(IntEnum):
|
||||||
@ -284,7 +289,7 @@ class Display(QThread):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
presentations,
|
presentations,
|
||||||
config: Config = Config(),
|
config: Config = DEFAULT_CONFIG,
|
||||||
start_paused=False,
|
start_paused=False,
|
||||||
skip_all=False,
|
skip_all=False,
|
||||||
record_to=None,
|
record_to=None,
|
||||||
@ -517,11 +522,12 @@ class App(QWidget):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*args,
|
*args,
|
||||||
config: Config = Config(),
|
config: Config = DEFAULT_CONFIG,
|
||||||
fullscreen: bool = False,
|
fullscreen: bool = False,
|
||||||
resolution: Tuple[int, int] = (1980, 1080),
|
resolution: Tuple[int, int] = (1980, 1080),
|
||||||
hide_mouse: bool = False,
|
hide_mouse: bool = False,
|
||||||
aspect_ratio: Qt.AspectRatioMode = Qt.IgnoreAspectRatio,
|
aspect_ratio: Qt.AspectRatioMode = Qt.IgnoreAspectRatio,
|
||||||
|
resize_mode: Qt.TransformationMode = Qt.SmoothTransformation,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -529,6 +535,7 @@ class App(QWidget):
|
|||||||
self.setWindowTitle(WINDOW_NAME)
|
self.setWindowTitle(WINDOW_NAME)
|
||||||
self.display_width, self.display_height = resolution
|
self.display_width, self.display_height = resolution
|
||||||
self.aspect_ratio = aspect_ratio
|
self.aspect_ratio = aspect_ratio
|
||||||
|
self.resize_mode = resize_mode
|
||||||
self.hide_mouse = hide_mouse
|
self.hide_mouse = hide_mouse
|
||||||
self.config = config
|
self.config = config
|
||||||
if self.hide_mouse:
|
if self.hide_mouse:
|
||||||
@ -584,7 +591,9 @@ class App(QWidget):
|
|||||||
self.deleteLater()
|
self.deleteLater()
|
||||||
|
|
||||||
def resizeEvent(self, event):
|
def resizeEvent(self, event):
|
||||||
self.pixmap = self.pixmap.scaled(self.width(), self.height(), self.aspect_ratio)
|
self.pixmap = self.pixmap.scaled(
|
||||||
|
self.width(), self.height(), self.aspect_ratio, self.resize_mode
|
||||||
|
)
|
||||||
self.label.setPixmap(self.pixmap)
|
self.label.setPixmap(self.pixmap)
|
||||||
self.label.resize(self.width(), self.height())
|
self.label.resize(self.width(), self.height())
|
||||||
|
|
||||||
@ -615,6 +624,7 @@ class App(QWidget):
|
|||||||
self.width(),
|
self.width(),
|
||||||
self.height(),
|
self.height(),
|
||||||
self.aspect_ratio,
|
self.aspect_ratio,
|
||||||
|
self.resize_mode,
|
||||||
)
|
)
|
||||||
return QPixmap.fromImage(p)
|
return QPixmap.fromImage(p)
|
||||||
|
|
||||||
@ -708,6 +718,13 @@ def _list_scenes(folder) -> List[str]:
|
|||||||
help="Set the aspect ratio mode to be used when rescaling video.",
|
help="Set the aspect ratio mode to be used when rescaling video.",
|
||||||
show_default=True,
|
show_default=True,
|
||||||
)
|
)
|
||||||
|
@click.option(
|
||||||
|
"--resize-mode",
|
||||||
|
type=click.Choice(RESIZE_MODES.keys(), case_sensitive=False),
|
||||||
|
default="smooth",
|
||||||
|
help="Set the resize (i.e., transformation) mode to be used when rescaling video.",
|
||||||
|
show_default=True,
|
||||||
|
)
|
||||||
@click.help_option("-h", "--help")
|
@click.help_option("-h", "--help")
|
||||||
@verbosity_option
|
@verbosity_option
|
||||||
def present(
|
def present(
|
||||||
@ -722,6 +739,7 @@ def present(
|
|||||||
exit_after_last_slide,
|
exit_after_last_slide,
|
||||||
hide_mouse,
|
hide_mouse,
|
||||||
aspect_ratio,
|
aspect_ratio,
|
||||||
|
resize_mode,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Present SCENE(s), one at a time, in order.
|
Present SCENE(s), one at a time, in order.
|
||||||
@ -813,6 +831,7 @@ def present(
|
|||||||
exit_after_last_slide=exit_after_last_slide,
|
exit_after_last_slide=exit_after_last_slide,
|
||||||
hide_mouse=hide_mouse,
|
hide_mouse=hide_mouse,
|
||||||
aspect_ratio=ASPECT_RATIO_MODES[aspect_ratio],
|
aspect_ratio=ASPECT_RATIO_MODES[aspect_ratio],
|
||||||
|
resize_mode=RESIZE_MODES[resize_mode],
|
||||||
)
|
)
|
||||||
a.show()
|
a.show()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
Reference in New Issue
Block a user