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

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.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.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 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 (can be converted to numpy array with
np.loadtxt(StringIO(polygon)
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:
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:
Returns:

result of qcobj.qconfigobj.val() (d, k) or simply the magnitude of d[k]

class qcobj.qconfigobj.Q_[source]

Bases: pint.unit.Quantity

A Quantity class with user settable preferred units for representation

static __new__(*args, **kargs)[source]
__reduce__()[source]
__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]
exception qcobj.qconfigobj.QConfigObjExtra(value)[source]

Bases: configobj.ConfigObjError

Extra value / section error

__init__(value)[source]
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:
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:
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:

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]
exception qcobj.qconfigobj.VdtDimensionalityError(dim1, dim2)[source]

Bases: validate.ValidateError

Dimensionality error class

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

Bases: validate.ValidateError

Range error class

__init__(value, vmin, vmax, units)[source]
class qcobj.qconfigobj.QValidator(*args, **kargs)[source]

Bases: validate.Validator

A Validator for Quantities

See also

Validator class

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

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.createPolygons(pols, k)[source]
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: PySide.QtCore.QObject

__init__(name='', parent=None, data=None)[source]
name()[source]
appendChild(item)[source]
child(row)[source]
childCount()[source]
columnCount()[source]
data()[source]
parent()[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

staticMetaObject = <PySide.QtCore.QMetaObject object>
class qcobj.cfggui.TreeModel(parent, qcobj=None)[source]

Bases: PySide.QtCore.QAbstractItemModel

__init__(parent, qcobj=None)[source]
columnCount(parent)[source]
data(index, role)[source]
flags(index)[source]

Must be implemented

headerData(section, orientation, role)[source]
index(row, column, parent)[source]
parent(index)[source]
rowCount(parent)[source]
setComparison(qcobj)[source]

Set comparison qcobj for highlighting differences

setData(index, value, role)[source]
setupModelData(qcobj)[source]

Populate model with data from QCconfigObj instance

staticMetaObject = <PySide.QtCore.QMetaObject object>
class qcobj.cfggui.TreeView(*args)[source]

Bases: PySide.QtGui.QTreeView

__init__(*args)[source]
resizeColumns()[source]
staticMetaObject = <PySide.QtCore.QMetaObject object>
class qcobj.cfggui.QuantityDialog(text, parent=None)[source]

Bases: PySide.QtGui.QDialog

__init__(text, parent=None)[source]
staticMetaObject = <PySide.QtCore.QMetaObject object>
class qcobj.cfggui.CfgGui(opts)[source]

Bases: PySide.QtGui.QMainWindow

__init__(opts)[source]
_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(event)[source]
openFile()[source]
staticMetaObject = <PySide.QtCore.QMetaObject object>
saveFile()[source]
toggleExpand(*args)[source]

qtCompat Module

The main initialization of our PySide/PyQt4 Package.

Warning

This module tries to import PySide if available, otherwise defaults to PyQt4 for the GUI. To change this behaviour set _TRY_PYSIDE to False.

Author:
  • 2009-2011 Nicola Creati
  • 2009-2017 Roberto Vidmar
Revision:

$Revision: 56 $ $Date: 2012-11-12 16:14:43 +0100 (Mon, 12 Nov 2012) $

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 PySide

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

Wrap to PySide QtGui.QFileDialog.getOpenFileName

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

Wrap to PySide QtGui.QFileDialog.getOpenFileNames

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

Wrap to PySide QtGui.QFileDialog.getSaveFileName