X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=wizard%2FBBoardPage.py;h=6d7fc89b4d0347261ded550efb51f19b52f07202;hb=8f2036c05d9a8531400c1ab97dca9193e92187d3;hp=21363e7a0b3738fabfa26410fe77ed05b9037cff;hpb=dd6d39a11bc6fc8a60bc334d36b8b065d26abbf7;p=bertos.git diff --git a/wizard/BBoardPage.py b/wizard/BBoardPage.py index 21363e7a..6d7fc89b 100644 --- a/wizard/BBoardPage.py +++ b/wizard/BBoardPage.py @@ -33,6 +33,8 @@ # Author: Lorenzo Berni # +import os + from PyQt4.QtCore import * from PyQt4.QtGui import * @@ -44,7 +46,7 @@ from BRoutePage import BRoutePage import const import qvariant_converter -from bertos_utils import presetList +from bertos_utils import presetList, _cmp class BBoardPage(BWizardPage): """ @@ -55,7 +57,6 @@ class BBoardPage(BWizardPage): 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 ## @@ -63,13 +64,22 @@ class BBoardPage(BWizardPage): """ Overload of the QWizardPage isComplete method. """ - return False + 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) + self.setProjectInfo("PROJECT_FROM_PRESET", True) + return True + else: + return False def nextId(self): - """ - Overload of the QWizardPage nextId method. - """ - return self.wizard().pageIndex(BRoutePage) + wizard = self.wizard() + if not self.projectInfo("PROJECT_FROM_PRESET"): + return wizard.pageIndex(BCpuPage) + else: + return QWizardPage.nextId(self) #### @@ -85,18 +95,57 @@ class BBoardPage(BWizardPage): """ 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()")) + self.connect(self.pageContent.customButton, SIGNAL("clicked()"), self.customButtonClicked) def reloadData(self): """ Overload of the BWizardPage reloadData method. """ self.project.loadProjectPresets() + preset_list = self.projectInfo("PRESET_TREE") + preset_list = preset_list["children"] + 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 customButtonClicked(self): + self.setProjectInfo("PROJECT_FROM_PRESET", False) + self.wizard().next() #### + 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 = const.PREDEFINED_BOARD_DEFAULT_ICON + 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