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.cfgindex 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 = magentalogging.level.notset = dimlogging.level.debug = yellow@@ -9,4 +10,4 @@ logging.level.critical = redlog.level =log.time = dim yellowlog.message = green-log.path = dim blue\ No newline at end of file+log.path = dim bluediff --git a/manim/__main__.py b/manim/__main__.pyindex d1536e26f..a64b35cfd 100644--- a/manim/__main__.py+++ b/manim/__main__.py@@ -12,7 +12,7 @@ from .scene.scene import Scenefrom .utils.sounds import play_error_soundfrom .utils.sounds import play_finish_soundfrom . import constants-from .logger import logger+from .logger import logger,consoledef 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 0name = scene_class.__name__- print("%d: %s" % (count, name))+ console.print("%d: %s" % (count, name),style="logging.level.info")num_to_class[count] = scene_classtry:- 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.pyindex 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 osimport sysdiff --git a/manim/logger.py b/manim/logger.pyindex d00246f3d..ab1f75cdf 100644--- a/manim/logger.py+++ b/manim/logger.py@@ -4,6 +4,8 @@ import loggingfrom rich.console import Consolefrom rich.logging import RichHandlerfrom rich.theme import Theme+from rich import print as printf+from rich import errors,colorfrom .utils.config_utils import config_parser, successfully_read_files@@ -11,10 +13,14 @@ from .utils.config_utils import config_parser, successfully_read_filesdef 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 clumsyreturn customTheme-try:customTheme = parse_theme(successfully_read_files)console = Console(theme=customTheme)diff --git a/manim/utils/cfgwriter.py b/manim/utils/cfgwriter.pyindex 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 pathimport 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 Trueexcept: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.pyindex 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."""