X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=wizard%2FBBoardPage.py;h=9e70a68a276e017a28fc4186f32dd0a994da3a31;hb=a256e501c16b63a423267f8621d6bdcda20d3f3a;hp=6b8dddfff2bcc84723cc27848afd27460c00d9a2;hpb=cc03eb93224f06debc7f426acd9374076e8be834;p=bertos.git diff --git a/wizard/BBoardPage.py b/wizard/BBoardPage.py index 6b8dddff..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,9 +33,20 @@ # Author: Lorenzo Berni # +import os + +from PyQt4.QtCore import * +from PyQt4.QtGui import * + from BWizardPage import BWizardPage -from const import * +from BCpuPage import BCpuPage +from BOutputPage import BOutputPage +from BRoutePage import BRoutePage + +import const +import qvariant_converter +from bertos_utils import presetList class BBoardPage(BWizardPage): """ @@ -44,5 +55,96 @@ class BBoardPage(BWizardPage): """ def __init__(self): - BWizardPage.__init__(self, UI_LOCATION + "/board_select.ui") + 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 ## + + def isComplete(self): + """ + Overload of the QWizardPage isComplete method. + """ + 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. + """ + return self.wizard().pageIndex(BRoutePage) + + #### + + ## Overloaded BWizardPage methods ## + + def setupUi(self): + """ + Overload of the BWizardPage setupUi method. + """ + pass + + def connectSignals(self): + """ + Overload of the BWizardPage connectSignals method. + """ + self.connect(self.pageContent.boardTree, SIGNAL("itemSelectionChanged()"), self, SIGNAL("completeChanged()")) + + def reloadData(self): + """ + Overload of the BWizardPage reloadData method. + """ + self._fillPresetTree() + + #### + + ## Slots ## + + + #### + + @property + 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