Skip to content

Commit d717bc6

Browse files
refactor: use PyQT5 for window display (#49)
* wip: use PyQT5 for window display * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * wip: first slide is shown * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * wip: pushing non-working code * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * wip: some logging * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * feat: new configuration wizard working * fix: prevent key error * wip: making action work * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * wip: soon done! info + video * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: bugs in sleep and exiting * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * try: offscreen * fix: pop default value if not present * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * feat: add aspect ratio option * chore: typing wip * fix: now() function returns seconds, not milliseconds anymore Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent bc3d55f commit d717bc6

File tree

10 files changed

+464
-255
lines changed

10 files changed

+464
-255
lines changed

.github/workflows/test_examples.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66

77
name: Test Examples
88

9+
env:
10+
QT_QPA_PLATFORM: offscreen
11+
912
jobs:
1013
build-examples:
1114
strategy:

.pre-commit-config.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,13 @@ repos:
3838
- --ignore-missing-imports
3939
# Disallow dynamic typing
4040
- --disallow-any-unimported
41-
- --disallow-any-expr
42-
- --disallow-any-decorated
4341
- --disallow-any-generics
44-
- --disallow-any-explicit
4542
- --disallow-subclassing-any
4643

4744
# Disallow untyped definitions and calls
4845
- --disallow-untyped-defs
4946
- --disallow-incomplete-defs
5047
- --check-untyped-defs
51-
- --disallow-untyped-decorators
5248

5349
# None and optional handling
5450
- --no-implicit-optional

manim_slides/config.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from typing import List, Optional, Set
44

55
from pydantic import BaseModel, root_validator, validator
6+
from PyQt5.QtCore import Qt
67

7-
from .defaults import LEFT_ARROW_KEY_CODE, RIGHT_ARROW_KEY_CODE
88
from .manim import logger
99

1010

@@ -14,13 +14,16 @@ class Key(BaseModel):
1414
ids: Set[int]
1515
name: Optional[str] = None
1616

17+
def set_ids(self, *ids: int) -> None:
18+
self.ids = set(ids)
19+
1720
@validator("ids", each_item=True)
18-
def id_is_posint(cls, v: int):
21+
def id_is_posint(cls, v: int) -> int:
1922
if v < 0:
2023
raise ValueError("Key ids cannot be negative integers")
2124
return v
2225

23-
def match(self, key_id: int):
26+
def match(self, key_id: int) -> bool:
2427
m = key_id in self.ids
2528

2629
if m:
@@ -32,12 +35,12 @@ def match(self, key_id: int):
3235
class Config(BaseModel):
3336
"""General Manim Slides config"""
3437

35-
QUIT: Key = Key(ids=[ord("q")], name="QUIT")
36-
CONTINUE: Key = Key(ids=[RIGHT_ARROW_KEY_CODE], name="CONTINUE / NEXT")
37-
BACK: Key = Key(ids=[LEFT_ARROW_KEY_CODE], name="BACK")
38-
REVERSE: Key = Key(ids=[ord("v")], name="REVERSE")
39-
REWIND: Key = Key(ids=[ord("r")], name="REWIND")
40-
PLAY_PAUSE: Key = Key(ids=[32], name="PLAY / PAUSE")
38+
QUIT: Key = Key(ids=[Qt.Key_Q], name="QUIT")
39+
CONTINUE: Key = Key(ids=[Qt.Key_Right], name="CONTINUE / NEXT")
40+
BACK: Key = Key(ids=[Qt.Key_Left], name="BACK")
41+
REVERSE: Key = Key(ids=[Qt.Key_V], name="REVERSE")
42+
REWIND: Key = Key(ids=[Qt.Key_R], name="REWIND")
43+
PLAY_PAUSE: Key = Key(ids=[Qt.Key_Space], name="PLAY / PAUSE")
4144

4245
@root_validator
4346
def ids_are_unique_across_keys(cls, values):
@@ -46,7 +49,7 @@ def ids_are_unique_across_keys(cls, values):
4649
for key in values.values():
4750
if len(ids.intersection(key.ids)) != 0:
4851
raise ValueError(
49-
"Two or more keys share a common key code: please make sure each key has distinc key codes"
52+
"Two or more keys share a common key code: please make sure each key has distinct key codes"
5053
)
5154
ids.update(key.ids)
5255

manim_slides/defaults.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,2 @@
1-
import platform
2-
from typing import Tuple
3-
4-
import cv2
5-
6-
__all__ = [
7-
"FONT_ARGS",
8-
"FOLDER_PATH",
9-
"CONFIG_PATH",
10-
"RIGHT_ARROW_KEY_CODE",
11-
"LEFT_ARROW_KEY_CODE",
12-
]
13-
14-
FONT_ARGS: Tuple[int, int, int, int, int] = (
15-
cv2.FONT_HERSHEY_SIMPLEX, # type: ignore
16-
1,
17-
255,
18-
1,
19-
cv2.LINE_AA, # type: ignore
20-
)
211
FOLDER_PATH: str = "./slides"
222
CONFIG_PATH: str = ".manim-slides.json"
23-
24-
if platform.system() == "Windows":
25-
RIGHT_ARROW_KEY_CODE: int = 2555904
26-
LEFT_ARROW_KEY_CODE: int = 2424832
27-
elif platform.system() == "Darwin":
28-
RIGHT_ARROW_KEY_CODE = 63235
29-
LEFT_ARROW_KEY_CODE = 63234
30-
else:
31-
RIGHT_ARROW_KEY_CODE = 65363
32-
LEFT_ARROW_KEY_CODE = 65361

manim_slides/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@click.group(cls=DefaultGroup, default="present", default_if_no_args=True)
1010
@click.version_option(__version__, "-v", "--version")
1111
@click.help_option("-h", "--help")
12-
def cli():
12+
def cli() -> None:
1313
"""
1414
Manim Slides command-line utilities.
1515

manim_slides/manim.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
from contextlib import contextmanager
44
from importlib.util import find_spec
5+
from typing import Iterator
56

67
__all__ = [
78
"MANIM",
@@ -21,7 +22,7 @@
2122

2223

2324
@contextmanager
24-
def suppress_stdout() -> None:
25+
def suppress_stdout() -> Iterator[None]:
2526
with open(os.devnull, "w") as devnull:
2627
old_stdout = sys.stdout
2728
sys.stdout = devnull
@@ -65,8 +66,6 @@ def suppress_stdout() -> None:
6566
)
6667

6768

68-
FFMPEG_BIN = None
69-
7069
if MANIMGL:
7170
from manimlib import Scene, ThreeDScene, config
7271
from manimlib.constants import FFMPEG_BIN

0 commit comments

Comments
 (0)