pic_scanner.gui.models.element_bases.button
This module provides base functionality for creating buttons in the GUI.
Submodules
Attributes
Classes
A factory class to create GUIElementKey objects with predefined configurations. |
|
A class to represent the key for a GUI element. |
|
A metaclass to enhance classes with logging capabilities. Classes that inherit from |
Functions
|
Format a button text. |
Package Contents
- pic_scanner.gui.models.element_bases.button.PARENT_LOGGER
- class pic_scanner.gui.models.element_bases.button.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.LoggableA 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:
- class pic_scanner.gui.models.element_bases.button.GUIElementKey(key: str, enable_prefix: bool = False, enable_suffix: bool = False, prefix: str = None, suffix: str = None, replace_spaces: bool = False, replacement_char: str = '_', part_delimiter: str = '_', all_upper: bool = True, *args, **kwargs)
Bases:
str,pic_scanner.log_engine.LoggableA class to represent the key for a GUI element.
The class is a subclass of the `str
- Properties:
- prefix_enabled (bool):
Whether the prefix is enabled.
- prefix (str):
The prefix for the key.
- suffix_enabled (bool):
Whether the suffix is enabled.
- suffix (str):
The suffix for the key.
- pre_formatted (str):
The pre-formatted key.
- replacement_char (str):
The character to replace spaces with.
- replace_spaces (bool):
Whether to replace spaces in the key.
- formatted_key (str):
The formatted key.
This property is read-only and consists of the prefix, key, and suffix.
- part_delimiter (str):
The delimiter for the key parts.
- Parameters:
key (str)
enable_prefix (bool)
enable_suffix (bool)
prefix (str)
suffix (str)
replace_spaces (bool)
replacement_char (str)
part_delimiter (str)
all_upper (bool)
- property all_upper
- Whether the key should be all upper case.
- Returns:
True if the key should be all upper case, False otherwise.
- Return type:
bool
- property part_delimiter_1
- The first part delimiter for the key.
- Returns:
The first part delimiter for the key.
- Return type:
str
- property part_delimiter_2
- The second part delimiter for the key.
- Returns:
The second part delimiter for the key.
- Return type:
str
- property prefix_enabled: bool
Whether the prefix is enabled.
- Returns:
True if the prefix is enabled, False otherwise.
- Return type:
bool
- property prefix: str
The prefix for the key.
- Returns:
The prefix for the key.
- Return type:
str
- property suffix_enabled: bool
Whether the suffix is enabled.
- Returns:
True if the suffix is enabled, False otherwise.
- Return type:
bool
- property suffix: str
The suffix for the key.
- Returns:
The suffix for the key.
- Return type:
str
- property pre_formatted: str
The pre-formatted key.
- Returns:
The pre-formatted key.
- Return type:
str
- property replacement_char: str
The character to replace spaces with.
- Returns:
The character to replace spaces with.
- Return type:
str
- property replace_spaces: bool
Whether to replace spaces in the key.
- Returns:
True if spaces should be replaced, False otherwise.
- Return type:
bool
- property formatted_key: str
The formatted key.
- Returns:
The formatted key.
- Return type:
str
- property formatted
- The formatted key with the prefix and suffix.
- Returns:
The formatted key.
- Return type:
str
- pic_scanner.gui.models.element_bases.button.MOD_LOGGER
- class pic_scanner.gui.models.element_bases.button.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.LoggableA 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:
text (str)
key (str)
key_factory (pic_scanner.gui.models.element_bases.element_key.factories.GUIElementKeyFactory)
- - 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.format_button_text(text: str, skip_titalize=False)
Format a button text.
- Parameters:
text (str) – The text to format.
skip_titalize (bool) – Whether to skip titalizing the text. (Default: False)
- Returns:
The formatted button text.
- Return type:
str
Examples
>>> format_button_text('my button') 'My Button'
>>> format_button_text('my button', skip_titalize=True) 'my button'