# Author: Lorenzo Berni <duplo@develer.com>
#
+import os
+
from PyQt4.QtCore import *
from PyQt4.QtGui import *
def __init__(self):
BWizardPage.__init__(self, const.UI_LOCATION + "/board_select.ui")
self.setTitle(self.tr("Select the board from the predefined ones"))
- self._last_selected = None
## Overloaded QWizardPage methods ##
"""
Overload of the QWizardPage isComplete method.
"""
- return False
-
- def nextId(self):
- """
- Overload of the QWizardPage nextId method.
- """
- return self.wizard().pageIndex(BRoutePage)
+ if self.selected:
+ preset_path = qvariant_converter.getDict(self.selected.data(Qt.UserRole))
+ preset_path = qvariant_converter.getStringDict(preset_path["info"])
+ preset_path = preset_path["path"]
+ self.setProjectInfo("PROJECT_BOARD", preset_path)
+ return True
+ else:
+ return False
####
"""
Overload of the BWizardPage connectSignals method.
"""
- pass
+ self.connect(self.pageContent.boardList, SIGNAL("itemSelectionChanged()"), self.updateUi)
+ self.connect(self.pageContent.boardList, SIGNAL("itemSelectionChanged()"), self, SIGNAL("completeChanged()"))
def reloadData(self):
"""
Overload of the BWizardPage reloadData method.
"""
- self._fillPresetTree()
+ preset_list = self.projectInfo("PRESET_TREE")
+ preset_list = preset_list["children"]
+ def _cmp(x, y):
+ return cmp(x["info"].get('ord', 0), y["info"].get('ord', 0))
+ preset_list = sorted(preset_list.values(), _cmp)
+ self.setItems(preset_list)
####
## Slots ##
+ def updateUi(self):
+ if self.selected:
+ info_dict = qvariant_converter.getDict(self.selected.data(Qt.UserRole))
+ info_dict = qvariant_converter.getStringDict(info_dict["info"])
+ description = info_dict.get("description", "")
+ image = os.path.join(info_dict["path"], ".image.png")
+ if os.path.exists(image):
+ self.pageContent.imageLabel.setPixmap(QPixmap(image))
+ self.pageContent.imageLabel.setVisible(True)
+ else:
+ self.pageContent.imageLabel.setVisible(False)
+ self.pageContent.descriptionLabel.setText(description)
####
- def _fillPresetTree(self):
- self.project.loadProjectPresets()
- preset_tree = self.project.info("PRESET_TREE")
- for obj in preset_tree['children']:
- self._createPresetNode(self.pageContent.boardTree, obj)
-
- def _createPresetNode(self, parent, obj):
- item_name = obj['info'].get('name', obj['info']['filename'])
- item = QTreeWidgetItem(parent, [item_name])
- children_dict = obj['children']
- for child in children_dict:
- self._createPresetNode(item, child)
+ def setItems(self, preset_list):
+ self.pageContent.boardList.clear()
+ selected_board = self.projectInfo("PROJECT_BOARD")
+ for item_data in preset_list:
+ item_name = item_data["info"].get("name", item_data["info"]["filename"])
+ item_icon = os.path.join(item_data["info"]["path"], const.PREDEFINED_BOARD_ICON_FILE)
+ if not os.path.exists(item_icon):
+ item_icon = ":/images/default_board_icon.png"
+ item = QListWidgetItem(QIcon(item_icon), item_name)
+ item.setData(Qt.UserRole, qvariant_converter.convertDict(item_data))
+ self.pageContent.boardList.addItem(item)
+ if selected_board and selected_board == item_data["info"]["path"]:
+ self.pageContent.boardList.setCurrentItem(item)
+
+ @property
+ def selected(self):
+ return self.pageContent.boardList.currentItem()
\ No newline at end of file