Utilities

CodeVideoRenderer.utils.noManimOutput() Generator[None, Any, None][source]

Context manager used to execute code without outputting Manim logs.

CodeVideoRenderer.utils.stripEmptyLines(text: str) str[source]

Remove empty lines from the beginning and end of a string.

Parameters:

text (str) – The input string to process.

Returns:

The string with empty lines removed from the beginning and end.

Return type:

str

CodeVideoRenderer.utils.typeName(item_type: Any) str[source]

Get the name of a type, handling union types and generic types.

Parameters:

item_type – The type or value to get the name of.

Returns:

The name of the type.

Return type:

str

CodeVideoRenderer.utils.checkType(value: Any, expected_type: Any | type[Any], param_name: str, path: str = '') None[source]

Recursively check if a value matches the expected type.

Parameters:
  • value (Any) – The value to check.

  • expected_type (Any | type[Any]) – The expected type.

  • param_name (str) – The name of the parameter being checked.

  • path (str, optional) – The path to the current value (for nested types). Defaults to "".

Raises:
  • TypeError – If the value doesn’t match the expected type.

  • ValueError – If the value doesn’t match a Literal type.

CodeVideoRenderer.utils.typeChecker(func: Callable[[P], R]) Callable[[P], R][source]

Decorator to check types of function arguments and return value.

Parameters:

func (Callable) – The function to decorate.

Returns:

The wrapped function with type checking.

Return type:

Callable

CodeVideoRenderer.utils.addGlowEffect(input_path: str | PathLike[str], output_path: str | PathLike[str], output: bool) None[source]

Add a glow effect to a video.

Parameters:
  • input_path (StrPath) – Path to the input video file.

  • output_path (StrPath) – Path to save the output video file.

  • output (bool) – Whether to display progress bars.

Returns:

None

CodeVideoRenderer.utils.findSpacePositions(string: str) list[list[int]][source]

Find the 2D positions of all non-leading, non-trailing spaces in a string. Each position is represented as a list [row_index, column_index].

Parameters:

string (str) – A string.

Returns:

A list of 2D positions of all non-leading, non-trailing spaces. Each position is represented as a list [row_index, column_index].

Return type:

list[list[int]]

CodeVideoRenderer.utils.findEmptyLinePositions(string: str) list[int][source]

Find the line indices of all empty lines in a string.

Parameters:

string (str) – A string.

Returns:

A list of line indices of all empty lines.

Return type:

list[int]

CodeVideoRenderer.utils.replaceMiddleSpacesWithOccupyCharacter(string: str) str[source]

Replace all non-leading, non-trailing spaces in the input string with OCCUPY_CHARACTER. Retain leading and trailing spaces.

Parameters:

string (str) – Original string.

Returns:

Processed string with middle spaces replaced by OCCUPY_CHARACTER.

Return type:

str

class CodeVideoRenderer.utils.DefaultProgressBar(*args: Any, **kwargs: Any)[source]

Default progress bar.

class CodeVideoRenderer.utils.RichProgressBarLogger(*args: Any, **kwargs: Any)[source]

A progress logger that uses Rich to display progress bars.

new_tqdm_bar(bar)[source]

Create a Rich progress bar task for the given bar.

close_tqdm_bar(bar)[source]

Close the Rich progress bar task for the given bar.

bars_callback(bar, attr, value, old_value)[source]

Update the Rich progress bar task based on the attribute change.

stop()[source]

Stop the Rich progress bar.