pic_scanner.gui.models.element_bases.button.factories

Attributes

PARENT_LOGGER

MOD_LOGGER

Classes

ButtonSchematic

A metaclass to enhance classes with logging capabilities. Classes that inherit from

GUIElementKeyFactory

A factory class to create GUIElementKey objects with predefined configurations.

ButtonFactory

A class to create ButtonSchematic instances.

Module Contents

class pic_scanner.gui.models.element_bases.button.factories.ButtonSchematic(text: str, auto_build=False, key: str = None, create_disabled=False, create_hidden=False, skip_enforcing_unique_keys=False, key_factory: pic_scanner.gui.models.element_bases.element_key.factories.GUIElementKeyFactory = None, **kwargs)

Bases: pic_scanner.log_engine.Loggable

A metaclass to enhance classes with logging capabilities. Classes that inherit from ‘Loggable’ can instantly access a logger without manually setting it up. This logger is derived from a parent logger, ensuring consistent logging behavior and hierarchy.

Parameters:
- log_device

The logger device associated with the instance of the class.

instances
built_instances
DEFAULT_SUFFIX = 'button'
suffix
classmethod has_key(key: str, case_sensitive=False, return_instance=False) bool | ButtonSchematic | None

Checks if the class instances dictionary contains the provided key with optional case sensitivity and instance return.

Parameters:
  • key (str) – The key to check in the ButtonSchematic.instances dictionary.

  • case_sensitive (bool) – Whether the key comparison should be case-sensitive. Default is False.

  • return_instance (bool) – Whether to return the instance corresponding to the key. Default is False.

Returns:

  • If return_instance is False: True if the key is present in the instances dictionary, False otherwise.

  • If return_instance is True: The instance corresponding to the key, or None if the key is not found.

Return type:

Union[bool, ‘ButtonSchematic’, None]

Examples

>>> ButtonSchematic.has_key('MY_BUTTON')
False
>>> ButtonSchematic.has_key('MY_BUTTON', case_sensitive=True)
True
>>> ButtonSchematic.has_key('MY_BUTTON', return_instance=True)
None
>>> ButtonSchematic.has_key('MY_BUTTON', case_sensitive=True, return_instance=True)
<ButtonSchematic object at 0x000001>
classmethod get_instance(key: str, default=None, case_sensitive=False) 'ButtonSchematic' or None

Returns an instance from the class instances dictionary based on the provided key.

Parameters:
  • key (str) – The key to look up in the ButtonSchematic.instances dictionary.

  • default – The default value to return if the key is not found. Default is None.

  • case_sensitive (bool) – Whether the key lookup should be case-sensitive. Default is False.

Returns:

The instance corresponding to the key, or the default value if the key is not found.

Return type:

‘ButtonSchematic’ or None

Examples

>>> ButtonSchematic.get_instance('MY_BUTTON')
None
>>> ButtonSchematic.get_instance('MY_BUTTON', default='DEFAULT')
'DEFAULT'
>>> ButtonSchematic.get_instance('MY_BUTTON', default='DEFAULT', case_sensitive=True)
None
classmethod check_key(key: str, case_sensitive=False) bool

Check if the key is in the ButtonSchematic.instances dictionary.

Parameters:
  • key (str) – The key to check in the ButtonSchematics.instances dictionary.

  • case_sensitive (bool) – Whether the key comparison should be case-sensitive. Default is False.

Returns:

True if the key is in the instances dictionary, False otherwise.

Return type:

bool

Examples

>>> ButtonSchematic.check_key('MY_BUTTON')
False
>>> ButtonSchematic.check_key('MY_BUTTON', case_sensitive=True)
True
build()

Build the button.

Building the button will create the button object and store it in the ButtonSchematic.instances dictionary.

Returns:

None

disable()

Disables the button.

Returns:

None

enable()

Enables the button.

Returns:

None

hide()

Hides the button.

Returns:

None

unhide()

Unhides the button.

Returns:

None

update(**kwargs)

Updates the button.

Returns:

None

property auto_build
Whether the button should be built automatically.
Returns:

True if the button should be built automatically, False otherwise.

Return type:

bool

Examples

>>> button = ButtonSchematic('My Button')
>>> button.auto_build
False
property built
Whether the button has been built.
Returns:

True if the button has been built, False otherwise.

