Multi Projector System 4

Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
config_reader.ConfigReader Class Reference

A configuration file reader for INI-format files. More...

## Public Member Functions
| __init__ (self, str config_path)
| Constructor for ConfigReader.
float | get_linear_parameter (self)
| Retrieves the linear parameter value.
str | get_image_path (self)
| Retrieves the image path.
str | get_overlap (self)
| Retrieves the overlap value.
str | get_blend_mode (self)
| Retrieves the blend mode.
None | save_config (self)
| Saves the current configuration back to the file.

## Public Attributes
| file_path
| Path object representing the configuration file location.

## Protected Member Functions
str | _get (self, str section, str key, Any fallback=None)
| Internal helper method to safely retrieve configuration values.

## Protected Attributes
| _parser
| Internal ConfigParser instance for reading INI files.

## Detailed Description

A configuration file reader for INI-format files.

This class provides a convenient interface for reading configuration parameters from INI files. It uses Python's configparser module internally and provides type-safe accessor methods for different parameter types. The class is particularly designed for managing image processing configurations including linear parameters, image paths, overlap values, and blend modes.

The configuration file is expected to have a 'Parameters' section with keys such as 'linear_parameter', 'image_path', 'overlap', and 'blend_mode'.

Note
  All getter methods provide default fallback values if the configuration keys are missing.

## Constructor & Destructor Documentation

## ◆ __init__()

config_reader.ConfigReader.__init__ | ( |  | self,
|  | str | config_path
| ) |  |

Constructor for ConfigReader.

Parameters

  config_path | Path to the configuration file (string)

Exceptions

  FileNotFoundError | if the configuration file doesn't exist

Initializes the ConfigReader by loading the specified INI file. The file path is converted to a Path object for robust file handling. The configuration is immediately read into memory using configparser.

Example usage:

reader = ConfigReader('/path/to/config.ini')

## Member Function Documentation

## ◆ _get()

str config_reader.ConfigReader._get | ( |  | self,
|  | str | section,
|  | str | key,
|  | Any | fallback = `None`
| ) |  |
| protected

Internal helper method to safely retrieve configuration values.

Parameters

  section | The section name in the INI file
  key | The key name within the section
  fallback | Default value to return if section or key doesn't exist

Returns
  Configuration value as a string, or fallback value

This method abstracts the error handling for missing sections or keys in the configuration file. It catches NoSectionError and NoOptionError exceptions and returns the fallback value instead.

## ◆ get_blend_mode()

str config_reader.ConfigReader.get_blend_mode | ( |  | self | ) |

Retrieves the blend mode.

Returns
  Blend mode as a string

Reads the 'blend_mode' key from the 'Parameters' section. Returns 'linear' as the default value if the key doesn't exist. Common blend modes might include 'linear', 'average', 'max', etc.

## ◆ get_image_path()

str config_reader.ConfigReader.get_image_path | ( |  | self | ) |

Retrieves the image path.

Returns
  Image path as a string

Reads the 'image_path' key from the 'Parameters' section. Returns an empty string if the key doesn't exist.

## ◆ get_linear_parameter()

float config_reader.ConfigReader.get_linear_parameter | ( |  | self | ) |

Retrieves the linear parameter value.

Returns
  Linear parameter as a float

Reads the 'linear_parameter' key from the 'Parameters' section. If the key doesn't exist, returns 0.0 as the default value. The returned value is guaranteed to be a float type.

Example:

linear_val = reader.get_linear_parameter()
print(f"Linear parameter: {linear_val}")

## ◆ get_overlap()

str config_reader.ConfigReader.get_overlap | ( |  | self | ) |

Retrieves the overlap value.

Returns
  Overlap value as a string

Reads the 'overlap' key from the 'Parameters' section. Returns '0' as the default value if the key doesn't exist.

## ◆ save_config()

None config_reader.ConfigReader.save_config | ( |  | self | ) |

Saves the current configuration back to the file.

Returns
  None

Writes the current state of the configuration parser back to the original file. This is useful if the configuration has been modified programmatically and needs to be persisted.

Warning
  This will overwrite the existing configuration file.

The documentation for this class was generated from the following file:

- Doxygen_Final/config_reader.py