Skip to content

Commit 4a26029

Browse files
committed
Verify that the value assigned to window_size in the config has an expected value
1 parent 509386b commit 4a26029

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

manim/_config/utils.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,25 @@ def _determine_quality(qual: str | None) -> str:
143143
return qual
144144

145145

146+
def _parse_window_size(window_size: str | tuple[int, ...]) -> tuple[int, int] | str:
147+
invalid_window_size_error_message = (
148+
"window_size must be specified either as 'default', a string of the form "
149+
"'width,height', or a tuple of 2 ints of the form (width, height)."
150+
)
151+
152+
if isinstance(window_size, tuple):
153+
if len(window_size) != 2:
154+
raise ValueError(invalid_window_size_error_message)
155+
return window_size
156+
elif len(window_size.split(",")) == 2:
157+
(window_width, window_height) = tuple(map(int, window_size.split(",")))
158+
return (window_width, window_height)
159+
elif window_size == "default":
160+
return window_size
161+
else:
162+
raise ValueError(invalid_window_size_error_message)
163+
164+
146165
class ManimConfig(MutableMapping):
147166
"""Dict-like class storing all config options.
148167
@@ -1431,7 +1450,8 @@ def window_size(self) -> str | tuple[int, ...]:
14311450

14321451
@window_size.setter
14331452
def window_size(self, value: str | tuple[int, ...]) -> None:
1434-
self._d.__setitem__("window_size", value)
1453+
window_size = _parse_window_size(value)
1454+
self._d.__setitem__("window_size", window_size)
14351455

14361456
def resolve_movie_file_extension(self, is_transparent: bool) -> None:
14371457
prev_file_extension = self.movie_file_extension

0 commit comments

Comments
 (0)