X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=wizard%2FBBoardPage.py;h=301d46b7c36383abe30aa6a5aa50c11375d88686;hb=c34de402cec6fda7bf4474f32fed5e5c02cd7e7e;hp=5d83fda38ddab5a030171e445baee875e5f2b597;hpb=f0c8799f695c20bda1134592ac357620af6cc9fd;p=bertos.git diff --git a/wizard/BBoardPage.py b/wizard/BBoardPage.py index 5d83fda3..301d46b7 100644 --- a/wizard/BBoardPage.py +++ b/wizard/BBoardPage.py @@ -46,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): """ @@ -64,13 +64,14 @@ class BBoardPage(BWizardPage): """ 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 #### @@ -86,6 +87,8 @@ class BBoardPage(BWizardPage): """ Overload of the BWizardPage connectSignals method. """ + self.connect(self.pageContent.boardList, SIGNAL("itemSelectionChanged()"), self.updateUi) + self.connect(self.pageContent.boardList, SIGNAL("itemSelectionChanged()"), self, SIGNAL("completeChanged()")) def reloadData(self): """ @@ -93,19 +96,42 @@ class BBoardPage(BWizardPage): """ 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, _cmp) + 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 setItems(self, preset_list): self.pageContent.boardList.clear() - for item in preset_list: - self.pageContent.boardList.addItem(item["info"].get("name", item["info"]["filename"])) \ No newline at end of file + 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