Utilities

Utility classes and functions for validation, file operations, and platform detection.

Common utilities used across different GUI backends.

class qtpyguihelper.utils.ValidationUtils[source]

Bases: object

Utilities for validating form data and configurations.

static validate_required_fields(form_data, required_fields)[source]

Validate that all required fields have values.

Parameters:
  • form_data (Dict[str, Any]) – Dictionary of form field values

  • required_fields (List[str]) – List of field names that are required

Returns:

List of missing field names (empty if all valid)

Return type:

List[str]

static validate_numeric_range(value, min_val=None, max_val=None)[source]

Validate that a numeric value is within the specified range.

Parameters:
  • value (int | float) – The numeric value to validate

  • min_val (float | None) – Minimum allowed value (inclusive)

  • max_val (float | None) – Maximum allowed value (inclusive)

Returns:

True if value is within range, False otherwise

Return type:

bool

class qtpyguihelper.utils.FileUtils[source]

Bases: object

Utilities for file operations.

static save_data_to_json(data, file_path, include_empty=True)[source]

Save data to a JSON file.

Parameters:
  • data (Dict[str, Any]) – Data to save

  • file_path (str) – Path to save the file

  • include_empty (bool) – Whether to include empty/None values

Returns:

True if successful, False otherwise

Return type:

bool

static load_data_from_json(file_path)[source]

Load data from a JSON file.

Parameters:

file_path (str) – Path to the JSON file

Returns:

Loaded data dictionary, or None if failed

Return type:

Dict[str, Any] | None

class qtpyguihelper.utils.PlatformUtils[source]

Bases: object

Utilities for platform-specific operations.

static get_system()[source]

Get the current operating system.

Return type:

str

static is_macos()[source]

Check if running on macOS.

Return type:

bool

static is_windows()[source]

Check if running on Windows.

Return type:

bool

static is_linux()[source]

Check if running on Linux.

Return type:

bool

static is_dark_mode()[source]

Detect if the system is using dark mode.

Returns:

True if dark mode is detected, False otherwise

Return type:

bool

class qtpyguihelper.utils.FormatUtils[source]

Bases: object

Utilities for formatting values.

static format_float(value, format_string=None)[source]

Format a float value according to the specified format string.

Parameters:
  • value (float) – The float value to format

  • format_string (str | None) – Format string (e.g., “.2f”, “.4f”)

Returns:

Formatted string representation

Return type:

str

static parse_float(value_str)[source]

Parse a string to float, returning None if invalid.

Parameters:

value_str (str) – String to parse

Returns:

Parsed float value or None

Return type:

float | None

static parse_int(value_str)[source]

Parse a string to int, returning None if invalid.

Parameters:

value_str (str) – String to parse

Returns:

Parsed int value or None

Return type:

int | None

class qtpyguihelper.utils.LayoutUtils[source]

Bases: object

Utilities for layout calculations and adjustments.

static calculate_window_center(window_width, window_height, screen_width, screen_height)[source]

Calculate the center position for a window.

Parameters:
  • window_width (int) – Width of the window

  • window_height (int) – Height of the window

  • screen_width (int) – Width of the screen

  • screen_height (int) – Height of the screen

Returns:

Tuple of (x, y) coordinates for centering

Return type:

tuple

Get recommended widget sizes for different field types.

Returns:

Dictionary mapping field types to size recommendations

Return type:

Dict[str, Dict[str, int]]