X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=wizard%2FBBoardPage.py;h=9e70a68a276e017a28fc4186f32dd0a994da3a31;hb=ab03b5b37726fb8b39a6f6c915f8668bddd779ee;hp=28130c9e4f5cb69cdde79c1662f439df3e247bee;hpb=4b0ca7f4b9df26e052b13a9d6b99f693047b63cc;p=bertos.git diff --git a/wizard/BBoardPage.py b/wizard/BBoardPage.py index 28130c9e..9e70a68a 100644 --- a/wizard/BBoardPage.py +++ b/wizard/BBoardPage.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # encoding: utf-8 # -# This file is part of slimqc. +# This file is part of bertos. # # Bertos is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,6 +33,8 @@ # Author: Lorenzo Berni # +import os + from PyQt4.QtCore import * from PyQt4.QtGui import * @@ -40,6 +42,7 @@ from BWizardPage import BWizardPage from BCpuPage import BCpuPage from BOutputPage import BOutputPage +from BRoutePage import BRoutePage import const import qvariant_converter @@ -62,24 +65,23 @@ class BBoardPage(BWizardPage): """ Overload of the QWizardPage isComplete method. """ - return self.pageContent.boardList.currentItem() is not None + if self.selected: + _info_dict = qvariant_converter.getDict(self.selected.data(0, Qt.UserRole)) + _type = _info_dict["type"] + type = qvariant_converter.getString(_type) + if type == "project": + self.setProjectInfo("PROJECT_PRESET", qvariant_converter.getString(_info_dict["path"])) + return True + else: + return False + else: + return False def nextId(self): """ Overload of the QWizardPage nextId method. """ - # Stub of nextId logic - if self.advanced: - self.setProjectInfo("PRESET_ADVANCED_CONFIG", True) - return self.wizard().pageIndex(BCpuPage) - # Search for suitable toolchains. If there isn't one return - # BToolchainPage id (BToolchainPage should then route to BOutputPage - # instead of BModulePage). - - # If a suitable toolchain is found the user has to be prompted - # directly to the BOutputPage - else: - return self.wizard().pageIndex(BOutputPage) + return self.wizard().pageIndex(BRoutePage) #### @@ -95,49 +97,54 @@ class BBoardPage(BWizardPage): """ Overload of the BWizardPage connectSignals method. """ - self.connect(self.pageContent.boardList, SIGNAL('itemSelectionChanged()'), self.itemSelectionChanged) + self.connect(self.pageContent.boardTree, SIGNAL("itemSelectionChanged()"), self, SIGNAL("completeChanged()")) def reloadData(self): """ Overload of the BWizardPage reloadData method. """ - presets = presetList("/Users/duplo/Development/bertos") - self.setProjectInfo("PRESETS", presets) - self.populatePresetList() - - def populatePresetList(self): - self.pageContent.boardList.clear() - presets = self.projectInfo("PRESETS") - for preset, info in presets.items(): - board_list = self.pageContent.boardList - item = QListWidgetItem(info["PRESET_NAME"], board_list) - item.setData(Qt.UserRole, qvariant_converter.convertString(preset)) - if self._last_selected == preset: - self.pageContent.boardList.setCurrentItem(item) - if not self._last_selected and self.pageContent.boardList.count(): - self.pageContent.boardList.setCurrentRow(0) + self._fillPresetTree() #### ## Slots ## - def itemSelectionChanged(self): - preset_path = qvariant_converter.getString(self.pageContent.boardList.currentItem().data(Qt.UserRole)) - presets = self.projectInfo("PRESETS") - selected_preset = presets[preset_path] - text_components = [ - "Board: %s" %selected_preset["PRESET_NAME"], - "CPU: %s" %selected_preset["CPU_NAME"], - ] - if selected_preset["PRESET_DESCRIPTION"]: - text_components.append("Description: %s" %selected_preset["PRESET_DESCRIPTION"]) - text = "\n".join(text_components) - self.pageContent.descriptionLabel.setText(text) - self._last_selected = preset_path - self.emit(SIGNAL("completeChanged()")) #### @property - def advanced(self): - return self.pageContent.advancedCheckBox.isChecked() \ No newline at end of file + def selected(self): + # We can only take the selected item list (not the single item) + _selected_items = self.pageContent.boardTree.selectedItems() + if _selected_items: + return _selected_items[0] + else: + return None + + def _fillPresetTree(self): + self.pageContent.boardTree.clear() + 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): + selected_item_name = self.projectInfo("PROJECT_PRESET") + item_name = obj["info"].get("name", obj["info"]["filename"]) + item = QTreeWidgetItem(parent, [item_name]) + item.setIcon(0, QIcon(self._getNodeIcon(obj))) + children_dict = obj["children"] + item.setData(0, Qt.UserRole, qvariant_converter.convertDict(obj["info"])) + if obj["info"]["path"] == selected_item_name: + self.pageContent.boardTree.setCurrentItem(item) + for child in children_dict: + self._createPresetNode(item, child) + + def _getNodeIcon(self, obj): + icon_file = os.path.join(obj["info"]["path"], const.PREDEFINED_BOARD_ICON_FILE) + if os.path.exists(icon_file): + return icon_file + elif obj["info"]["type"] == "dir": + return const.PREDEFINED_BOARD_DEFAULT_DIR_ICON + else: + return const.PREDEFINED_BOARD_DEFAULT_PROJECT_ICON