API Reference

Logging Module

Logger class

Logging Levels

Logging level constants for the LogNGraph package.

This module defines standard logging levels used throughout the LogNGraph package. The levels follow a hierarchical structure where lower numerical values indicate more verbose logging.

Constants:
TRACE (int): Level 0 - Most detailed information for tracing program execution.
DEBUG (int): Level 1 - Diagnostic information useful for debugging.
INFO (int): Level 2 - General information about program execution.
WARNING (int): Level 3 - Indicates potential issues that don’t prevent execution.
ERROR (int): Level 4 - Errors that affect functionality but allow continued operation.
FATAL (int): Level 5 - Critical errors that prevent further operation.
NONE (int): Level 6 - Special value to disable all logging.

Example

>>> from logngraph.log import get_logger
>>> from logngraph.log.levels import INFO, DEBUG
>>> logger = get_logger(__name__, level=DEBUG)
>>> logger.set_level(INFO)

Note

These levels follow the standard syslog severity levels with the addition of TRACE for ultra-verbose logging and NONE for disabling logs.

logngraph.log.levels.DEBUG = 1

Level 1 - Diagnostic information useful for debugging.

Type:

int

logngraph.log.levels.ERROR = 4

Level 4 - Errors that affect functionality but allow continued operation.

Type:

int

logngraph.log.levels.FATAL = 5

Level 5 - Critical errors that prevent further operation.

Type:

int

logngraph.log.levels.INFO = 2

Level 2 - General information about program execution.

Type:

int

logngraph.log.levels.NONE = 6

Level 6 - Special value to disable all logging.

Type:

int

logngraph.log.levels.TRACE = 0

Level 0 - Most detailed information for tracing program execution.

Type:

int

logngraph.log.levels.WARNING = 3

Level 3 - Indicates potential issues that don’t prevent execution.

Type:

int

Graphics Module

Window Class

class logngraph.graph.Window(title='Window', width=800, height=600, resizable=True)[source]

Bases: object

Parameters:
  • title (str)

  • width (int)

  • height (int)

  • resizable (bool)

__init__(title='Window', width=800, height=600, resizable=True)[source]
Parameters:
  • title (str)

  • width (int)

  • height (int)

  • resizable (bool)

Return type:

None

bind_keydown(key, function, args=None)[source]

Bind given keypress to given function. Function will be called when the key is pressed.

Parameters:
  • key (str) – Key press. Must be a valid pygame key name (e.g., ‘a’, ‘space’, ‘enter’).

  • function (Callable) – Function to call when the key is pressed.

  • args (Iterable[Any]) – Arguments to pass to the function.

Returns:

None

Return type:

None

bind_keyup(key, function, args=None)[source]

Bind given keypress to given function. Function will be called when the key is pressed.

Parameters:
  • key (str) – Key press. Must be a valid pygame key name (e.g., ‘a’, ‘space’, ‘enter’).

  • function (Callable) – Function to call when the key is pressed.

  • args (Iterable[Any]) – Arguments to pass to the function.

Returns:

None

Return type:

None

circle(center, radius, color='#ffffff')[source]

Create circle with center at center and radius=radius.

Parameters:
  • center (tuple[float, float] | Vec2D) – Center position of the circle.

  • radius (float) – Radius of the circle.

  • color – Fill color of the circle.

Returns:

None

Return type:

None

fill(color)[source]

Fill the window with given color.

Parameters:

color (tuple[int, int, int] | str) – Color to fill the window with.

Returns:

None

Return type:

None

handle_events()[source]

Handles event (quit, keypresses, etc.)

Returns:

None

Return type:

None

property height: int
line(start_pos, end_pos, color='#ffffff', width=1)[source]

Draw a line from start_pos to end_pos with width=width and color=color.

Parameters:
  • start_pos (tuple[float, float] | Vec2D) – Starting position of the line.

  • end_pos (tuple[float, float] | Vec2D) – Ending position of the line.

  • color – Color of the line.

  • width (int) – Width of the line.

Returns:

None

Return type:

None

polygon(*args, color='#ffffff')[source]

Draw a polygon with given position arguments.

Parameters:
  • args (float | tuple[float, float] | Vec2D) – x, y pairs of coordinates of the vertices of the polygon. E.g. (0, 0), (15, 60), (123, 624), or 0, 0, 15, 60, 123, 624.

  • color – Fill color of the polygon.

Returns:

None

Return type:

None

rect(left_top, width_height, color='#ffffff')[source]

Draw a rectangle with given width and height and at given coordinates.

Parameters:
  • left_top (tuple[float, float] | Vec2D) – Leftmost top coordinates of the rectangle.

  • width_height (tuple[float, float] | Vec2D) – Width and height of the rectangle.

  • color – Fill color of the rectangle.

Returns:

None

Return type:

None

rotate(angle)[source]
Parameters:

angle (float)

Return type:

None

screenshot(filename)[source]

Save a screenshot of the window to a file.

Parameters:

filename (str) – Path to the file to save the screenshot to.

Returns:

None

Return type:

None

static set_title(title)[source]
Parameters:

title (str)

Return type:

None

stop()[source]

Stops the window.

Returns:

None

Return type:

None

translate(x, y)[source]
Parameters:
  • x (float)

  • y (float)

Return type:

None

update()[source]

Updates the window.

Returns:

None

Return type:

None

property width: int
write(center, text='', color='#ffffff', antialias=True, font='Arial', size=16)[source]

Write given text to the screen.

Parameters:
  • center (tuple[int, int]) – Center position of the text.

  • text (str) – Text to write.

  • color – Color of the text.

  • antialias (bool) – Enable antialiasing of the text.

  • font (Font | str) – Font of the text.

  • size (int) – Font size of the text.

Returns:

None

Return type:

None

Vectors

Vec2D class

class logngraph.vector.Vec2D(x, y)[source]

Bases: object

Parameters:
  • x (float)

  • y (float)

__add__(other)[source]
Parameters:

other (Self)

Return type:

Self

__cmp__(other)[source]
Parameters:

other (Self)

Return type:

bool

__eq__(other)[source]

Return self==value.

Parameters:

other (Self)

Return type:

bool

__getitem__(index)[source]
Parameters:

index (int | str | slice)

__hash__()[source]

Return hash(self).

__iter__()[source]
__mul__(other)[source]
Parameters:

other (float | int | Self)

Return type:

Self

__neg__()[source]
__repr__()[source]

Return repr(self).

__str__()[source]

Return str(self).

__sub__(other)[source]
Parameters:

other (Self)

Return type:

Self

__truediv__(other)[source]
Parameters:

other (float)

copy()[source]
Return type:

Self

cross(other)[source]
Parameters:

other (Self)

Return type:

Self

dist(other)[source]
Parameters:

other (Self)

Return type:

float

limit(max_mag)[source]
Parameters:

max_mag (float | int)

Return type:

Self

mag()[source]
Return type:

float

norm()[source]
Return type:

Self

rotate(degrees, pivot=None)[source]
Parameters:
  • degrees (float)

  • pivot (Self)

Return type:

Self

translate(translation)[source]
Parameters:

translation (Self)

Return type:

Self

Errors

exception logngraph.errors.FeatureNotInstalledError(message)[source]

Bases: Exception

__init__(message)[source]
exception logngraph.errors.InvalidArgsError(message)[source]

Bases: Exception

__init__(message)[source]
exception logngraph.errors.InvalidKeyError(message)[source]

Bases: Exception

__init__(message)[source]