Configuration¶
Configuration classes for defining GUI structure and behavior.
Configuration Loader¶
Configuration loader for reading and validating JSON GUI configuration files.
This module provides classes and functions for loading, parsing, and validating GUI configuration files in JSON format. It supports two-layer validation: 1. JSON Schema validation for structural correctness 2. Semantic validation via ConfigValidator for business logic
The module defines dataclasses for representing different parts of the GUI configuration (fields, windows, tabs, buttons) and provides a ConfigLoader class for loading and validating these configurations.
Typical usage example:
loader = ConfigLoader() config = loader.load_from_file(‘path/to/config.json’) field = loader.get_field_by_name(‘username’)
- class vibegui.config_loader.FieldConfig(name, type, label, default_value=None, required=False, min_value=None, max_value=None, options=None, choices=None, placeholder=None, tooltip=None, width=None, height=None, format_string=None)[source]¶
Bases:
objectConfiguration for a single form field.
Represents all configuration options for a form field including its type, label, default value, constraints, and display options.
- Parameters:
- default_value¶
Default value for the field. Defaults to None.
- Type:
Any, optional
- choices¶
Alternative to options for combo/select fields. Defaults to None.
- Type:
List[str], optional
- class vibegui.config_loader.WindowConfig(title='GUI Application', width=800, height=600, resizable=True, icon=None)[source]¶
Bases:
objectConfiguration for the main application window.
Defines the appearance and behavior of the main GUI window including dimensions, title, and resizability.
- class vibegui.config_loader.TabConfig(name, title, fields, layout='vertical', enabled=True, tooltip=None)[source]¶
Bases:
objectConfiguration for a single tab in a tabbed interface.
Represents a tab containing multiple form fields with its own layout and display properties.
- Parameters:
- fields¶
List of form fields contained in this tab.
- Type:
List[FieldConfig]
- layout¶
Layout style for fields (‘vertical’, ‘horizontal’, ‘grid’, ‘form’). Defaults to ‘vertical’.
- Type:
- fields: List[FieldConfig]¶
- class vibegui.config_loader.CustomButtonConfig(name, label, tooltip=None, enabled=True, icon=None, style=None)[source]¶
Bases:
objectConfiguration for a custom action button.
Defines a custom button that can trigger application-specific actions beyond the standard submit/cancel buttons.
- Parameters:
- class vibegui.config_loader.GuiConfig(window, fields, tabs=None, layout='vertical', submit_button=True, submit_label='Submit', cancel_button=True, cancel_label='Cancel', use_tabs=False, custom_buttons=None)[source]¶
Bases:
objectComplete GUI configuration for the entire application.
Top-level configuration object that contains all settings for the GUI including window, fields, tabs, layout, and buttons.
- Parameters:
window (WindowConfig)
fields (List[FieldConfig])
layout (str)
submit_button (bool)
submit_label (str)
cancel_button (bool)
cancel_label (str)
use_tabs (bool)
custom_buttons (List[CustomButtonConfig] | None)
- window¶
Main window configuration.
- Type:
- fields¶
List of form fields (used when not using tabs).
- Type:
List[FieldConfig]
- custom_buttons¶
List of custom buttons. Defaults to None.
- Type:
List[CustomButtonConfig], optional
- window: WindowConfig¶
- fields: List[FieldConfig]¶
- custom_buttons: List[CustomButtonConfig] | None = None¶
- class vibegui.config_loader.ConfigLoader[source]¶
Bases:
objectLoads and validates GUI configuration from JSON files.
Provides functionality to load GUI configurations from JSON files or dictionaries, validate them against JSON Schema and semantic rules, and parse them into GuiConfig objects.
The loader performs two-layer validation: 1. JSON Schema validation (if jsonschema package is available) 2. Semantic validation via ConfigValidator
Example
>>> loader = ConfigLoader() >>> config = loader.load_from_file('my_form.json') >>> username_field = loader.get_field_by_name('username')
- SUPPORTED_FIELD_TYPES = {'check', 'checkbox', 'color', 'combo', 'date', 'datetime', 'email', 'file', 'float', 'int', 'number', 'password', 'radio', 'range', 'select', 'spin', 'text', 'textarea', 'time', 'url'}¶
- SUPPORTED_LAYOUTS = {'form', 'grid', 'horizontal', 'vertical'}¶
- load_from_file(config_path)[source]¶
Load configuration from a JSON file.
Reads a JSON configuration file, validates it, and returns a GuiConfig object.
- Parameters:
config_path (str) – Path to the JSON configuration file.
- Returns:
Validated GUI configuration object.
- Return type:
- Raises:
FileNotFoundError – If the configuration file does not exist.
json.JSONDecodeError – If the file contains invalid JSON.
ValueError – If schema validation fails.
ConfigurationError – If semantic validation fails.
- load_from_dict(config_data)[source]¶
Load configuration from a dictionary.
Validates and parses a configuration dictionary into a GuiConfig object. Performs both JSON schema and semantic validation.
- Parameters:
config_data (Dict[str, Any]) – Configuration data as a dictionary.
- Returns:
Validated GUI configuration object.
- Return type:
- Raises:
ValueError – If schema validation fails.
ConfigurationError – If semantic validation fails.
- get_field_by_name(name)[source]¶
Get a field configuration by name.
Searches for a field with the given name in the currently loaded configuration.
- Parameters:
name (str) – Name of the field to retrieve.
- Returns:
The field configuration if found. None: If no config is loaded or field is not found.
- Return type:
Configuration Validator¶
Configuration validation utilities for vibegui.
- class vibegui.config_validator.ConfigValidator[source]¶
Bases:
objectValidates GUI configuration for correctness and completeness.
- SUPPORTED_FIELD_TYPES = {'check', 'checkbox', 'color', 'combo', 'date', 'datetime', 'email', 'file', 'float', 'int', 'number', 'password', 'radio', 'range', 'select', 'spin', 'text', 'textarea', 'time', 'url'}¶
- classmethod validate_and_raise(config)[source]¶
Validate configuration and raise ConfigurationError if invalid.
- Parameters:
config (GuiConfig) – The GUI configuration to validate
- Raises:
ConfigurationError – If the configuration is invalid
- Return type:
None