3. qcobj Package¶
3.1. qconfigobj Module¶
Validator errors classes:



Validator class:

QConfigObj classes:




-
class
qcobj.qconfigobj.Certifier(*args, **kargs)[source]¶ Bases:
validate.ValidatorA Validator for Quantities
See also
Validator class
-
quantity_chek(value, *args, **kargs)[source]¶ Check if value has the right dimensions and is in the allowed range.
Quantity MUST be specified in configspec like:
>>> quantity(units='Pa / s', min=0, max=100, default=50 Pa /s)
- where:
min and max CAN be positional arguments
default value can be specified in any dimensionally correct unit after the first blank
- Parameters
value (instance) – the value we are checking
- Returns
validated quantity (or quantities)
- Raises
VdtUnitsError if no units are specified –
ValueError if value is not a quantity –
SyntaxError if quantity specification uses a wrong syntax –
VdtDimensionalityError if value has the wrong physical – dimension
VdtRangeError if value (converted to the units defined – in configspec) is not in range [vmin, vmax]
-
quantity_list_chek(value, *args, **kargs)[source]¶ Check if value has the right dimensions and is in the allowed range.
Quantity MUST be specified in configspec like:
>>> quantity_list(units='Pa / s', min=0, max=100, nmin=1, nmax=2, default=list('50 Pa/s', '75 Pa/s'))
- where:
min, max, nmin, nmax CAN be positional arguments
default value can be specified in any dimensionally correct unit after the first blank
- Parameters
value (instance) – the value we are checking
- Returns
validated quantity (or quantities)
- Raises
VdtUnitsError if no units are specified –
ValueError if value is not a quantity –
SyntaxError if quantity specification uses a wrong syntax –
VdtDimensionalityError if value has the wrong physical – dimension
VdtRangeError if value (converted to the units defined – in configspec) is not in range [vmin, vmax]
-
-
class
qcobj.qconfigobj.QConfigObj(*args, **kargs)[source]¶ Bases:
qcobj.qconfigobj._QConfigObjA Quantity aware ConfigObj class with CONFIGFILES_KEY support
-
__init__(*args, **kargs)[source]¶ Create a new instance. kargs are from
configobj.ConfigObj- Keyword Arguments
infile (file instance) – Input file (None)
configspec (list of strings) – configspec (None)
encoding (string) – encoding (None)
interpolation (bool) – True
raise_errors (bool) – False
list_values (bool) – True
create_empty (bool) – False
file_error (bool) – False
stringify (bool) – True,
indent_type (string) – None
default_encoding (string) – None
unrepr (bool) – False
write_empty_values (bool) – False
_inspec (bool) – False
strict (bool) – True
noextra (bool) – True
-
-
exception
qcobj.qconfigobj.QConfigObjExtra(value)[source]¶ Bases:
configobj.ConfigObjErrorExtra value / section error
-
exception
qcobj.qconfigobj.QConfigObjInvalid(value)[source]¶ Bases:
configobj.ConfigObjErrorInvalid value error
-
class
qcobj.qconfigobj.Q_(*args, **kargs)[source]¶ Bases:
pint.quantity.build_quantity_class.<locals>.QuantityA Quantity class with user settable preferred units for representation
-
static
__new__(cls, *args, **kargs)[source]¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__()[source]¶ Allow pickling quantities. Since UnitRegistries are not pickled, upon unpickling the new object is always attached to the application registry.
-
__str__()[source]¶ Return
qcobj.qconfigobj.eng_string()representation of magnitude rounded at 6 decimals with units
-
static
-
exception
qcobj.qconfigobj.VdtDimensionalityError(dim1, dim2)[source]¶ Bases:
validate.ValidateErrorDimensionality error class
-
exception
qcobj.qconfigobj.VdtLengthError(value, nmin, nmax)[source]¶ Bases:
validate.ValidateErrorList length error class
-
exception
qcobj.qconfigobj.VdtRangeError(value, vmin, vmax, units)[source]¶ Bases:
validate.ValidateErrorRange error class
-
exception
qcobj.qconfigobj.VdtUnitsError(value)[source]¶ Bases:
validate.ValidateErrorMissing units keyword in quantity type specifier
-
class
qcobj.qconfigobj._QConfigObj(*args, **kargs)[source]¶ Bases:
configobj.ConfigObjA Quantity aware ConfigObj class
-
__init__(*args, **kargs)[source]¶ Create a new instance. kargs are from
configobj.ConfigObj- Keyword Arguments
infile (file instance) – Input file (None)
configspec (list of strings) – configspec (None)
encoding (string) – encoding (None)
interpolation (bool) – True
raise_errors (bool) – False
list_values (bool) – True
create_empty (bool) – False
file_error (bool) – False
stringify (bool) – True,
indent_type (string) – None
default_encoding (string) – None
unrepr (bool) – False
write_empty_values (bool) – False
_inspec (bool) – False
strict (bool) – True
noextra (bool) – True
-
_specAtPath(path)[source]¶ Return configspec section at path
- Parameters
path (list) – list of section names
- Returns
configspec section at path
-
comment(path, key)[source]¶ Return comment from configspec for key at path
- Parameters
path (list) – list of section names
key (string) – valid key in section at path
- Returns
comment from configspec for key at path
-
configUnits(section, key)[source]¶ Return units string for key in section or None
- Parameters
section (
qcobj.qconfigobj.QConfigObj.Section) – instancekey (string) – valid key in section
- Returns
Return units string for key in section or None
-
pretty()[source]¶ Return pretty string representation for report attribute
- Returns
pretty string representation for report attribute
-
reference_quantity(section, key)[source]¶ Return reference quantity for section[key]
- Parameters
section (
qcobj.qconfigobj.QConfigObj.Section) – instancekey (string) – valid key in section
- Returns
Return reference quantity for section[key]
Note
At present USED ONLY IN
GMOD2.boundaryCondition
-
val_to_default(section, key, value)[source]¶ Set section[key] with value converted to default units (if any)
- Parameters
section (
qcobj.qconfigobj.QConfigObj.Section) – instancekey (string) – valid key in section
value (float or int) – new value
Note
At present used only in addMag and setMag
-
-
qcobj.qconfigobj.eng_string(x, fmt='%s', si=False, doround=None)[source]¶ Returns float/int value <x> formatted in a simplified engineering format using an exponent that is a multiple of 3.
- Parameters
fmt (string) – printf-style string used to format the value before the exponent.
si (boolean) – if True, use SI suffix for exponent, e.g. k instead of e3, n instead of e-9 etc.
doround (boolean) – if not None round the number to doround decimal digits
- Returns: float/int value <x> formatted in a simplified engineering
format using an exponent that is a multiple of 3.
E.g. with fmt='%.2f': 1.23e-08 => 12.30e-9 123 => 123.00 1230.0 => 1.23e3 -1230000.0 => -1.23e6 and with si=True: 1230.0 => 1.23k -1230000.0 => -1.23M and with doround=6 0.30000000000000004 => 0.3
-
qcobj.qconfigobj.errors(cobj, ok)[source]¶ Return errors in a configuration file in terse format
- Parameters
cobj (
qcobj.qconfigobj.QConfigObjinstance) – instanceok (dict) – results dictionary returned by validate
- Returns
error messages string
-
qcobj.qconfigobj.extract(string, start='(', stop=')', firststop=True)[source]¶ Return substring between start and first/last stop characters
- Parameters
string (string) – the string to extract from
start (string) – the left delimiter string
stop (string) – the right delimiter string
firststop (bool) – if True extract to the rightmost stop
- Returns
the extracted string
-
qcobj.qconfigobj.isStringLike(s)[source]¶ Returns True if s acts “like” a string, i.e. is str or unicode.
- Parameters
s (string) – instance to inspect
- Returns
True if s acts like a string
-
qcobj.qconfigobj.makeSpec(name, params, level=0)[source]¶ Create ConfigObj configspec string definition for section name
- Parameters
name (string) – name of the section we are building
params (Odict) –
ordered dict instance with the directives: The directives are (key, value) where value is a dictionary with the keywords:
comments: a comment string or a list of comment strings
units: a string with the units of measure
default: a default value (optional)
min: minimum value accepted (optional)
max: maximum value accepted (optional)
OLD (deprecated) –
params – ordered dict instance with the directives: The directives are (key, value) where value is a tuple of (comment, comment, … comment, ‘units, min, max’, default). In case of int and float optional minimum or min and max values can be specified separated by ONE SINGLE blank char
level (int) – indentation level
- Returns
configSpec string
-
qcobj.qconfigobj.makeSpecEntry(key, spec)[source]¶ Accept new syntax suggested by Reviewer #1
- Parameters
key (string) – keyword
spec (dict) –
dictionary defining the quantity and valid range. Valid keywords:
comments: a comment string or a list of comment strings
units: a string with the units of measure
default: a default value (optional)
min: minimum value accepted (optional)
max: maximum value accepted (optional)
- Returns
configSpec string for key
-
qcobj.qconfigobj.msec2cmyear(ms)[source]¶ Return m/s converted to cm/year Quantity
- Parameters
ms (float) – meters per second
- Returns
cm / year
-
qcobj.qconfigobj.qLike(value, section, key)[source]¶ Return value converted to a quantity like key in section
- Parameters
value (float or int) – value to convert
section (
qcobj.qconfigobj.QConfigObj.Section) – instancekey (string) – an existing key in section
- Returns
- A
qcobj.qconfigobj.Q_instance like the one at section[key] with magnitude value
- A
-
qcobj.qconfigobj.reindent(s, numSpaces=4, no_empty_lines=False)[source]¶ Return string s reindented by numSpaces spaces
- Parameters
s (string) – string to reindent
numSpaces (int) – number of spaces to shift to the right
no_empty_lines (bool) – if True remove empty lines
- Returns
reindented string
-
qcobj.qconfigobj.setVal(section, key, value)[source]¶ Set value to section[key] converted to default units
- Parameters
section (
qcobj.qconfigobj.QConfigObj.Section) – instancekey (string) – valid key for section
value (float or int) – value to set at section[key] converted to Quantity
-
qcobj.qconfigobj.splitPolygons(s)[source]¶ Return a list of polygons from s. Separator is a blank line. Separation lines with blanks are digested as well.
- Parameters
s (string) – string defining polygon(s) separated by a blank line. One vertex per line
- Returns
list with polygons
-
qcobj.qconfigobj.sumVal(section, key, value)[source]¶ Add value to section[key] converted to default units
- Parameters
section (
qcobj.qconfigobj.QConfigObj.Section) – instancekey (string) – valid key for section
value (float or int) – value to add to section[key]
-
qcobj.qconfigobj.toBaseUnits(q)[source]¶ Return magnitude of quantity q converted to base units * * Used for polygons * *
- Parameters
q (
qcobj.qconfigobj.Q_) – instance- Returns
magnitude of q in base units
-
qcobj.qconfigobj.val(section, key)[source]¶ Return value of section[key] in units specified in configspec
- Parameters
section (
qcobj.qconfigobj.QConfigObj.Section) – instancekey (string) – valid key for section
- Returns
values in section[key] converted to units defined in configspec
-
qcobj.qconfigobj.vval(d, k)[source]¶ Return magnitude in units specified in configspec for key k’ in qconfigobj section `d or simply magnitude if d is a dict instance
- Parameters
d (dict or
qcobj.qconfigobj.QConfigObj.Sectioninstance) – dict_likek (string) – key in d
- Returns
result of
qcobj.qconfigobj.val()(d, k) or simply the magnitude of d[k]
3.2. utils Module¶
-
qcobj.utils.makeDoc(configSpecLines)[source]¶ Return dictionary with sphinx documentation for configspecLines
- Parameters
configSpecLines (list) – configspec file lines for ConfigObj
- Returns
dictionary with sphinx documentation for configspecLines
- Return type
dict
-
qcobj.utils.makeSphinxDoc(configSpecLines, docsource, header)[source]¶ Create Sphinx documentation for configspecLines at directory docsource.
- Parameters
configSpecLines (list) – configspec file lines for ConfigObj
docsource (Path) – root directory for documentation.
header (str) – header text for the documentation
-
qcobj.utils.saveSection(section, name, docsource, subpath, header='')[source]¶ Recursively save configobject section and subsections documentation into separate files, one for each section, in a nested folder structure starting at docsource.
- Parameters
section (dict) – dictionary with the sections documentation
name (str) – .rst file name of the document
docsource (Path) – write .rst file starting from this directory
subpath (Path) – subdirctory to which write the .rst document
header (str) – header for the first level (root) of the document
3.3. cfggui Module¶

-
class
qcobj.cfggui.CfgGui(opts)[source]¶ Bases:
PySide2.QtWidgets.QWidget-
_loadQCobjs(pn)[source]¶ Load all QConfigObj instances form file(s) in pn Remove blanks in polygons and create the widgets for every instance.
-
staticMetaObject= <PySide2.QtCore.QMetaObject object>¶
-
-
class
qcobj.cfggui.QuantityDialog(text, parent=None)[source]¶ Bases:
PySide2.QtWidgets.QDialog-
staticMetaObject= <PySide2.QtCore.QMetaObject object>¶
-
-
class
qcobj.cfggui.TreeItem(name='', parent=None, data=None)[source]¶ Bases:
PySide2.QtCore.QObject-
__init__(name='', parent=None, data=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
setData(value, validRange, column)[source]¶ Set node data with value converted to appropriate units as stated in validRange and return it or return None
-
staticMetaObject= <PySide2.QtCore.QMetaObject object>¶
-
-
class
qcobj.cfggui.TreeModel(parent, qcobj=None)[source]¶ Bases:
PySide2.QtCore.QAbstractItemModel-
columnCount(self, parent: PySide2.QtCore.QModelIndex = Invalid(PySide2.QtCore.QModelIndex)) → int[source]¶
-
data(self, index: PySide2.QtCore.QModelIndex, role: int = PySide2.QtCore.Qt.ItemDataRole.DisplayRole) → typing.Any[source]¶
-
headerData(self, section: int, orientation: PySide2.QtCore.Qt.Orientation, role: int = PySide2.QtCore.Qt.ItemDataRole.DisplayRole) → typing.Any[source]¶
-
index(self, row: int, column: int, parent: PySide2.QtCore.QModelIndex = Invalid(PySide2.QtCore.QModelIndex)) → PySide2.QtCore.QModelIndex[source]¶
-
parent(self) → PySide2.QtCore.QObject[source]¶ parent(self, child: PySide2.QtCore.QModelIndex) -> PySide2.QtCore.QModelIndex
-
rowCount(self, parent: PySide2.QtCore.QModelIndex = Invalid(PySide2.QtCore.QModelIndex)) → int[source]¶
-
setData(self, index: PySide2.QtCore.QModelIndex, value: typing.Any, role: int = PySide2.QtCore.Qt.ItemDataRole.EditRole) → bool[source]¶
-
staticMetaObject= <PySide2.QtCore.QMetaObject object>¶
-
-
class
qcobj.cfggui.TreeView(*args)[source]¶ Bases:
PySide2.QtWidgets.QTreeView-
staticMetaObject= <PySide2.QtCore.QMetaObject object>¶
-
-
qcobj.cfggui.deBlank(section, key, wordsPerLine=2)[source]¶ Remove blanks and format with wordsPerLine words per line every value with the key == ‘polygon’
-
qcobj.cfggui.noBlanks(withblanks, wordsPerLine=2)[source]¶ Remove blanks and format with wordsPerLine words per line
3.4. qtCompat Module¶
The main initialization of our PySide2/PyQt5 Package.
Warning
This module tries to import PySide2 if available, otherwise defaults to PyQt5 for the GUI. To change this behaviour set TRY_PYSIDE to False.
- Author
2009-2011 Nicola Creati
2009-2020 Roberto Vidmar
- Copyright
2011-2020 Nicola Creati <ncreati@inogs.it> Roberto Vidmar <rvidmar@inogs.it>
- License
MIT/X11 License (see
license.txt)
-
qcobj.qtCompat.getOpenFileName(*args, **kargs)[source]¶ Wrap to PySide QtWidgets.QFileDialog.getOpenFileName