def parse_theme(fp): config_parser.read(fp) theme = dict(config_parser["logger"]) # replaces `_` by `.` as rich understands it theme = dict( zip([key.replace("_", ".") for key in theme.keys()], list(theme.values()))) theme["log.width"] = None if theme["log.width"] == "-1" else int( theme["log.width"]) theme["log.height"] = (None if theme["log.height"] == "-1" else int( theme["log.height"])) theme["log.timestamps"] = config_parser["logger"].getboolean( "log.timestamps") try: customTheme = Theme({ k: v for k, v in theme.items() if k not in ["log.width", "log.height", "log.timestamps"] }) except (color.ColorParseError, errors.StyleSyntaxError): customTheme = None printf( "[logging.level.error]It seems your colour configuration couldn't be parsed. Loading the default color configuration...[/logging.level.error]" ) return customTheme, theme
def _parse_theme(config_logger): theme = dict( zip( [key.replace("_", ".") for key in config_logger.keys()], list(config_logger.values()), )) theme["log.width"] = None if theme["log.width"] == "-1" else int( theme["log.width"]) theme["log.height"] = (None if theme["log.height"] == "-1" else int( theme["log.height"])) theme["log.timestamps"] = False try: customTheme = Theme({ k: v for k, v in theme.items() if k not in ["log.width", "log.height", "log.timestamps"] }) except (color.ColorParseError, errors.StyleSyntaxError): customTheme = None printf( "[logging.level.error]It seems your colour configuration couldn't be parsed. Loading the default color configuration...[/logging.level.error]" ) return customTheme
def parse_theme(config_logger): theme = dict( zip( [key.replace("_", ".") for key in config_logger.keys()], list(config_logger.values()), ) ) theme["log.width"] = None if theme["log.width"] == "-1" else int(theme["log.width"]) theme["log.height"] = ( None if theme["log.height"] == "-1" else int(theme["log.height"]) ) theme["log.timestamps"] = False try: customTheme = Theme( { k: v for k, v in theme.items() if k not in ["log.width", "log.height", "log.timestamps"] } ) except (color.ColorParseError, errors.StyleSyntaxError): printf(WRONG_COLOR_CONFIG_MSG) customTheme = None return customTheme
def parse_theme(fp): config_parser.read(fp) theme = dict(config_parser["logger"]) # replaces `_` by `.` as rich understands it for key in theme: temp = theme[key] del theme[key] key = key.replace("_", ".") theme[key] = temp try: customTheme = Theme(theme) except (color.ColorParseError, errors.StyleSyntaxError): customTheme = None printf( "[logging.level.error]It seems your colour configuration couldn't be parsed. Loading the default color configuration...[/logging.level.error]" ) return customTheme
def parse_theme(parser: configparser.ConfigParser) -> Theme: """Configure the rich style of logger and console output. Parameters ---------- parser : :class:`configparser.ConfigParser` A parser containing any .cfg files in use. Returns ------- :class:`rich.Theme` The rich theme to be used by the manim logger. See Also -------- :func:`make_logger`. """ theme = {key.replace("_", "."): parser[key] for key in parser} theme["log.width"] = None if theme["log.width"] == "-1" else int(theme["log.width"]) theme["log.height"] = ( None if theme["log.height"] == "-1" else int(theme["log.height"]) ) theme["log.timestamps"] = False try: custom_theme = Theme( { k: v for k, v in theme.items() if k not in ["log.width", "log.height", "log.timestamps"] }, ) except (color.ColorParseError, errors.StyleSyntaxError): printf(WRONG_COLOR_CONFIG_MSG) custom_theme = None return custom_theme
return customTheme, theme config_items = _run_config() config_parser, successfully_read_files = config_items[1], config_items[-1] try: customTheme, themedict = parse_theme(successfully_read_files) console = Console( theme=customTheme, record=True, height=themedict["log.height"], width=themedict["log.width"], ) except KeyError: console = Console(record=True) printf("[logging.level.warning]No cfg file found, creating one in " + successfully_read_files[0] + " [/logging.level.warning]") # These keywords Are Highlighted specially. RichHandler.KEYWORDS = [ "Played", "animations", "scene", "Reading", "Writing", "script", "arguments", "Invalid", "Aborting", "module", "File", "Rendering",