Microscope settings

Microscope settings file

Microscope settings are made persistent via a microscope settings file. By default, this file exists at ~/.openflexure/microscope_settings.json.

The class openflexure_microscope.config.OpenflexureSettingsFile provides functionality for loading a JSON-format settings file as a Python dictionary, and merging changed settings back into the file.

The default settings are loaded by the openflexure_microscope.config.user_settings, which can be imported anywhere in the microscope server application to allow reading and writing of persistent settings.

class openflexure_microscope.config.OpenflexureSettingsFile(path: str, defaults: Optional[dict] = None)[source]

An object to handle expansion, conversion, and saving of the microscope configuration.

  • config_path (str) – Path to the config JSON file (None falls back to default location)
  • expand (bool) – Expand paths to valid auxillary config files.
load() → dict[source]

Loads settings from a file on-disk.

save(config: dict, backup: bool = True)[source]

Save settings to a file on-disk.

  • config (dict) – Dictionary of new settings
  • backup (bool) – Back up previous settings file
merge(config: dict) → dict[source]

Merge settings dictionary with settings loaded from file on-disk.

Parameters:config (dict) – Dictionary of new settings
openflexure_microscope.config.load_json_file(config_path) → dict[source]

Open a .json config file

Parameters:config_path (str) – Path to the config JSON file. If None, defaults to DEFAULT_CONFIG_PATH
openflexure_microscope.config.save_json_file(config_path: str, config_dict: dict)[source]

Save a .json config file

  • config_dict (dict) – Dictionary of config data to save.
  • config_path (str) – Path to the config JSON file.

Creates an empty file, and all folder structure currently nonexistant.

Parameters:config_path – Path to the (possibly) new file
openflexure_microscope.config.initialise_file(config_path, populate: str = '{}\n')[source]

Check if a file exists, and if not, create it and optionally populate it with content

  • config_path (str) – Path to the file.
  • populate (str) – String to dump to the file, if it is being newly created
openflexure_microscope.config.user_settings = <openflexure_microscope.config.OpenflexureSettingsFile object>

Default user settings object

openflexure_microscope.config.user_configuration = <openflexure_microscope.config.OpenflexureSettingsFile object>

Default user settings object