configeditor

Models for configobj objects

jukebox.core.gui.configeditor.ConfigObjModel represents one ConfigObj and is designed for TreeViews. jukeboxcore.gui.configeditor.InifilesModel is designed for listviews and represents multiple ConfigObjs.

class jukeboxcore.gui.configeditor.ConfigObjModel(conf, parent=None)[source]

Bases: PySide.QtCore.QAbstractItemModel

Model for ConfigObj

A ConfigObj is a tree structured ordered dictionary. It represents ini-Files. There can also be a config specification. You can validate your ConfigObj against that specification. The model holds the configobj and can extract data like keys, values, specification. It should be used with a tree view because you can nest sections inside your ini.

The data is validated life. So invalid or valid values get different forground roles.

The internal pointers of the indices are the sections of the ConfigObj. The three columns are key, value, spec.

Constructs a new config obj model

Parameters:
  • conf (configobj.ConfigObj) – the ConfigObj with its spec already set!.
  • parent (PySide.QtCore.QObject) – the parent object
Returns:

None

Return type:

None

Raises:

None

rowCount(parent)[source]

Reimplemented from QtCore.QAbstractItemModel

columnCount(parent)[source]

Reimplemented from QtCore.QAbstractItemModel

3 Columns: Key, Value, Spec

data(index, role=PySide.QtCore.Qt.ItemDataRole.DisplayRole)[source]

Reimplemented from QtCore.QAbstractItemModel

The value gets validated and is red if validation fails and green if it passes.

setData(index, value, role=PySide.QtCore.Qt.ItemDataRole.EditRole)[source]

Reimplemented from QtCore.QAbstractItemModel

You can only set the value.

Parameters:
  • index (PySide.QtCore.QModelIndex) – the index to edit, column should be 1.
  • value (object) – the new value for the configobj
  • role (QtCore.Qt.ItemDataRole) – Optional - the ItemDataRole. Default is QtCore.Qt.EditRole
Returns:

True if index was edited, False if index could not be edited.

Return type:

bool

Raises:

None

restore_default(index)[source]

Set the value of the given index row to its default

Parameters:index
Returns:
Return type:
Raises:
headerData(section, orientation, role)[source]

Reimplemented from QtCore.QAbstractItemModel

Just the header text for the 3 columns. Rows do not have headers.

flags(index)[source]

Reimplemented from QtCore.QAbstractItemModel

Only the value is editable

parent(index)[source]

Reimplemented from QtCore.QAbstractItemModel

index(row, column, parent)[source]

Reimplemented from QtCore.QAbstractItemModel

The internal pointer is the section. The row determines the key in the scalars then sections of the configobj. So for a given index, use row to retrieve the key:

key = self.get_key(index.internalPointer(), index.row())

To use the key on the section to get the value OR use get_value(index) / get_configspec_str

get_value(index)[source]

Return the value of the given index

The index stores the section as internal pointer. The row of the index determines the key. The key is used on the section to return the value

Parameters:index (QModelIndex) – The QModelIndex
Returns:The value for the given index
get_configspec_str(index)[source]

Return the config spec string of the given index

The index stores the section as internal pointer. The row of the index determines the key. The section stores the spec in its configspec attribute The key is used on the configspec attribute to return the spec

Parameters:index (QModelIndex) – The QModelIndex
Returns:The spec for the given index or None
get_key(section, row)[source]

Return the key for the given section and row

A sections stores scalars and sections. The row is the index for the combination of scalars and sections.

Parameters:
  • section (Section) – A ConfigObj section
  • row (int) – the index for (section.scalars + section.sections)
Returns:

the key

Return type:

str

Raises:

IndexError

set_valid_col(color)[source]

Set the forgroundrole color for values if they are valid

Parameters:color (QtGui.QColor) – this color will be returned from data() when the value is valid and role is QtCore.Qt.ForegroundRole
Returns:None
Return type:None
Raises:None

default is: QtGui.QColor(105, 205, 105)

set_invalid_col(color)[source]

Set the forgroundrole color for values if they are valid

Parameters:color (QtGui.QColor) – this color will be returned from data() when the value is valid and role is QtCore.Qt.ForegroundRole
Returns:None
Return type:None
Raises:None

default is: QtGui.QColor(250, 135, 135)

staticMetaObject = <PySide.QtCore.QMetaObject object at 0x0000000004F742C8>
class jukeboxcore.gui.configeditor.InifilesModel(configs, parent=None)[source]

Bases: PySide.QtCore.QAbstractListModel

A list model for inifiles

Stores multiple configobjs in a list that represent inifiles on the harddisk.

Constructs a new model with the given ConfigObjs

Parameters:
  • configs (list of ConfigObjs) – the configobjs to display
  • parent (QObject) – the parent qobject
Returns:

None

Raises:

None

confobjRole = PySide.QtCore.Qt.ItemDataRole.UserRole
rowCount(parent=None)[source]

Reimplemented from QAbstractItemModel

Parameters:parent (QModelIndex) – The parent index
Returns:the number of configs
Return type:int
Raises:None
data(index, role)[source]

Reimplemented from QtCore.QAbstractItemModel

Parameters:
  • index (QModelIndex) – the index
  • role (QtCore.Qt.ItemDataRole) – the data role
Returns:

some data. for display role it returns the filename of the configobj

Raises:

None

For display role the filename is returned.

headerData(section, orientation, role)[source]

Returns the data for the given role and section in the header with the specified orientation.

Parameters:
  • section (int) – the section
  • orientation (QtCore.Qt.Orientation) – horizontal or vertical orientation
  • role (QtCore.Qt.ItemDataRole) – the datarole. default is DisplayRole
Returns:

headerData

Raises:

None

set_index_edited(index, edited)[source]

Set whether the conf was edited or not.

Edited files will be displayed with a ‘*’

Parameters:
  • index (QModelIndex) – the index that was edited
  • edited (bool) – if the file was edited, set edited to True, else False
Returns:

None

Return type:

None

Raises:

None

get_edited()[source]

Return all indices that were modified

Returns:list of indices for modified confs
Return type:list of QModelIndex
Raises:None
validate(index)[source]

Validate the conf for the given index

Parameters:index (QModelIndex) – the index of the model to validate
Returns:True if passed and a False/True dict representing fail/pass. The structure follows the configobj. If the configobj does not have a configspec True is returned.
Return type:True|Dict
Raises:None
staticMetaObject = <PySide.QtCore.QMetaObject object at 0x0000000004F764C8>