|
ENLIGHTEN
Cross-platform desktop GUI for Wasatch Photonics spectrometers
|
This is a wrapper over ConfigParser. More...
Public Member Functions | |
| __init__ (self, ctl) | |
| clear (self) | |
| dump (self) | |
| get (self, section, key, raw=False, default="0") | |
| get_bool (self, section, key, default=False) | |
| Not using ConfigParser.getboolean() because we want to support defaults. | |
| get_float (self, section, key, default=0.0) | |
| get_int (self, section, key, default=0) | |
| get_options (self, section) | |
| get_sections (self) | |
| has_option (self, section, option) | |
| has_section (self, section) | |
| load_defaults (self) | |
| load_text (self) | |
| Slurp file as array of lines. | |
| parse (self) | |
| Load as ConfigParser object. | |
| process_color (self, value) | |
| process_pen_style (self, value) | |
| reload (self) | |
| We read the .ini twice: | |
| remove_section (self, section) | |
| save (self) | |
| save_callback (self) | |
| save_file (self, full=False) | |
| set (self, section, key, value) | |
| stub_dir (self) | |
| create EnlightenSpectra directory if not found. | |
| stub_missing (self) | |
| If no enlighten.ini file exists, make one. | |
| stub_test (self) | |
| Create test spectra dir if not found. | |
Public Attributes | |
| color_names = ColorNames() | |
| config = None | |
| ctl = ctl | |
| dict | defaults = None |
| directory = common.get_default_data_dir() | |
| lb_save_result = cfu.label_save_ini_result | |
| int | linenum = 0 |
| list | lines = [] |
| multispec = None | |
| pathname = os.path.join(self.directory, "enlighten.ini") | |
| save_callback = 1) | |
| test_dir = os.path.join(self.directory, 'testSpectrometers') | |
This is a wrapper over ConfigParser.
It adds the following features:
This class manages enlighten.ini, which should be found under EnlightenSpectra.
A default template file will be created if none exists.
Like most .ini files, sections are delineated in [brackets], followed by lines of "name = value" pairs. Blank lines and those starting with pound (#) are ignored.
Most sections are global and affect all spectrometers. Individual spectrometer settings can be controlled by sections named with the given device's serialNumber ([WP-00001], etc).
Note that in the name of user-friendliness and automation, some English-language values are dynamically translated from strings to corresponding Qt objects (colors, pen styles etc) in get().
(widget, type, ini_label) e.g., config.register(checkbox_batch_enabled, bool, "batch.enabled")
Such that:
"enlighten.ini" pre-dated me, and needed to be supported. Doing this from scratch, I'd go with JSON, which supports much more complex structured data. For now, the compromise will be that "complex" objects requiring JSON configuration can use their own configuration files, pointed to by this one.
We are using what current configparser docs call the "legacy API" – my recollection is that it was the only API when this class was written under Python 2.7. At some point we may want to update to the newer dict- style interface.
| enlighten.file_io.Configuration.Configuration.__init__ | ( | self, | |
| ctl ) |
| enlighten.file_io.Configuration.Configuration.clear | ( | self | ) |
| enlighten.file_io.Configuration.Configuration.dump | ( | self | ) |
| enlighten.file_io.Configuration.Configuration.get | ( | self, | |
| section, | |||
| key, | |||
| raw = False, | |||
| default = "0" ) |
| raw | return the literal value exactly as found in the file (otherwise, perform interpretive post-processing of color names and pen styles) |
| section | which INI section the key should be found in |
| key | which setting we're looking for |
| default | value to return if not found |
| enlighten.file_io.Configuration.Configuration.get_bool | ( | self, | |
| section, | |||
| key, | |||
| default = False ) |
Not using ConfigParser.getboolean() because we want to support defaults.
| enlighten.file_io.Configuration.Configuration.get_float | ( | self, | |
| section, | |||
| key, | |||
| default = 0.0 ) |
| enlighten.file_io.Configuration.Configuration.get_int | ( | self, | |
| section, | |||
| key, | |||
| default = 0 ) |
| enlighten.file_io.Configuration.Configuration.get_options | ( | self, | |
| section ) |
| enlighten.file_io.Configuration.Configuration.get_sections | ( | self | ) |
| enlighten.file_io.Configuration.Configuration.has_option | ( | self, | |
| section, | |||
| option ) |
| enlighten.file_io.Configuration.Configuration.has_section | ( | self, | |
| section ) |
| enlighten.file_io.Configuration.Configuration.load_defaults | ( | self | ) |
| enlighten.file_io.Configuration.Configuration.load_text | ( | self | ) |
Slurp file as array of lines.
| enlighten.file_io.Configuration.Configuration.parse | ( | self | ) |
Load as ConfigParser object.
| enlighten.file_io.Configuration.Configuration.process_color | ( | self, | |
| value ) |
| enlighten.file_io.Configuration.Configuration.process_pen_style | ( | self, | |
| value ) |
| enlighten.file_io.Configuration.Configuration.reload | ( | self | ) |
We read the .ini twice:
| enlighten.file_io.Configuration.Configuration.remove_section | ( | self, | |
| section ) |
| enlighten.file_io.Configuration.Configuration.save | ( | self | ) |
| enlighten.file_io.Configuration.Configuration.save_callback | ( | self | ) |
| enlighten.file_io.Configuration.Configuration.save_file | ( | self, | |
| full = False ) |
| enlighten.file_io.Configuration.Configuration.set | ( | self, | |
| section, | |||
| key, | |||
| value ) |
| enlighten.file_io.Configuration.Configuration.stub_dir | ( | self | ) |
create EnlightenSpectra directory if not found.
| enlighten.file_io.Configuration.Configuration.stub_missing | ( | self | ) |
If no enlighten.ini file exists, make one.
| enlighten.file_io.Configuration.Configuration.stub_test | ( | self | ) |
Create test spectra dir if not found.
| enlighten.file_io.Configuration.Configuration.color_names = ColorNames() |
| enlighten.file_io.Configuration.Configuration.config = None |
| enlighten.file_io.Configuration.Configuration.ctl = ctl |
| enlighten.file_io.Configuration.Configuration.defaults = None |
| enlighten.file_io.Configuration.Configuration.directory = common.get_default_data_dir() |
| enlighten.file_io.Configuration.Configuration.lb_save_result = cfu.label_save_ini_result |
| int enlighten.file_io.Configuration.Configuration.linenum = 0 |
| list enlighten.file_io.Configuration.Configuration.lines = [] |
| enlighten.file_io.Configuration.Configuration.multispec = None |
| enlighten.file_io.Configuration.Configuration.pathname = os.path.join(self.directory, "enlighten.ini") |
| enlighten.file_io.Configuration.Configuration.save_callback = 1) |
| enlighten.file_io.Configuration.Configuration.test_dir = os.path.join(self.directory, 'testSpectrometers') |