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
-
static
-
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 aKeyboardHandler
,MouseHandler
and anAuxiliaryDisplay
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 helpF2
..F10
for switching displaysF11
to toggle fullscreen modeF12
to take a screenshotESCAPE
to shutdown the application
Parameters: - displays (
List
[Display
]) – List of up to 9 displays - auxiliary_display (
Optional
[AuxiliaryDisplay
]) – - keyboard_handler (
Optional
[KeyboardHandler
]) – - mouse_handler (
Optional
[MouseHandler
]) – - config (
Optional
[DisplayConfiguration
]) – Can be generated viaMainWindowConfigurator
- fps (
int
) – Target frame rate (frames per second)
-
classmethod
configurator
()¶ Convenience method to create a matching configurator
Return type: MainWindowConfigurator
- The