X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=wizard%2FBBoardPage.py;h=03f96048202ba2a00a7a0458930c48aaa64c0dff;hb=HEAD;hp=28130c9e4f5cb69cdde79c1662f439df3e247bee;hpb=4b0ca7f4b9df26e052b13a9d6b99f693047b63cc;p=bertos.git diff --git a/wizard/BBoardPage.py b/wizard/BBoardPage.py index 28130c9e..03f96048 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 @@ -28,22 +28,22 @@ # # Copyright 2010 Develer S.r.l. (http://www.develer.com/) # -# $Id$ # # Author: Lorenzo Berni # +import os + from PyQt4.QtCore import * from PyQt4.QtGui import * from BWizardPage import BWizardPage from BCpuPage import BCpuPage -from BOutputPage import BOutputPage import const import qvariant_converter -from bertos_utils import presetList +from bertos_utils import presetList, _cmp class BBoardPage(BWizardPage): """ @@ -53,8 +53,7 @@ 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 + self.setTitle(self.tr("Select your development board")) ## Overloaded QWizardPage methods ## @@ -62,24 +61,23 @@ class BBoardPage(BWizardPage): """ Overload of the QWizardPage isComplete method. """ - return self.pageContent.boardList.currentItem() is not None + 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) + self.setProjectInfo("PRESET_LOADED", False) + return True + 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 + wizard = self.wizard() + if not self.projectInfo("PROJECT_FROM_PRESET"): + return wizard.pageIndex(BCpuPage) else: - return self.wizard().pageIndex(BOutputPage) + return QWizardPage.nextId(self) #### @@ -95,49 +93,57 @@ class BBoardPage(BWizardPage): """ Overload of the BWizardPage connectSignals method. """ - self.connect(self.pageContent.boardList, SIGNAL('itemSelectionChanged()'), self.itemSelectionChanged) + self.connect(self.pageContent.boardList, SIGNAL("currentItemChanged(QListWidgetItem*,QListWidgetItem*)"), self.updateUi) + self.connect(self.pageContent.boardList, SIGNAL("currentItemChanged(QListWidgetItem*,QListWidgetItem*)"), self, SIGNAL("completeChanged()")) + self.connect(self.pageContent.customButton, SIGNAL("clicked()"), self.customButtonClicked) - def reloadData(self): + def reloadData(self, previous_id=None): """ 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.project.loadProjectPresets() + preset_list = self.projectInfo("PRESET_TREE") + preset_list = preset_list["children"] + preset_list = sorted(preset_list.values(), _cmp) + self.setItems(preset_list) + project_from_preset = self.projectInfo("PROJECT_FROM_PRESET") + project_board = self.projectInfo("PROJECT_BOARD") + if not (project_from_preset and project_board): self.pageContent.boardList.setCurrentRow(0) #### ## 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()")) + 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", "") + path = unicode(QUrl.fromLocalFile(info_dict["path"]).toString()) + description = description.replace("$path", path) + self.pageContent.descriptionArea.setHtml(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 advanced(self): - return self.pageContent.advancedCheckBox.isChecked() \ No newline at end of file + def selected(self): + return self.pageContent.boardList.currentItem()