from const import *
class BModulePage(BWizardPage):
+ """
+ Page of the wizard that permits to select and configurate the BeRTOS modules.
+ """
def __init__(self):
BWizardPage.__init__(self, UI_LOCATION + "/module_select.ui")
self._connectSignals()
def reloadData(self):
+ """
+ Overload of the BWizardPage reloadData method.
+ """
QApplication.instance().setOverrideCursor(Qt.WaitCursor)
self._setupUi()
self._loadModuleData()
QApplication.instance().restoreOverrideCursor()
def _setupButtonGroup(self):
+ """
+ Sets up the button group.
+ """
self._button_group = QButtonGroup()
self._button_group.setExclusive(False)
self.connect(self._button_group, SIGNAL("buttonClicked(int)"), self._moduleSelectionChanged)
def _loadModuleData(self):
+ """
+ Loads the module data.
+ """
## Load the module data only if it isn't already loaded
if self._projectInfoRetrieve("MODULES") == None \
and self._projectInfoRetrieve("LISTS") == None \
self._exceptionOccurred(self.tr("Error parsing line '%2' in file %1").arg(e.path).arg(e.line))
def _fillModuleTree(self):
+ """
+ Fills the module tree with the module entries separated in categories.
+ """
modules = self._projectInfoRetrieve("MODULES")
if modules is None:
return
def _fillPropertyTable(self):
+ """
+ Slot called when the user selects a module from the module tree.
+ Fills the property table using the configuration parameters defined in
+ the source tree.
+ """
module = self._currentModule()
if module is not None:
self._control_group.clear()
self.pageContent.moduleLabel.setText(module_label)
def _insertCheckBox(self, index, value):
- ## boolean property
+ """
+ Inserts in the table at index a checkbox for a boolean property setted
+ to value.
+ """
check_box = QCheckBox()
self.pageContent.propertyTable.setCellWidget(index, 1, check_box)
if value == "1":
self._control_group.addControl(index, check_box)
def _insertComboBox(self, index, value, value_list):
- ## enum property
+ """
+ Inserts in the table at index a combobox for an enum property setted
+ to value.
+ """
try:
enum = self._projectInfoRetrieve("LISTS")[value_list]
combo_box = QComboBox()
self.pageContent.propertyTable.setItem(index, 1, QTableWidgetItem(value))
def _insertSpinBox(self, index, value, informations):
+ """
+ Inserts in the table at index a spinbox for an int, a long or an unsigned
+ long property setted to value.
+ """
## int, long or undefined type property
spin_box = None
if bertos_utils.isLong(informations) or bertos_utils.isUnsignedLong(informations):
def _currentModule(self):
+ """
+ Retuns the current module name.
+ """
current_module = self.pageContent.moduleTree.currentItem()
# return only the child items
if current_module is not None and current_module.parent() is not None:
return None
def _currentModuleConfigurations(self):
+ """
+ Returns the current module configuration.
+ """
return self._configurations(self._currentModule())
def _currentProperty(self):
+ """
+ Rerturns the current property from the property table.
+ """
return qvariant_converter.getString(self.pageContent.propertyTable.item(self.pageContent.propertyTable.currentRow(), 0).data(Qt.UserRole))
def _currentPropertyItem(self):
+ """
+ Returns the QTableWidgetItem of the current property.
+ """
return self.pageContent.propertyTable.item(self.pageContent.propertyTable.currentRow(), 0)
def _configurations(self, module):
+ """
+ Returns the configuration for the selected module.
+ """
configuration = self._projectInfoRetrieve("MODULES")[module]["configuration"]
if len(configuration) > 0:
return self._projectInfoRetrieve("CONFIGURATIONS")[configuration]
return {}
def _resetPropertyDescription(self):
+ """
+ Resets the label for each property table entry.
+ """
for index in range(self.pageContent.propertyTable.rowCount()):
property_name = qvariant_converter.getString(self.pageContent.propertyTable.item(index, 0).data(Qt.UserRole))
# Awful solution! Needed because if the user change the module, the selection changed...
self.pageContent.propertyTable.item(index, 0).setText(self._currentModuleConfigurations()[property_name]['brief'])
def _showPropertyDescription(self):
+ """
+ Slot called when the property selection changes. Shows the description
+ of the selected property.
+ """
self._resetPropertyDescription()
configurations = self._currentModuleConfigurations()
if self._currentProperty() in configurations.keys():
self._currentPropertyItem().setText(description + "\n" + name)
def _setupUi(self):
+ """
+ Set up the user interface.
+ """
self.pageContent.moduleTree.clear()
self.pageContent.moduleTree.setHeaderHidden(True)
self.pageContent.propertyTable.horizontalHeader().setResizeMode(QHeaderView.Stretch)
self.pageContent.moduleLabel.setVisible(False)
def _connectSignals(self):
+ """
+ Connect the signals with the related slots.
+ """
self.connect(self.pageContent.moduleTree, SIGNAL("itemPressed(QTreeWidgetItem*, int)"), self._fillPropertyTable)
self.connect(self.pageContent.moduleTree, SIGNAL("itemChanged(QTreeWidgetItem*, int)"), self._dependencyCheck)
self.connect(self.pageContent.propertyTable, SIGNAL("itemSelectionChanged()"), self._showPropertyDescription)
self.connect(self._control_group, SIGNAL("stateChanged"), self._saveValue)
def _saveValue(self, index):
+ """
+ Slot called when the user modifies one of the configuration parameters.
+ It stores the new value."""
property = qvariant_converter.getString(self.pageContent.propertyTable.item(index, 0).data(Qt.UserRole))
configuration = self._projectInfoRetrieve("MODULES")[self._currentModule()]["configuration"]
configurations = self._projectInfoRetrieve("CONFIGURATIONS")
self._projectInfoStore("CONFIGURATIONS", configurations)
def _moduleSelectionChanged(self, index):
+ """
+ Slot called when the user selects or unselects a module from the module
+ tree.
+ """
module = unicode(self.pageContent.moduleTable.item(index, 1).text())
if self._button_group.button(index).isChecked():
self._moduleSelected(module)
self._moduleUnselected(module)
def _dependencyCheck(self, item):
+ """
+ Checks the dependencies of the module associated with the given item.
+ """
checked = False
module = unicode(item.text(0))
if item.checkState(0) == Qt.Checked:
self.removeFileDependencies(module)
def _moduleSelected(self, selectedModule):
+ """
+ Resolves the selection dependencies.
+ """
modules = self._projectInfoRetrieve("MODULES")
modules[selectedModule]["enabled"] = True
self._projectInfoStore("MODULES", modules)
item.child(child).setCheckState(0, Qt.Checked)
def _moduleUnselected(self, unselectedModule):
+ """
+ Resolves the unselection dependencies.
+ """
modules = self._projectInfoRetrieve("MODULES")
modules[unselectedModule]["enabled"] = False
self._projectInfoStore("MODULES", modules)
item.child(child).setCheckState(0, Qt.Unchecked)
def selectDependencyCheck(self, module):
+ """
+ Returns the list of unsatisfied dependencies after a selection.
+ """
unsatisfied = set()
modules = self._projectInfoRetrieve("MODULES")
files = self._projectInfoRetrieve("FILES")
return unsatisfied
def unselectDependencyCheck(self, dependency):
+ """
+ Returns the list of unsatisfied dependencies after an unselection.
+ """
unsatisfied = set()
modules = self._projectInfoRetrieve("MODULES")
for module, informations in modules.items():
return unsatisfied
def removeFileDependencies(self, module):
+ """
+ Removes the files dependencies of the given module.
+ """
modules = self._projectInfoRetrieve("MODULES")
files = self._projectInfoRetrieve("FILES")
dependencies = modules[module]["depends"]
self._projectInfoStore("FILES", files)
class QControlGroup(QObject):
+ """
+ Simple class that permit to connect different signals of different widgets
+ with a slot that emit a signal. Permits to group widget and to understand which of
+ them has sent the signal.
+ """
+
def __init__(self):
QObject.__init__(self)
self._controls = {}
def addControl(self, id, control):
+ """
+ Add a control.
+ """
self._controls[id] = control
if type(control) == QCheckBox:
self.connect(control, SIGNAL("stateChanged(int)"), lambda: self._stateChanged(id))
self.connect(control, SIGNAL("valueChanged(double)"), lambda: self._stateChanged(id))
def clear(self):
+ """
+ Remove all the controls.
+ """
self._controls = {}
def _stateChanged(self, id):
+ """
+ Slot called when the value of one of the stored widget changes. It emits
+ another signal.
+ """
self.emit(SIGNAL("stateChanged"), id)
\ No newline at end of file