ENLIGHTEN
Cross-platform desktop GUI for Wasatch Photonics spectrometers
Loading...
Searching...
No Matches
enlighten.file_io.Configuration.Configuration Class Reference

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')
 

Detailed Description

This is a wrapper over ConfigParser.

It adds the following features:

  • generates a stub template if none found
  • preserves comments when saving .ini
  • auto-expands named Colors
  • auto-converts Qt line styles to enum

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().

Todo
allow Business Objects to define their own ConfigurationDefaults.
Todo
support registration, similar to EEPROMEditor, of tuples like the following:

(widget, type, ini_label) e.g., config.register(checkbox_batch_enabled, bool, "batch.enabled")

Such that:

  • register() will apply NON-DEFAULT config values to the widget
  • set() will update both the widget and config section
  • get() will return the current widget value
Design Considerations

"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.

Stale code notice

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.

Constructor & Destructor Documentation

◆ __init__()

enlighten.file_io.Configuration.Configuration.__init__ ( self,
ctl )

Member Function Documentation

◆ clear()

enlighten.file_io.Configuration.Configuration.clear ( self)

◆ dump()

enlighten.file_io.Configuration.Configuration.dump ( self)

◆ get()

enlighten.file_io.Configuration.Configuration.get ( self,
section,
key,
raw = False,
default = "0" )
Parameters
rawreturn the literal value exactly as found in the file (otherwise, perform interpretive post-processing of color names and pen styles)
sectionwhich INI section the key should be found in
keywhich setting we're looking for
defaultvalue to return if not found
Returns
something, always (defaults to string "0")

◆ get_bool()

enlighten.file_io.Configuration.Configuration.get_bool ( self,
section,
key,
default = False )

Not using ConfigParser.getboolean() because we want to support defaults.

◆ get_float()

enlighten.file_io.Configuration.Configuration.get_float ( self,
section,
key,
default = 0.0 )

◆ get_int()

enlighten.file_io.Configuration.Configuration.get_int ( self,
section,
key,
default = 0 )

◆ get_options()

enlighten.file_io.Configuration.Configuration.get_options ( self,
section )

◆ get_sections()

enlighten.file_io.Configuration.Configuration.get_sections ( self)

◆ has_option()

enlighten.file_io.Configuration.Configuration.has_option ( self,
section,
option )

◆ has_section()

enlighten.file_io.Configuration.Configuration.has_section ( self,
section )

◆ load_defaults()

enlighten.file_io.Configuration.Configuration.load_defaults ( self)

◆ load_text()

enlighten.file_io.Configuration.Configuration.load_text ( self)

Slurp file as array of lines.

◆ parse()

enlighten.file_io.Configuration.Configuration.parse ( self)

Load as ConfigParser object.

◆ process_color()

enlighten.file_io.Configuration.Configuration.process_color ( self,
value )

◆ process_pen_style()

enlighten.file_io.Configuration.Configuration.process_pen_style ( self,
value )

◆ reload()

enlighten.file_io.Configuration.Configuration.reload ( self)

We read the .ini twice:

  • once as an array of lines (we use this when re-saving the file later)
  • again as a parsed configuration tree

◆ remove_section()

enlighten.file_io.Configuration.Configuration.remove_section ( self,
section )

◆ save()

enlighten.file_io.Configuration.Configuration.save ( self)

◆ save_callback()

enlighten.file_io.Configuration.Configuration.save_callback ( self)

◆ save_file()

enlighten.file_io.Configuration.Configuration.save_file ( self,
full = False )

◆ set()

enlighten.file_io.Configuration.Configuration.set ( self,
section,
key,
value )

◆ stub_dir()

enlighten.file_io.Configuration.Configuration.stub_dir ( self)

create EnlightenSpectra directory if not found.

◆ stub_missing()

enlighten.file_io.Configuration.Configuration.stub_missing ( self)

If no enlighten.ini file exists, make one.

◆ stub_test()

enlighten.file_io.Configuration.Configuration.stub_test ( self)

Create test spectra dir if not found.

Member Data Documentation

◆ color_names

enlighten.file_io.Configuration.Configuration.color_names = ColorNames()

◆ config

enlighten.file_io.Configuration.Configuration.config = None

◆ ctl

enlighten.file_io.Configuration.Configuration.ctl = ctl

◆ defaults

enlighten.file_io.Configuration.Configuration.defaults = None

◆ directory

enlighten.file_io.Configuration.Configuration.directory = common.get_default_data_dir()

◆ lb_save_result

enlighten.file_io.Configuration.Configuration.lb_save_result = cfu.label_save_ini_result

◆ linenum

int enlighten.file_io.Configuration.Configuration.linenum = 0

◆ lines

list enlighten.file_io.Configuration.Configuration.lines = []

◆ multispec

enlighten.file_io.Configuration.Configuration.multispec = None

◆ pathname

enlighten.file_io.Configuration.Configuration.pathname = os.path.join(self.directory, "enlighten.ini")

◆ save_callback

enlighten.file_io.Configuration.Configuration.save_callback = 1)

◆ test_dir

enlighten.file_io.Configuration.Configuration.test_dir = os.path.join(self.directory, 'testSpectrometers')

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