Return type:

bool

property button: Button or None

The PySimpleGUI button object.

Return type:

Button or None

property create_disabled: bool

Whether the button should be created in a disabled state.

Returns:

True if the button should be created in a disabled state, False otherwise.

Return type:

bool

property create_hidden
Whether the button should be created in a hidden state.
Returns:

True if the button should be created in a hidden state, False otherwise.

Return type:

bool

property disabled
Whether the button is disabled.
Returns:

True if the button is disabled, False otherwise.

Return type:

bool

property enabled
Whether the button is enabled.
Returns:

True if the button is enabled, False otherwise.

Return type:

bool

property enforce_unique_keys
Whether to enforce unique keys for buttons.
Returns:

True if unique keys are enforced, False otherwise.

Return type:

bool

property hidden
property key
The key for the button.
Returns:

The key for the button.

Return type:

str

property state
Returns a `Box` object containing the state of the button, including whether it is enabled
and visible.
Returns:

A Box object with the button’s state attributes.

Return type:

Box

Examples

>>> button = ButtonSchematic('My Button')
>>> button.state
{'enabled': False, 'visible': False}
property text: str

The text for display on the button.

Returns:

The text for the button.

Return type:

str

property visible
Whether the button is visible.
Returns:

True if the button is visible, False otherwise.

Return type:

bool

pic_scanner.gui.models.element_bases.button.factories.PARENT_LOGGER
class pic_scanner.gui.models.element_bases.button.factories.GUIElementKeyFactory(default_prefix=None, default_suffix=None, default_replacement_char='_', default_part_delimiter='_', default_all_upper=True, default_replace_spaces=True, skip_sample=True)

Bases: pic_scanner.gui.models.element_bases.element_key.Loggable

A factory class to create GUIElementKey objects with predefined configurations.

create_key(key: str, enable_prefix: bool = False, enable_suffix: bool = False, prefix: str = None, suffix: str = None, replace_spaces: bool = None, replacement_char: str = None, part_delimiter: str = None, all_upper: bool = None) pic_scanner.gui.models.element_bases.element_key.GUIElementKey

Create a GUIElementKey with the specified parameters, falling back to factory defaults where necessary.

Parameters:
  • key (str) – The base key string.

  • enable_prefix (bool) – Whether to enable the prefix.

  • enable_suffix (bool) – Whether to enable the suffix.

  • prefix (str) – The prefix to use. Defaults to the factory default.

  • suffix (str) – The suffix to use. Defaults to the factory default.

  • replace_spaces (bool) – Whether to replace spaces in the key.

  • replacement_char (str) – The character to replace spaces with. Defaults to the factory default.

  • part_delimiter (str) – The delimiter for the key parts. Defaults to the factory default.

  • all_upper (bool) – Whether to convert the key to all upper case. Defaults to the factory default.

Returns:

` The configured GUI element key.

Return type:

GUIElementKey

pic_scanner.gui.models.element_bases.button.factories.MOD_LOGGER
class pic_scanner.gui.models.element_bases.button.factories.ButtonFactory(window_name: str, default_auto_build=False, default_size=None, default_hidden=False, default_disabled=False, key_factory=None)

Bases: pic_scanner.gui.models.element_bases.button.Loggable

A class to create ButtonSchematic instances.

Properties:
instances (dict):

A dictionary of instances of the ButtonFactory.

Parameters:

window_name (str)

__new__()

Create a new instance of the ButtonFactory if one does not already exist.

Parameters:

window_name (str)

__init__()

Initialize the ButtonFactory.

Parameters:

window_name (str)

create_button -> ButtonSchematic

Create a ButtonSchematic with the specified parameters, falling back to factory defaults where necessary.

instances
create_button(text: str, auto_build: bool = None, size: tuple = None, hidden: bool = None, disabled: bool = None, key: str = None)

Create a ButtonSchematic with the specified parameters, falling back to factory defaults where necessary.

Parameters:
  • text (str) – The text for the button.

  • auto_build (bool) – Whether the button should be built automatically.

  • size (tuple) – The size of the button.

  • hidden (bool) – Whether the button should be hidden.

  • disabled (bool) – Whether the button should be disabled.

  • key (str) – The key for the button.

Returns:

The ButtonSchematic instance.

Return type:

ButtonSchematic