|
Multi Projector System 4
|
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. | |
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'.
| config_reader.ConfigReader.__init__ | ( | self, | |
| str | config_path | ||
| ) |
Constructor for ConfigReader.
| config_path | Path to the configuration file (string) |
| 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:
|
protected |
Internal helper method to safely retrieve configuration values.
| 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 |
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.
| str config_reader.ConfigReader.get_blend_mode | ( | self | ) |
Retrieves the blend mode.
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.
| str config_reader.ConfigReader.get_image_path | ( | self | ) |
Retrieves the image path.
Reads the 'image_path' key from the 'Parameters' section. Returns an empty string if the key doesn't exist.
| float config_reader.ConfigReader.get_linear_parameter | ( | self | ) |
Retrieves the linear parameter value.
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:
| str config_reader.ConfigReader.get_overlap | ( | self | ) |
Retrieves the overlap value.
Reads the 'overlap' key from the 'Parameters' section. Returns '0' as the default value if the key doesn't exist.
| None config_reader.ConfigReader.save_config | ( | self | ) |
Saves the current configuration back to the file.
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.