async2v.components.pygame.main module

Pygame main window

To use any of the pygame components & utilities, a pygame MainWindow component needs to be part of the application. It is the central container for displays, keyboard & mouse handling.

It comes with a configurator to set the desired resolution and initial fullscreen mode via command line.

Example for integrating the main window into the application:

class Launcher(ApplicationLauncher):

    def __init__(self):
        super().__init__()
        self.add_configurator(MyKeyboardHandler.configurator())
        self.add_configurator(MainWindow.configurator())

    def register_application_components(self, args, app: Application):
        displays = [
            # add displays here
            OpenCvDebugDisplay(),
        ]
        main_window_config = MainWindow.configurator().config_from_args(args)
        main = MainWindow(displays, config=main_window_config)
        # add more components here
        app.register(main)

Summary

Classes:

DisplayConfiguration Display configuration for MainWindow
MainWindow Pygame main window component
MainWindowConfigurator Configurator for MainWindow

Reference

class DisplayConfiguration(resolution, fullscreen)

Bases: object

Display configuration for MainWindow

class MainWindowConfigurator

Bases: async2v.cli.Configurator

Configurator for MainWindow

static config_from_args(args)

Get configuration from argparse output

Return type:DisplayConfiguration
class MainWindow(displays, auxiliary_display=None, keyboard_handler=None, mouse_handler=None, config=None, fps=60)

Bases: async2v.components.base.IteratingComponent, async2v.components.base.ContainerMixin

Pygame main window component

Holds up to 9 pygame Display subcomponents. Optionally a KeyboardHandler, MouseHandler and an AuxiliaryDisplay can be specified.

All display & input logic should be in those subcomponents, usually there is no need to subclass MainWindow.

The MainWindow comes with a few predefined key bindings:
  • F1 to toggle on screen help
  • F2 .. F10 for switching displays
  • F11 to toggle fullscreen mode
  • F12 to take a screenshot
  • ESCAPE to shutdown the application
Parameters:
classmethod configurator()

Convenience method to create a matching configurator

Return type:MainWindowConfigurator