pyxora.utils.engine

 1from pyxora import debug,version,pygame_version,sdl_version,python_version
 2
 3from traceback import extract_tb
 4import os
 5import sys
 6
 7import pygame
 8
 9__all__ = ["print_versions","error","warning","quit"]
10
11def print_versions() -> None:
12    """Print the versions for the engine library and its dependencies."""
13    print("-"*50)
14    print("pyxora:", version)
15    print("Dependencies: ")
16    print("\tRendering: pygame-ce", pygame_version, "| SDL", sdl_version)
17    # print("\tPhysics: pymunk", pymunk_version)
18    print("Python:", python_version)
19    print("-"*50)
20
21def error(err: Exception) -> None:
22    """
23    Handles exceptions by showing a popup error box or printing if pyxora.debug is True.
24
25    Args:
26        err (Exception): The exception instance that was raised.
27    """
28    error_type = type(err).__name__
29    error_message = str(err)
30    traceback_list = extract_tb(err.__traceback__)
31
32    error_details = [
33        f"File: {os.path.basename(tb.filename)}, Line: {tb.lineno}"
34        for tb in traceback_list
35    ]
36    formatted_traceback = (
37        "\n".join(error_details) if len(error_details) <= 1
38        else "\n" + "\n".join(error_details)
39    )
40
41    nice_error_message = (
42        f"Type: {error_type}\n"
43        f"Message: {error_message}\n"
44        f"Traceback: {formatted_traceback}"
45    )
46
47    if debug:
48        print(
49            "-----------------------------------\n"
50            "Error: An unexpected error occurred\n"
51            f"{nice_error_message}\n"
52            "-----------------------------------"
53        )
54    else:
55        pygame.display.message_box(
56            "An unexpected error occurred",
57            nice_error_message,
58            "error"
59        )
60
61
62def warning(message: str) -> None:
63    """
64    Prints a warning message to the console.
65
66    Args:
67        message (str): The warning message to display.
68    """
69    print(f"Warning: {message}")
70
71# def log(): ...
72
73
74def quit() -> None:
75    """
76    Exit the application cleanly.
77
78    Calls `sys.exit()` to terminate the process.
79    """
80    sys.exit()
def error(err: Exception) -> None:
22def error(err: Exception) -> None:
23    """
24    Handles exceptions by showing a popup error box or printing if pyxora.debug is True.
25
26    Args:
27        err (Exception): The exception instance that was raised.
28    """
29    error_type = type(err).__name__
30    error_message = str(err)
31    traceback_list = extract_tb(err.__traceback__)
32
33    error_details = [
34        f"File: {os.path.basename(tb.filename)}, Line: {tb.lineno}"
35        for tb in traceback_list
36    ]
37    formatted_traceback = (
38        "\n".join(error_details) if len(error_details) <= 1
39        else "\n" + "\n".join(error_details)
40    )
41
42    nice_error_message = (
43        f"Type: {error_type}\n"
44        f"Message: {error_message}\n"
45        f"Traceback: {formatted_traceback}"
46    )
47
48    if debug:
49        print(
50            "-----------------------------------\n"
51            "Error: An unexpected error occurred\n"
52            f"{nice_error_message}\n"
53            "-----------------------------------"
54        )
55    else:
56        pygame.display.message_box(
57            "An unexpected error occurred",
58            nice_error_message,
59            "error"
60        )

Handles exceptions by showing a popup error box or printing if pyxora.debug is True.

Arguments:
  • err (Exception): The exception instance that was raised.
def warning(message: str) -> None:
63def warning(message: str) -> None:
64    """
65    Prints a warning message to the console.
66
67    Args:
68        message (str): The warning message to display.
69    """
70    print(f"Warning: {message}")

Prints a warning message to the console.

Arguments:
  • message (str): The warning message to display.
def quit() -> None:
75def quit() -> None:
76    """
77    Exit the application cleanly.
78
79    Calls `sys.exit()` to terminate the process.
80    """
81    sys.exit()

Exit the application cleanly.

Calls sys.exit() to terminate the process.