qcobj Package

qconfigobj Module

Validator errors classes:

Inheritance diagram of qcobj.qconfigobj.VdtDimensionalityError
Inheritance diagram of qcobj.qconfigobj.VdtRangeError
Inheritance diagram of qcobj.qconfigobj.VdtUnitsError

Validator class:

Inheritance diagram of qcobj.qconfigobj.Certifier

QConfigObj classes:

Inheritance diagram of qcobj.qconfigobj.QConfigObj
Inheritance diagram of qcobj.qconfigobj.Q_
Inheritance diagram of qcobj.qconfigobj.QConfigObjExtra
Inheritance diagram of qcobj.qconfigobj.QConfigObjInvalid
qcobj.qconfigobj.colorize(*args)[source]
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) – instance

  • key (string) – an existing key in section

Returns

A qcobj.qconfigobj.Q_ instance like the one at

section[key] with magnitude value

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
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) – instance

  • key (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) – instance

  • key (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) – instance

  • key (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_like

  • k (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.

__reduce__()[source]

helper for pickle

__str__()[source]

Return qcobj.qconfigobj.eng_string() representation of magnitude rounded at 6 decimals with units

__repr__()[source]

Return UnitRegistry Quantity representation

exception qcobj.qconfigobj.QConfigObjInvalid(value)[source]

Bases: configobj.ConfigObjError

Invalid value error

__init__(value)[source]

Initialize self. See help(type(self)) for accurate signature.

exception qcobj.qconfigobj.QConfigObjExtra(value)[source]

Bases: configobj.ConfigObjError

Extra value / section error

__init__(value)[source]

Initialize self. See help(type(self)) for accurate signature.

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

_saveErrors()[source]

Save errors in a configuration file in terse format

_extra()[source]

Save extra values / sections in instance

_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) – instance

  • key (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) – instance

  • key (string) – valid key in section

Returns

Return reference quantity for section[key]

Note

At present USED ONLY IN :class: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) – instance

  • key (string) – valid key in section

  • value (float or int) – new value

Note

At present used only in addMag and setMag

write_to_string()[source]

Return write content in a string

Returns

Return write content in a string

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

__init__(value)[source]

Initialize self. See help(type(self)) for accurate signature.

exception qcobj.qconfigobj.VdtDimensionalityError(dim1, dim2)[source]

Bases: validate.ValidateError

Dimensionality error class

__init__(dim1, dim2)[source]

Initialize self. See help(type(self)) for accurate signature.

exception qcobj.qconfigobj.VdtRangeError(value, vmin, vmax, units)[source]

Bases: validate.ValidateError

Range error class

__init__(value, vmin, vmax, units)[source]

Initialize self. See help(type(self)) for accurate signature.

exception qcobj.qconfigobj.VdtLengthError(value, nmin, nmax)[source]

Bases: validate.ValidateError

List length error class

__init__(value, nmin, nmax)[source]

Initialize self. See help(type(self)) for accurate signature.

class qcobj.qconfigobj.Certifier(*args, **kargs)[source]

Bases: validate.Validator

A Validator for Quantities

See also

Validator class

__init__(*args, **kargs)[source]
>>> vtri = Validator()
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

Inheritance diagram of qcobj.cfggui
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’

qcobj.cfggui.colorize(s, color)[source]

Return an HTML colorized string for s

qcobj.cfggui.getPath(index)[source]

Return section path at index

qcobj.cfggui.valueAtPath(cobj, path, name)[source]

Return cobj value at path or raise RuntimeError

class qcobj.cfggui.TreeItem(name='', parent=None, data=None)[source]

Bases: PyQt5.QtCore.QObject

__init__(name='', parent=None, data=None)[source]

Initialize self. See help(type(self)) for accurate signature.

name()[source]
appendChild(item)[source]
child(row)[source]
childCount()[source]
columnCount()[source]
data()[source]
parent(self) → QObject[source]
row()[source]
setData(value, validRange, column)[source]

Set node data with value converted to appropriate units as stated in validRange and return it or return None

class qcobj.cfggui.TreeModel(parent, qcobj=None)[source]

Bases: PyQt5.QtCore.QAbstractItemModel

__init__(parent, qcobj=None)[source]

Initialize self. See help(type(self)) for accurate signature.

columnCount(self, parent: QModelIndex = QModelIndex()) → int[source]
data(self, QModelIndex, role: int = Qt.DisplayRole) → Any[source]
flags(index)[source]

Must be implemented

headerData(self, int, Qt.Orientation, role: int = Qt.DisplayRole) → Any[source]
index(self, int, int, parent: QModelIndex = QModelIndex()) → QModelIndex[source]
parent(self, QModelIndex) → QModelIndex[source]

parent(self) -> QObject

rowCount(self, parent: QModelIndex = QModelIndex()) → int[source]
setComparison(qcobj)[source]

Set comparison qcobj for highlighting differences

setData(self, QModelIndex, Any, role: int = Qt.EditRole) → bool[source]
setupModelData(qcobj)[source]

Populate model with data from QCconfigObj instance

class qcobj.cfggui.TreeView(*args)[source]

Bases: PyQt5.QtWidgets.QTreeView

__init__(*args)[source]

Initialize self. See help(type(self)) for accurate signature.

resizeColumns()[source]
class qcobj.cfggui.QuantityDialog(text, parent=None)[source]

Bases: PyQt5.QtWidgets.QDialog

__init__(text, parent=None)[source]

Initialize self. See help(type(self)) for accurate signature.

class qcobj.cfggui.CfgGui(opts)[source]

Bases: PyQt5.QtWidgets.QWidget

__init__(opts)[source]

Initialize self. See help(type(self)) for accurate signature.

_loadQCobjs(pn)[source]

Load all QConfigObj instances form file(s) in pn Remove blanks in polygons and create the widgets for every instance.

setFileChanged(filename)[source]
closeEvent(self, QCloseEvent)[source]
openFile()[source]
saveFile()[source]
toggleExpand(*args)[source]

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._pyside_import_module(moduleName)[source]

The import for PySide

qcobj.qtCompat._pyqt4_import_module(moduleName)[source]

The import for PyQt4

qcobj.qtCompat.import_module(moduleName)

The import for PyQt4

qcobj.qtCompat.getOpenFileName(*args, **kargs)[source]

Wrap to PyQt4 QtWidgets.QFileDialog.getOpenFileName

qcobj.qtCompat.getOpenFileNames(*args, **kargs)[source]

Wrap to PyQt4 QtWidgets.QFileDialog.getOpenFileNames

qcobj.qtCompat.getSaveFileName(*args, **kargs)[source]

Wrap to PyQt4 QtWidgets.QFileDialog.getSaveFileName