Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Add some exception handling on wrong colours and fix some errors

Syrus Dark804a98f3f953
diff --git a/example_scenes/manim.cfg b/example_scenes/manim.cfg
index dffdaea37..78ad3e99a 100644
--- a/example_scenes/manim.cfg
+++ b/example_scenes/manim.cfg
@@ -1,4 +1,5 @@
[log.color]
+#It is parsed by Rich Colour Parse `rich.color`
logging.keyword = magenta
logging.level.notset = dim
logging.level.debug = yellow
@@ -9,4 +10,4 @@ logging.level.critical = red
log.level =
log.time = dim yellow
log.message = green
-log.path = dim blue
\ No newline at end of file
+log.path = dim blue
diff --git a/manim/__main__.py b/manim/__main__.py
index d1536e26f..a64b35cfd 100644
--- a/manim/__main__.py
+++ b/manim/__main__.py
@@ -12,7 +12,7 @@ from .scene.scene import Scene
from .utils.sounds import play_error_sound
from .utils.sounds import play_finish_sound
from . import constants
-from .logger import logger
+from .logger import logger,console
def open_file_if_needed(file_writer):
@@ -72,10 +72,10 @@ def prompt_user_for_choice(scene_classes):
for count, scene_class in enumerate(scene_classes):
count += 1 # start with 1 instead of 0
name = scene_class.__name__
- print("%d: %s" % (count, name))
+ console.print("%d: %s" % (count, name),style="logging.level.info")
num_to_class[count] = scene_class
try:
- user_input = input(constants.CHOOSE_NUMBER_MESSAGE)
+ user_input = console.input("[log.message]"+constants.CHOOSE_NUMBER_MESSAGE+"[/log.message]")
return [num_to_class[int(num_str)]
for num_str in re.split(r"\s*,\s*", user_input.strip())]
except KeyError:
diff --git a/manim/config.py b/manim/config.py
index c3f55abda..399fa9ad0 100644
--- a/manim/config.py
+++ b/manim/config.py
@@ -1,3 +1,9 @@
+"""
+config.py
+---------
+Process the manim.cfg file and the command line arguments into a single
+config object.
+"""
import os
import sys
diff --git a/manim/logger.py b/manim/logger.py
index d00246f3d..ab1f75cdf 100644
--- a/manim/logger.py
+++ b/manim/logger.py
@@ -4,6 +4,8 @@ import logging
from rich.console import Console
from rich.logging import RichHandler
from rich.theme import Theme
+from rich import print as printf
+from rich import errors,color
from .utils.config_utils import config_parser, successfully_read_files
@@ -11,10 +13,14 @@ from .utils.config_utils import config_parser, successfully_read_files
def parse_theme(fp):
config_parser.read(fp)
theme = dict(config_parser["log.color"])
- customTheme = Theme(theme)
+ try:
+ customTheme = Theme(theme)
+ except (color.ColorParseError,errors.StyleSyntaxError):
+ customTheme = None
+ printf("[logging.level.error]Looks like your colour configuration has an error. So loading default color configuration[/logging.level.error]")
+ #console.log(e) #Not logging it as it looks clumsy
return customTheme
-
try:
customTheme = parse_theme(successfully_read_files)
console = Console(theme=customTheme)
diff --git a/manim/utils/cfgwriter.py b/manim/utils/cfgwriter.py
index 55945f387..ead61a251 100644
--- a/manim/utils/cfgwriter.py
+++ b/manim/utils/cfgwriter.py
@@ -1,3 +1,10 @@
+"""
+cfgwriter.py
+------------
+
+Inputs the configuration files while checking it is valid.
+
+"""
from os import path
import configparser
@@ -20,7 +27,7 @@ def check_valid_colour(color):
Returns whether it is valid color or not.
"""
try:
- Color.parse(color) is None
+ Color.parse(color)
return True
except:
return False
@@ -29,9 +36,7 @@ def check_valid_colour(color):
def main():
console = Console()
config = configparser.ConfigParser()
- config.read(
- successfully_read_files
- )
+ config.read( successfully_read_files )
default = {
"logging.keyword": "bold yellow",
"logging.level.notset": "dim",
@@ -58,7 +63,7 @@ def main():
console.print("Enter the Style for %s" % key + ":", style=key, end="")
temp = input()
if temp:
- while check_valid_colour(temp) == False:
+ while check_valid_colour(temp):
console.print(
"[red bold]Your Style is not valid. Try again.[/red bold]"
)
diff --git a/manim/utils/config_utils.py b/manim/utils/config_utils.py
index db22cdb29..cb48cc807 100644
--- a/manim/utils/config_utils.py
+++ b/manim/utils/config_utils.py
@@ -1,9 +1,8 @@
"""
-config.py
----------
+config_utils.py
+---------------
-Process the manim.cfg file and the command line arguments into a single
-config object.
+Utility functions for parsing manim config files.
"""