pyggui package

Subpackages

Submodules

pyggui.controller module

Module containing the controller class.

Controller class object acts as an intermediate between game wide objects, used for page redirection, game pausing, …

class pyggui.controller.Controller(game: Game)[source]

Bases: object

Main object throughout the game. Mediator between game object and everything else. Contains page_stack attribute which is a Stack, containing visited pages.

add_event_handler(event_handler: EventHandler) None[source]

Method adds a game-wide EventHandler object.

Parameters

event_handler (EventHandler) – EventHandler object to add.

add_event_type_handler(event_type: int, handler: Callable)[source]

Method adds a single game-wide event type handler. The handler callable function gets triggered once the event_type appears in the main input loop.

Parameters
  • event_type (int) – Pygame event type.

  • handler (Callable) – Callable function to get called once the event type appears in the main input loop.

add_overlay_item(item: any, name: Optional[str] = None)[source]

Method adds item to the overlay page while also adding it to the overlay items dictionary.

Parameters
  • item (any) – Item to add.

  • name (str) – Name of item, item will get added under this name into the overlay items dictionary.

property current_page: any

Current page on top of the page stack.

Returns

any – Page

property display
property display_size
property dt: float

Difference in time (milliseconds) between current frame and previous frame.

Returns

float – Milliseconds

property dt_s: float

Difference in time (seconds) between current frame and previous frame.

Returns

float – Seconds

go_back() None[source]

Method goes back one page in the page stack.

property input
pause_game() None[source]

Method pauses and un-pauses game.

property paused: bool

If game is currently paused.

Returns

bool – If paused

redirect_to_page(to_page: str, *args, **kwargs) None[source]

Method redirects to page defined as a string. Args and Kwargs are passed to page class initialization. Error gets displayed if page does not exist. TODO: Make custom error

Parameters
  • to_page (str) – Page to redirect to, has to be defined in the pages dictionary.

  • *args (any) – Get passed to pages class initialization.

  • **kwargs (any) – Get passed to pages class initialization.

property single_page: bool

Property for fetching if page stack currently only contains one page. Useful for back buttons.

Returns

bool – True if only one page is currently inside the page stack.

pyggui.exceptions module

Module containing exceptions.

exception pyggui.exceptions.AssetDoesNotExistError(message=None)[source]

Bases: pyggui.exceptions.AssetsError

When an asset is being accessed but the directory or file does not exist.

exception pyggui.exceptions.AssetsDirectoryNotDefinedError(message=None)[source]

Bases: pyggui.exceptions.AssetsError

Assets directory not defined error. When assets are being accessed by the Assets object, but no direcctory was defined.

exception pyggui.exceptions.AssetsError(message=None)[source]

Bases: Exception

Base exception for Assets related errors.

exception pyggui.exceptions.ControllerError(message=None)[source]

Bases: Exception

Base exception for controller related errors.

exception pyggui.exceptions.ItemError(message=None)[source]

Bases: Exception

Base exception for item related errors.

exception pyggui.exceptions.NotResizableError(message=None)[source]

Bases: pyggui.exceptions.ItemError

Item can not be resized error.

exception pyggui.exceptions.RedirectionError(message=None)[source]

Bases: pyggui.exceptions.ControllerError

Page redirection error.

pyggui.input module

Module containing the input class which updates and handles keyboard / mouse input.

class pyggui.input.Input(game: Game)[source]

Bases: object

Main class for handling keyboard and mouse input. TODO: Update this mess

add_event_handler(event_handler: pyggui.gui.event_handler.EventHandler) None[source]

Method adds event handler object to self, its event types are added to the event types dictionary, its handlers get triggered once the type appears in the main input loop.

Parameters

event_handler (EventHandler) – EventHandler object to add.

add_event_type_handler(event_type: int, handler: Callable) None[source]

Method adds a single event type handler. The handler will get called once the event_type appears in the input main loop.

Parameters
  • event_type (int) – Pygame event type integer number

  • handler (Callable) – Callable function to get called once the event type appears in the input main loop.

property mouse_pressed: bool

If mouse was clicked on current frame.

Returns

bool – If clicked

property previous_mouse_pressed: bool

If mouse was pressed on previous frame.

Returns

bool – If pressed

remove_event_handler(event_handler: pyggui.gui.event_handler.EventHandler) None[source]

Method removes passed EventHandler from self.

Parameters

event_handler (EventHandler) – EventHandler object to remove

remove_event_handlers(event_handlers: List[pyggui.gui.event_handler.EventHandler]) None[source]

Method removes all passed event handler objects from self. EventHandlers therefor wont be triggered anymore.

Parameters

event_handlers (List[EventHandler]) – List of EventHandler objects to remove

update() bool[source]

Main loop for going over Pygame events. Loop goes over user added events.

Returns

bool – False if game was quit, True otherwise

pyggui.input.get_key_pressed_dict() dict[source]

Method returns a dictionary of currently pressed keys (on current frame). # TODO: Sort this out, make pretty :returns: dict – Dictionary containing button states.

pyggui.main module

Module containing main Game class

class pyggui.main.Game(display_size: Tuple[int, int] = (720, 360), page_directory: Optional[str] = None, entry_page: str = '_WelcomePage', assets_directory: Optional[str] = None, fps: int = 0, display: Optional[pygame.Surface] = None)[source]

Bases: object

Main class for game, holds every game wide property, setting and the main run loop.

property display
display_resize_handler(event) None[source]

Handler updates the display and its size once the display window has been re-sized.

property display_size
property dt: float

Difference in time (milliseconds) between current frame and previous frame.

property dt_s: float

Difference in time (seconds) between current frame and previous frame.

property fps: float

Current FPS the game is running at.

run() None[source]

Run main game loop. Will update Window, Input and grab time passed from previous frame. Loop ends if Input.update returns False i.e. a quit event appeared.

pyggui.window module

Module for the Window class which handles everything related to window drawing and updating. Game wide objects and settings should be set here.

class pyggui.window.Window(game: Game)[source]

Bases: object

Main class for handling everything window related.

update() None[source]

Method updates and draws the current page while also updating the screen.

Module contents