pyggui.helpers package

Submodules

pyggui.helpers.file_handling module

Module for anything related to files

class pyggui.helpers.file_handling.DirectoryReader[source]

Bases: object

Class consisting of static methods for reading directories. Used for fetching sub-directories, all files, the directories structure, etc.

static get_all_directories(dir_path: str) List[Tuple[str, str]][source]

Method finds all sub-directories in the given directory.

Parameters

dir_path (str) – Path to directory to search from

Returns

List[Tuple[str, str]] – List of tuples (directory name, directory path).

static get_all_files(dir_path: str) List[Tuple[str, str]][source]

Method finds all file names and its paths in the given directory.

Parameters

dir_path (str) – Path to directory to search from

Returns

List[Tuple[str, str]] – List of tuples (file name, file path).

static get_structure(dir_path: str) Dict[str, Union[str, List, Dict]][source]

Method goes over the passed directory and creates a special structured dictionary.

Created dictionary follows this rules:
  • For each directory create a sub-dictionary under the directories name as the key,

  • Each file in giver directory is added in a list under ‘files’ key, file gets added as a tuple where

    first value is the files name, second value its relative path based on dir_path.

The above is then run recursively across the directories tree structure.

Example

Passing bottom directory with its relative or absolute path Directory:

button/
  • normal.png

on_click/
  • 01.png

  • 02.png

on_hover/
  • 01.png

Will return dictionary:
{

‘path’: ‘button/’ ‘files’: [(‘normal.png’, ‘button/normal.png’)],

‘on_click’: {

‘path’: ‘button/on_click’ ‘files’: [

(‘01.png’, ‘button/on_click/01.png’), (‘02.png’, ‘button/on_click/02.png’) ]

},

‘on_hover’: {

‘path’: ‘button/on_hover’, ‘files’: [

(‘01.png’, ‘button/on_hover/01.png’)

]

}

}

Parameters

dir_path (str) – Directory path to traverse and create structure from.

Returns

Dict[str, Union[str, List, Dict]] – Structured dictionary.

class pyggui.helpers.file_handling.ImageLoader[source]

Bases: object

static load_folder(folder_path: str) List[pygame.Surface][source]

Method loads all ImageLoader from the folder intro a sprite list.

Parameters

folder_path (str) – Path to folder to load images from

Returns

list[pygame.surface.Surface] – List containing Pygame images loaded as surfaces

static load_image(image_path: str) pygame.Surface[source]

Method loads given path into image.

Parameters

image_path (str) – Path to image to load

Returns

pygame.surface.Surface – Image loaded as a Pygame surface

static load_transparent_folder(folder_path: str) List[pygame.Surface][source]

Method loads all ImageLoader from the folder intro a sprite list.

Parameters

folder_path (str) – Path to folder to load images from

Returns

list[pygame.surface.Surface] – List containing Pygame images loaded as surfaces

static load_transparent_image(image_path: str) pygame.Surface[source]

Method loads given path into transparent image.

Parameters

image_path (str) – Path to image to load

Returns

pygame.surface.Surface – Image loaded as a Pygame surface

class pyggui.helpers.file_handling.Json[source]

Bases: object

Class for loading, writing and updating data in json files. All json files must contain dictionaries as the main scope object.

static load(path: str) Union[Dict, List][source]

Method loads a single json file, returning its contents.

Parameters

path (str) – Path to Json file.

Returns

Union[Dict, List] – Content of the Json file

static save(path: str, data: Dict) None[source]

Method saves data into a json file specified by passed path.

Parameters
  • path (str) – Path to Json file to save data to.

  • data (Dict) – Dictionary to save in the json file.

static update(path: str, data: Dict) Dict[source]

Method will update the dictionary with data and return the updated dict.

Parameters
  • path (str) – Path to Json file.

  • data (Dict) – Dictionary of key-value pairs to update in the json file

Returns

Dict – Updated dictionary.

pyggui.helpers.helpers module

Module containing various helper functions that don’t belong in specific files or directories. Functions and or objects should be written in pure Python.

pyggui.helpers.helpers.check_callable_arguments(func: Callable, *args) Callable[source]

Function checks that the passed callable func accepts arguments passed through args.

Parameters
  • func () – Callable function to perform check on.

  • *args () – Arguments passed to check presence in passed function.

Returns

Callable – Passed function check passed, otherwise error gets raised.

pyggui.helpers.helpers.create_callable(func: Callable, *args, **kwargs) Callable[source]

Function creates a callable function where the called function gets passed as an argument along with its args and kwargs.

Parameters
  • func (Callable) – Function to be called

  • *args (any) – Args passed to passed function

  • **kwargs (any) – Kwargs passed to passed function

Returns

Callable – Function that executes passed function when called.

pyggui.helpers.helpers.create_object_repr(instance: any) str[source]

Function creates an object representation string by reading its class name and all attributes. Formatted: ClassName(attr1=val1, attr2=val2, … , attrN=valN)

Parameters

instance (any) – Object instance.

Returns

str – Representation of object.

pyggui.helpers.stack module

Module containing Abstract Data Type Stack implementation.

class pyggui.helpers.stack.Stack(initial_data: Optional[iter] = None)[source]

Bases: object

Abstract Data Type Stack implementation.

empty() bool[source]

Method checks if stack is empty.

Returns

bool – If empty

peak() any[source]

Method returns the top element of the stack. Does not change the stack.

Returns

any – Element on top of stack.

pop() None[source]

Method removes the top element from the stack.

push(element) None[source]

Method adds element to the top of stack.

Parameters

element (any) – Element to add.

take() any[source]

Method returns the top element from the stack while also removing it.

Returns

any – Element on top of stack.

Module contents

Import only public classes and functions.