qcobj
Package¶
qconfigobj
Module¶
Validator errors classes:



Validator class:

QConfigObj classes:




-
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.
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.
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.
msec2cmyear
(ms)[source]¶ Return m/s converted to cm/year Quantity
- Parameters
ms (float) – meters per second
- Returns
cm / year
-
qcobj.qconfigobj.
errors
(cobj, ok)[source]¶ Return errors in a configuration file in terse format
- Parameters
cobj (
qcobj.qconfigobj.QConfigObj
instance) – instanceok (dict) – results dictionary returned by validate
- Returns
error messages 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.
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.
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.Section
instance) – dict_likek (string) – key in d
- Returns
result of
qcobj.qconfigobj.val()
(d, k) or simply the magnitude of d[k]
-
class
qcobj.qconfigobj.
Q_
[source]¶ Bases:
pint.quantity.Quantity
A 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.
-
__str__
()[source]¶ Return
qcobj.qconfigobj.eng_string()
representation of magnitude rounded at 6 decimals with units
-
static
-
exception
qcobj.qconfigobj.
QConfigObjInvalid
(value)[source]¶ Bases:
configobj.ConfigObjError
Invalid value error
-
exception
qcobj.qconfigobj.
QConfigObjExtra
(value)[source]¶ Bases:
configobj.ConfigObjError
Extra value / section error
-
class
qcobj.qconfigobj.
_QConfigObj
(*args, **kargs)[source]¶ Bases:
configobj.ConfigObj
A Quantity aware ConfigObj class
-
__init__
(*args, **kargs)[source]¶ Create a new instance. kargs are from 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
-
validRange
(path, key)[source]¶ Return valid range for quantity key at path
- Parameters
path (list) – list of section names
key (string) – valid key in section at path
- Returns
valid range for quantity 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 :class:GMOD2.boundaryCondition
-
-
class
qcobj.qconfigobj.
QConfigObj
(*args, **kargs)[source]¶ Bases:
qcobj.qconfigobj._QConfigObj
A Quantity aware ConfigObj class with CONFIGFILES_KEY support
-
__init__
(*args, **kargs)[source]¶ Create a new instance. kargs are from 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.
VdtUnitsError
(value)[source]¶ Bases:
validate.ValidateError
Missing units keyword in quantity type specifier
-
exception
qcobj.qconfigobj.
VdtDimensionalityError
(dim1, dim2)[source]¶ Bases:
validate.ValidateError
Dimensionality error class
-
exception
qcobj.qconfigobj.
VdtRangeError
(value, vmin, vmax, units)[source]¶ Bases:
validate.ValidateError
Range error class
-
exception
qcobj.qconfigobj.
VdtLengthError
(value, nmin, nmax)[source]¶ Bases:
validate.ValidateError
List length error class
-
class
qcobj.qconfigobj.
Certifier
(*args, **kargs)[source]¶ Bases:
validate.Validator
A 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]
-
cfggui
Module¶

-
qcobj.cfggui.
split_list
(L, n, stringify=True)[source]¶ Return a generator with the list L splitted in groups of n elements. If stringify evaluates as true, the groups of n elements are joined and terminated by
-
qcobj.cfggui.
noBlanks
(withblanks, wordsPerLine=2)[source]¶ Remove blanks and format with wordsPerLine words per line
-
qcobj.cfggui.
deBlank
(section, key, wordsPerLine=2)[source]¶ Remove blanks and format with wordsPerLine words per line every value with the key == ‘polygon’
-
class
qcobj.cfggui.
TreeItem
(name='', parent=None, data=None)[source]¶ Bases:
PyQt5.QtCore.QObject
qtCompat
Module¶
The main initialization of our PySide/PyQt4/pyQt5 Package.
Warning
This module tries to import PySide if available, otherwise defaults to PyQt4/PyQt5 for the GUI. To change this behaviour set _TRY_PYSIDE to False.
- Author
2009-2011 Nicola Creati
2009-2018 Roberto Vidmar
- Copyright
2011-2012 Nicola Creati <ncreati@inogs.it> Roberto Vidmar <rvidmar@inogs.it>
- License
MIT/X11 License (see
license.txt
)
-
qcobj.qtCompat.
import_module
(moduleName)¶ The import for PyQt4
-
qcobj.qtCompat.
getOpenFileName
(*args, **kargs)[source]¶ Wrap to PyQt4 QtWidgets.QFileDialog.getOpenFileName