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:
objectMain 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
- property input¶
- 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.AssetsErrorWhen an asset is being accessed but the directory or file does not exist.
- exception pyggui.exceptions.AssetsDirectoryNotDefinedError(message=None)[source]¶
Bases:
pyggui.exceptions.AssetsErrorAssets 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:
ExceptionBase exception for Assets related errors.
- exception pyggui.exceptions.ControllerError(message=None)[source]¶
Bases:
ExceptionBase exception for controller related errors.
- exception pyggui.exceptions.ItemError(message=None)[source]¶
Bases:
ExceptionBase exception for item related errors.
- exception pyggui.exceptions.NotResizableError(message=None)[source]¶
Bases:
pyggui.exceptions.ItemErrorItem can not be resized error.
- exception pyggui.exceptions.RedirectionError(message=None)[source]¶
Bases:
pyggui.exceptions.ControllerErrorPage 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:
objectMain 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
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:
objectMain 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.
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.