pyggui.gui package¶
Submodules¶
pyggui.gui.animation module¶
Module for animation classes that hold image lists and handle different types of animations.
- class pyggui.gui.animation.Animator(images: List[pygame.surface.Surface], animation_velocity: Union[int, float] = 1, loop: bool = False)[source]¶
Bases:
objectClass for handling animations in lists of images, can either loop indefinitely or loop once and stay at the last image. The get method should be called for fetching current image. That method also updates the state of the animator object, so it should be called even if the image wont be used.
- property at_end¶
- get() pygame.surface.Surface[source]¶
Method returns current image to display, also updates images index so this method should be called in a loop.
- Returns
pygame.surface.Surface – Current image in animation loop.
- property index¶
- set_animation(animation_type: str) None[source]¶
Method sets the current animation type of the object. Options:
normal: Only loops once over the images and stays at the last image. loop: Loops indefinitely.
- Parameters
animation_type (str) – Animation type between the currently implemented: normal, loop
pyggui.gui.bar module¶
Module for Bar classes.
- class pyggui.gui.bar.DefaultProgressBar(position: List[int] = [0, 0], size: Tuple[int, int] = (1, 1), visible: bool = True, selected: bool = False, color: Tuple[int, int, int] = (255, 255, 255), line_width: int = 3)[source]¶
Bases:
pyggui.gui.item.StaticItemDefault progress bar is a horizontal rectangle that gets filled up based on progress. The default color is white but can be changed by modifying the color attribute. update_progress(float) method should be used to update the fill of bar.
- property progress¶
- class pyggui.gui.bar.ProgressBar(*args, **kwargs)[source]¶
Bases:
pyggui.gui.item.StaticItemProgress bar is used for displaying progress. Passing a directory path in the argument directory_path will let you create a custom imaged progress bar, an DefaultProgressBar gets returned otherwise, for wich size should be passed.
pyggui.gui.container module¶
Module containing container classes used for storing and moving grouped items.
- class pyggui.gui.container.Container(*args, **kwargs)[source]¶
Bases:
objectContainer objects can store items in positions relative to self. If items get added to a container object, those items can all be moved together by moving the container object.
Passing the argument resizable as True will create a Resizable container, otherwise a StaticContainer where it and its items can’t be resized.
- class pyggui.gui.container.ResizableContainer(position: List[int] = [0, 0], size: Tuple[int, int] = (100, 100), visible: bool = False, selected: bool = False, resizable: bool = False)[source]¶
Bases:
pyggui.gui.item.ResizableItemContainer object can be resized along with every item contained in it. Because of this only re-sizable items can be added.
- add_item(item: any, relative_position: Tuple[int, int]) int[source]¶
Method adds item in a position relative to self upper left corner. Item will be moved along with the container object.
- Parameters
item (any) – Item to add.
relative_position (Tuple[int, int]) – Position of added item in container based on upper left corner.
- Returns
int – Position (index) in items list of added item.
- change_item_at_index(index: int, item: any) None[source]¶
Method changes item at index inside the items list. Position of item inside container stays the same.
- Parameters
index (int) – Index in items list to change item.
item (any) – Item to add.
- class pyggui.gui.container.StaticContainer(position: List[int] = [0, 0], size: Tuple[int, int] = (100, 100), visible: bool = False, selected: bool = False, resizable: bool = False)[source]¶
Bases:
pyggui.gui.item.StaticItemContainer object for holding items inside, items are moved with the container. Static container can not be resized but can still be moved.
- add_item(item: any, relative_position: Tuple[int, int]) int[source]¶
Method adds item in a position relative to self upper left corner. Item will be moved along with the container object.
- Parameters
item (any) – Item to add.
relative_position (Tuple[int, int]) – Position of added item in container based on upper left corner.
- Returns
int – Position (index) in items list of added item.
pyggui.gui.event_handler module¶
Module containing event handler classes.
- class pyggui.gui.event_handler.EventHandler(types: Union[int, List[int]], handlers: Union[Callable, List[Callable]])[source]¶
Bases:
objectClass stores event types and handlers for those events. Once one of the event types appears in the input event loop all of its handlers get called. Event types are Pygame specific event types.
- property handlers¶
- property types¶
pyggui.gui.grid module¶
Module containing grid definition and every addition needed for it.
- class pyggui.gui.grid.Cell(grid: pyggui.gui.grid.Grid, position_in_grid: Tuple, position: List[int] = [0, 0], size: Tuple[int, int] = (1, 1))[source]¶
Bases:
pyggui.gui.item.StaticItemClass for representing a single rectangle in the grid that is placed in the i, j position and has i-th rows height, j-th columns height. Items can be added to it, aligned and padded.
- add_item(item: any, align: Optional[str] = None, padding: Optional[str] = None) None[source]¶
Method adds item to cell, aligns and pads it base on passed values.
- Parameters
item (any) – Item to add.
align (str) – String defining alignment type. Multiple alignments are separated by a space character. Example: alignment = “centre top” # Centre should always be first.
padding (str) – String defining padding of item. Multiple alignments are separated by a comma. Value is passed next to the alignment position as an integer value. Example: padding = “top 5, left 3” # 5px from top 3px from bottom
- property padding¶
- class pyggui.gui.grid.Grid(position: List[int] = [0, 0], rows: int = 1, columns: int = 1, row_sizes: Optional[Union[List[int], List[float]]] = None, column_sizes: Optional[Union[List[int], List[float]]] = None, size: Optional[Tuple[int, int]] = None, visible: bool = False, selected: bool = False)[source]¶
Bases:
pyggui.gui.item.StaticItem- add_item(item: any, row: Optional[int] = None, column: Optional[int] = None, align: Optional[str] = None, padding: Optional[str] = None) None[source]¶
Method adds item to the grid in the specified cell at position row, column. Optional alignments, and paddings can be defined relative to the cell where the item is being added.
- Parameters
item (any) – Item to add.
row (int) – Row in grid to add the item in. Starting at 0.
column (int) – Column in grid to add the item in. Starting at 0.
align (str) – Representing one or more alignment types. These include: centre, top, bottom, left, right. Centre should be defined first. Separate alignments using a space ” “.
padding (str) – Representing one or more paddings of each side of the cell. Multiple can be passed by separating them with commas “,”, each padding should be passed as “side px”. Where sides include: top, bottom, left, right. Px represents an integer number of pixels to pad. Ex.: padding = “top 5, left 10”
- property columns¶
- property rows¶
- class pyggui.gui.grid.Row(grid: pyggui.gui.grid.Grid, data: Optional[List] = None)[source]¶
Bases:
objectSingle row in Grid, is only used for grabbing items using indexing with []. Row contains cells that are in that row in the grid.
- pyggui.gui.grid.make_grid_line(line: List[Union[float, int]], total_size: int, number_of_items: int) List[int][source]¶
Used internally by Grid for constructing cell sizes for each column, row. Function creates a list representing sizes of cells (in px) in that line (either row or column). Line can be passed as a list of decimals (representing percentage of total size) or integers (representing sizes). Line can also include less elements than there are rows/columns, elements then get added/removed accordingly.
- Parameters
line (List[Union[float, int]]) – List of either integers or floats representing different size format (px or %).
total_size (int) – Total size (height of all rows or width of all columns), can be either 1 (if %) or an integer representing size in px.
number_of_items (int) – Expected number of items in line.
pyggui.gui.image module¶
Module for classes handling images.
- class pyggui.gui.image.Image(*args, **kwargs)[source]¶
Bases:
objectClass for creating image objects and place them on screen or page. Argument ‘transparent’ decides how the passed image (if passed as a path) will be loaded (as a transparent surface
or not).
- Class can return either a ResizableImage object or a StaticImage object based on the passed argument ‘resizable’,
which defaults to false.
- class pyggui.gui.image.ResizableImage(image: Union[str, pygame.Surface], transparent: bool = False, position: List[int] = [0, 0], visible: bool = True, selected: bool = False, resizable: bool = True)[source]¶
Bases:
pyggui.gui.item.ResizableItemClass for handling a single static image that can be moved and re-sized. Inherits from ResizableItem.
- class pyggui.gui.image.StaticImage(image: Union[str, pygame.Surface], transparent: bool = False, position: List[int] = [0, 0], visible: bool = True, selected: bool = False, resizable: bool = False)[source]¶
Bases:
pyggui.gui.item.StaticItemClass for handling a single static image. This image can be moved but not resized, refer to ResizableImage for resizable images or pass ‘resizable=True’ to Image class constructor. inherits from StaticItem.
- pyggui.gui.image.fetch_image(image: Union[str, pygame.Surface], transparent: bool = False) pygame.Surface[source]¶
Function loads one image and returns it as a pygame.Surface object.
- Parameters
image (Union[str, pygame.Surface]) – Either a path to the image (preferably relative path), or an already loaded image as a pygame.Surface object.
transparent (bool) – If image should be loaded as transparent. If image is passed as a Surface object it is set as the default False.
- Returns
pygame.Surface – Image loaded into a surface,
pyggui.gui.item module¶
Module containing Item base classes.
- class pyggui.gui.item.BaseItem(position: List[int], size: Tuple[int, int], visible: bool = True, selected: bool = False)[source]¶
Bases:
objectBase class for all items.
- add_item(item: any, relative_position: Optional[Union[Tuple[int, int], List[int]]] = None) None[source]¶
Method adds item to self. If relative position is not specified, item will be added based on its position relative to this items position. If relative position is specified however, item will be added into that position relative to this items position.
- Parameters
item (any) – Item to add to self.
relative_position (Union[Tuple[int, int], List[int]]) – Optional; [x, y] value of added items position relative to this items upper left corner.
- property height: int¶
- move(change: Union[Tuple[int, int], List[int]]) None[source]¶
Method moves item by specified change along with every attached item.
- Parameters
change (Union[Tuple[int, int], List[int]]) – dx, dy to move item in each direction.
- move_to(point: Union[List[int], Tuple[int, int]]) None[source]¶
Method moves item to specified position along with every attached item.
- Parameters
point (Union[List[int], Tuple[int, int]]) – x, y point to move item to on screen or page.
- property position: List[int]¶
- property size: Tuple[int, int]¶
- update_items_positions() None[source]¶
Method updates every attached items position relative to self.
- property width: int¶
- property x: int¶
- property y: int¶
- class pyggui.gui.item.Item(controller: Controller, position: List[int] = [0, 0], size: Tuple[int, int] = (1, 1), on_click: Callable = None, movable: bool = False, visible: bool = True)[source]¶
Bases:
pyggui.gui.item.BaseItemClass for items that are interactive but dependant on controller object. Items have hovered property which is set to true once the item is hovered by mouse. Have on_click method to trigger an action once the item is clicked.
- add_on_click(on_click: Union[Callable, List[Callable], Tuple[Callable]]) None[source]¶
Method adds callable function or list of functions to self. These functions get executed once the item is clicked.
- Parameters
on_click (Union[Callable, List[Callable], Tuple[Callable]]) – Either a callable function or a list / tuple
of callable functions.
- debounce_time() bool[source]¶
Method checks if enough(debounce_interval) time passed from the time of the last click. Used for eliminating double clicks.
- Returns
bool – If debounce_interval time has passed or not
- property mouse_clicked¶
- class pyggui.gui.item.ResizableItem(position: List[int] = [0, 0], size: Tuple[int, int] = (1, 1), visible: bool = True, selected: bool = False)[source]¶
Bases:
pyggui.gui.item.BaseItemBase class for defining static items that have actions performed on them and are able to re-size. The main difference between the Item class is that it can be resized, the lack of on_hover / on_click methods and that this class does not need the controller to be passed. Items can not be attached to this class.
- resize(factor: float) None[source]¶
Method will re-size item based on a factor passed as argument. If class gets inherited method should first get called with super function.
- Parameters
factor (float) – Resize factor, 1 is the same size, 0.5 is half size and 2 is double size
- property scaled_height: int¶
Property returns objects scaled height. If not resized it is the same as its normal height.
- property scaled_position: List[int]¶
Property returns scaled position when item is re-sized, keeping original position intact.
- property scaled_width: int¶
Property returns objects scaled width. If not resized it is the same as its normal width.
- property scaled_x: int¶
Property returns scaled x position when item is re-sized, keeping original position intact.
- property scaled_y: int¶
Property returns scaled y position when item is re-sized, keeping original position intact.
- class pyggui.gui.item.StaticItem(position: List[int] = [0, 0], size: Tuple[int, int] = (1, 1), visible: bool = True, selected: bool = False)[source]¶
Bases:
pyggui.gui.item.BaseItemClass for static items that are not intractable (can’t be clicked and do not have hovered property).
pyggui.gui.page module¶
Module containing base classes for pages.
- class pyggui.gui.page.Page(controller: Controller)[source]¶
Bases:
objectMain class other pages should inherit from. Page object functions similarly to an Item, it can be moved and resized.
- add_event_handler(event_handler: pyggui.gui.event_handler.EventHandler) None[source]¶
Method adds a page-wide EventHandler object. This event handler is not triggered after the page has been redirected from i.e. with the redirect_to or go_back methods of Controller.
- Parameters
event_handler (EventHandler) – EventHandler object to add.
- add_event_type_handler(event_type: int, handler: Callable)[source]¶
Method adds a single page-wide event type handler. The handler callable function gets triggered once the event_type appears in the main input loop. This event type handler is not triggered after the page has been redirected from i.e. with the redirect_to or go_back methods of Controller.
- 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_item(item: any) None[source]¶
Method adds item to page. Items position should be set beforehand.
- Parameters
item (any) – Item to add to page. Item must have the update and draw methods.
- property display_size¶
- property height: int¶
- on_appearance() None[source]¶
Method gets called once the page been has brought up again. Safe for overriding.
- on_exit() None[source]¶
Method gets called once the page has been redirected from. Safe for overriding.
- property position: List[int]¶
- property size: Tuple[int, int]¶
- update() None[source]¶
Method updates every item added to page. Once the item is added, page no longer controlls its position but it has its original position stored.
- property width: int¶
- property x: int¶
- property y: int¶
pyggui.gui.text module¶
Module for text based items.
- class pyggui.gui.text.Text(position: List[int] = [0, 0], value: str = 'Text', font: Optional[str] = None, font_size: int = 21, color: Tuple[int, int, int] = (255, 255, 255))[source]¶
Bases:
pyggui.gui.item.StaticItemClass for displaying text on screen. You can pass own font file or use one of the System specific ones by passing a font name without any . / characters. Text can not be resized after initialization, for that use the ResizableText class TODO(Add).
Note: If you change the value of the text the render method should be called to re-render the changed text.
- render() None[source]¶
TODO: Add value property and setter to auto-update text Method re-renders the text surface, method should be called once the text value has changed.
- property value¶
Module contents¶
This imports all classes defined in the gui package. We exclude classes starting with _ as those are considered private.