# moderngl_window

General helper functions aiding in the boostrapping of this library.

class moderngl_window.ContextRefs

  Namespace for window/context references

  CONTEXT: Context | None = None
  WINDOW: BaseWindow | None = None

moderngl_window.activate_context(window: BaseWindow | None = None, ctx: Context | None = None) → None

  Register the active window and context. If only a window is supplied the context is taken from the window. Only a context can also be passed in.

  Keyword Arguments:

    - window (window) – The window to activate

    - ctx (moderngl.Context) – The moderngl context to activate

moderngl_window.create_parser() → ArgumentParser

  Create an argparser parsing the standard arguments for WindowConfig

moderngl_window.create_window_config_instance(config_cls: type[WindowConfig], timer: Timer | None = None, args: Any = None) → WindowConfig

  Create and initialize a instance of a WindowConfig class. Quite a bit of boilerplate is required to create a WindowConfig instance and this function aims to simplify that.

  Parameters:

    window_config – The WindowConfig class to create an instance of

  Keyword Arguments:

    kwargs – Arguments to pass to the WindowConfig constructor

  Returns:

    An instance of the WindowConfig class

moderngl_window.create_window_from_settings() → BaseWindow

  Creates a window using configured values in `moderngl_window.conf.Settings.WINDOW`. This will also activate the window/context.

  Returns:

    The Window instance

moderngl_window.ctx() → Context

  Obtain the active context

moderngl_window.find_window_classes() → list[str]

  Find available window packages :returns: A list of available window packages

moderngl_window.get_local_window_cls(window: str | None = None) → type[BaseWindow]

  Attempt to obtain a window class in the moderngl_window package using short window names such as `pyglet` or `glfw`.

  Parameters:

    window (str) – Name of the window

  Returns:

    A reference to the requested window class. Raises exception if not found.

moderngl_window.get_window_cls(window: str = '') → type[BaseWindow]

  Attempt to obtain a window class using the full dotted python path. This can be used to import custom or modified window classes.

  Parameters:

    window (str) – Name of the window

  Returns:

    A reference to the requested window class. Raises exception if not found.

moderngl_window.parse_args(args: Any | None = None, parser: ArgumentParser | None = None) → Namespace

  Parse arguments from sys.argv

  Passing in your own argparser can be user to extend the parser.

  Keyword Arguments:

    - args – override for sys.argv

    - parser – Supply your own argparser instance

moderngl_window.run_window_config(config_cls: type[WindowConfig], timer: Timer | None = None, args: Any = None) → None

  Run an WindowConfig entering a blocking main loop

  Parameters:

    config_cls – The WindowConfig class to render

  Keyword Arguments:

    - timer – A custom timer instance

    - args – Override sys.args

moderngl_window.run_window_config_instance(config: WindowConfig) → None

  Run an WindowConfig instance entering a blocking main loop.

  Parameters:

    window_config – The WindowConfig instance

moderngl_window.setup_basic_logging(level: int) → None

  Set up basic logging

  Parameters:

    level (int) – The log level

moderngl_window.valid_bool(value: str | None) → bool | None

  Validator for bool values

moderngl_window.valid_window_size(value: str) → tuple[int, int]

  Validator for window size parameter.

  Valid format is “[int]x[int]”. For example “1920x1080”.

moderngl_window.valid_window_size_multiplier(value: str) → float

  Validates window size multiplier

  Must be an integer or float greater than 0

moderngl_window.window() → BaseWindow

  Obtain the active window