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: object

Configuration for a single form field.

Represents all configuration options for a form field including its type, label, default value, constraints, and display options.

Parameters:
  • name (str)

  • type (str)

  • label (str)

  • default_value (Any)

  • required (bool)

  • min_value (float | None)

  • max_value (float | None)

  • options (List[str] | None)

  • choices (List[str] | None)

  • placeholder (str | None)

  • tooltip (str | None)

  • width (int | None)

  • height (int | None)

  • format_string (str | None)

name

Unique identifier for the field.

Type:

str

type

Field type (e.g., ‘text’, ‘number’, ‘select’, ‘checkbox’).

Type:

str

label

Display label shown to the user.

Type:

str

default_value

Default value for the field. Defaults to None.

Type:

Any, optional

required

Whether the field is required. Defaults to False.

Type:

bool, optional

min_value

Minimum value for numeric fields. Defaults to None.

Type:

float, optional

max_value

Maximum value for numeric fields. Defaults to None.

Type:

float, optional

options

Options for select/radio/combo fields. Defaults to None.

Type:

List[str], optional

choices

Alternative to options for combo/select fields. Defaults to None.

Type:

List[str], optional

placeholder

Placeholder text for input fields. Defaults to None.

Type:

str, optional

tooltip

Tooltip text shown on hover. Defaults to None.

Type:

str, optional

width

Field width in pixels. Defaults to None.

Type:

int, optional

height

Field height in pixels. Defaults to None.

Type:

int, optional

format_string

Python format string for float fields (e.g., ‘.2f’). Defaults to None.

Type:

str, optional

name: str
type: str
label: str
default_value: Any = None
required: bool = False
min_value: float | None = None
max_value: float | None = None
options: List[str] | None = None
choices: List[str] | None = None
placeholder: str | None = None
tooltip: str | None = None
width: int | None = None
height: int | None = None
format_string: str | None = None
class vibegui.config_loader.WindowConfig(title='GUI Application', width=800, height=600, resizable=True, icon=None)[source]

Bases: object

Configuration for the main application window.

Defines the appearance and behavior of the main GUI window including dimensions, title, and resizability.

Parameters:
title

Window title text. Defaults to ‘GUI Application’.

Type:

str

width

Window width in pixels. Defaults to 800.

Type:

int

height

Window height in pixels. Defaults to 600.

Type:

int

resizable

Whether the window can be resized. Defaults to True.

Type:

bool

icon

Path to window icon file. Defaults to None.

Type:

str, optional

title: str = 'GUI Application'
width: int = 800
height: int = 600
resizable: bool = True
icon: str | None = None
class vibegui.config_loader.TabConfig(name, title, fields, layout='vertical', enabled=True, tooltip=None)[source]

Bases: object

Configuration for a single tab in a tabbed interface.

Represents a tab containing multiple form fields with its own layout and display properties.

Parameters:
name

Unique identifier for the tab.

Type:

str

title

Display title shown on the tab.

Type:

str

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:

str

enabled

Whether the tab is enabled and accessible. Defaults to True.

Type:

bool

tooltip

Tooltip text shown on tab hover. Defaults to None.

Type:

str, optional

name: str
title: str
fields: List[FieldConfig]
layout: str = 'vertical'
enabled: bool = True
tooltip: str | None = None
class vibegui.config_loader.CustomButtonConfig(name, label, tooltip=None, enabled=True, icon=None, style=None)[source]

Bases: object

Configuration for a custom action button.

Defines a custom button that can trigger application-specific actions beyond the standard submit/cancel buttons.

Parameters:
  • name (str)

  • label (str)

  • tooltip (str | None)

  • enabled (bool)

  • icon (str | None)

  • style (str | None)

name

Unique identifier for the button.

Type:

str

label

Display text shown on the button.

Type:

str

tooltip

Tooltip text shown on button hover. Defaults to None.

Type:

str, optional

enabled

Whether the button is enabled and clickable. Defaults to True.

Type:

bool

icon

Path to button icon file. Defaults to None.

Type:

str, optional

style

CSS style string for button styling. Defaults to None.

Type:

str, optional

name: str
label: str
tooltip: str | None = None
enabled: bool = True
icon: str | None = None
style: str | None = None
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: object

Complete 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

Main window configuration.

Type:

WindowConfig

fields

List of form fields (used when not using tabs).

Type:

List[FieldConfig]

tabs

List of tabs for tabbed interface. Defaults to None.

Type:

List[TabConfig], optional

layout

Default layout style for fields. Defaults to ‘vertical’.

Type:

str

submit_button

Whether to show submit button. Defaults to True.

Type:

bool

submit_label

Label for submit button. Defaults to ‘Submit’.

Type:

str

cancel_button

Whether to show cancel button. Defaults to True.

Type:

bool

cancel_label

Label for cancel button. Defaults to ‘Cancel’.

Type:

str

use_tabs

Whether to use tabbed interface. Defaults to False.

Type:

bool

custom_buttons

List of custom buttons. Defaults to None.

Type:

List[CustomButtonConfig], optional

window: WindowConfig
fields: List[FieldConfig]
tabs: List[TabConfig] | None = None
layout: str = 'vertical'
submit_button: bool = True
submit_label: str = 'Submit'
cancel_button: bool = True
cancel_label: str = 'Cancel'
use_tabs: bool = False
custom_buttons: List[CustomButtonConfig] | None = None
class vibegui.config_loader.ConfigLoader[source]

Bases: object

Loads 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

config

Most recently loaded configuration.

Type:

GuiConfig, optional

SUPPORTED_FIELD_TYPES

Set of supported field type strings.

Type:

set

SUPPORTED_LAYOUTS

Set of supported layout type strings.

Type:

set

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:

GuiConfig

Raises:
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:

GuiConfig

Raises:
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:

FieldConfig

Configuration Validator

Configuration validation utilities for vibegui.

class vibegui.config_validator.ConfigValidator[source]

Bases: object

Validates 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_config(config)[source]

Validate a complete GUI configuration.

Parameters:

config (GuiConfig) – The GUI configuration to validate

Returns:

List of validation error messages (empty if valid)

Return type:

List[str]

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