From: duplo Date: Mon, 24 May 2010 13:25:15 +0000 (+0000) Subject: Add preset feature. X-Git-Tag: 2.5.0~111 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=afbcef7c7b408083dbcd77bc4697513dc10ea58d;p=bertos.git Add preset feature. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3806 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/wizard/BBoardPage.py b/wizard/BBoardPage.py index 5d83fda3..0877ea50 100644 --- a/wizard/BBoardPage.py +++ b/wizard/BBoardPage.py @@ -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): """ @@ -95,17 +98,40 @@ class BBoardPage(BWizardPage): 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 not os.path.exists(image): + image = ":/images/default_board_image.png" + self.pageContent.descriptionLabel.setText(description) + self.pageContent.imageLabel.setPixmap(QPixmap(image)) #### 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 = ":/images/default_board_icon.png" + 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 diff --git a/wizard/BProject.py b/wizard/BProject.py index c2f6613a..4564f79d 100644 --- a/wizard/BProject.py +++ b/wizard/BProject.py @@ -209,14 +209,14 @@ class BProject(object): _tree["info"] = self._loadPresetInfo(os.path.join(path, const.PREDEFINED_BOARD_SPEC_FILE)) _tree["info"]["filename"] = os.path.basename(path) _tree["info"]["path"] = path - _tree["children"] = [] + _tree["children"] = {} entries = set(os.listdir(path)) for entry in entries: _path = os.path.join(path, entry) if os.path.isdir(_path): sub_entries = set(os.listdir(_path)) if const.PREDEFINED_BOARD_SPEC_FILE in sub_entries: - _tree["children"].append(self._loadProjectPresetTree(_path)) + _tree["children"][_path] = self._loadProjectPresetTree(_path) # Add into the info dict the dir type (dir/project) if _tree["children"]: _tree["info"]["type"] = "dir" diff --git a/wizard/BProjectPresets.py b/wizard/BProjectPresets.py new file mode 100644 index 00000000..c0381a5c --- /dev/null +++ b/wizard/BProjectPresets.py @@ -0,0 +1,146 @@ +#!/usr/bin/env python +# encoding: utf-8 +# +# This file is part of slimqc. +# +# Bertos is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +# As a special exception, you may use this file as part of a free software +# library without restriction. Specifically, if other files instantiate +# templates or use macros or inline functions from this file, or you compile +# this file and link it with other files to produce an executable, this +# file does not by itself cause the resulting executable to be covered by +# the GNU General Public License. This exception does not however +# invalidate any other reasons why the executable file might be covered by +# the GNU General Public License. +# +# Copyright 2010 Develer S.r.l. (http://www.develer.com/) +# +# $Id$ +# +# Author: Lorenzo Berni +# + +import os + +from PyQt4 import uic + +from PyQt4.QtCore import * +from PyQt4.QtGui import * + +from BWizardPage import BWizardPage + +import const +import qvariant_converter + +class BProjectPresetsPage(QWidget): + def __init__(self, preset_data, parent=None): + QWidget.__init__(self, parent) + self.pageContent = uic.loadUi(os.path.join(const.DATA_DIR, const.UI_LOCATION, "preset_page.ui"), None) + self.project = QApplication.instance().project + self.settings = QApplication.instance().settings + self.preset_data = preset_data + layout = QVBoxLayout() + layout.addWidget(self.pageContent) + self.setLayout(layout) + self.setupUi() + self.connectSignals() + + def setupUi(self): + self.pageContent.presetList.clear() + def _cmp(x, y): + return cmp(x["info"].get('ord', 0), y["info"].get('ord', 0)) + for preset in sorted(self.preset_data["children"].values(), _cmp): + item_name = preset["info"].get("name", preset["info"]["filename"]) + item_icon = os.path.join(preset["info"]["path"], const.PREDEFINED_BOARD_ICON_FILE) + if not os.path.exists(item_icon): + item_icon = const.PREDEFINED_BOARD_DEFAULT_ICON + item_icon = QIcon(item_icon) + item = QListWidgetItem(item_icon, item_name) + item.setData(Qt.UserRole, qvariant_converter.convertString(preset["info"]["path"])) + self.pageContent.presetList.addItem(item) + self.pageContent.presetList.setCurrentRow(0) + self.updateUi() + + def connectSignals(self): + self.connect(self.pageContent.presetList, SIGNAL("itemSelectionChanged()"), self.updateUi) + self.connect(self.pageContent.presetList, SIGNAL("itemSelectionChanged()"), self, SIGNAL("completeChanged()")) + + def updateUi(self): + if self.selected: + preset_path = qvariant_converter.getString(self.selected.data(Qt.UserRole)) + preset = self.preset_data["children"][preset_path] + self.pageContent.descriptionLabel.setText(preset["info"].get("description", "")) + image = os.path.join(preset["info"]["path"], const.PREDEFINED_BOARD_IMAGE_FILE) + if not os.path.exists(image): + image = const.PREDEFINED_BOARD_DEFAULT_IMAGE + self.pageContent.imageLabel.setPixmap(QPixmap(image)) + + @property + def selected(self): + return self.pageContent.presetList.currentItem() + + +class BProjectPresets(BWizardPage): + def __init__(self): + BWizardPage.__init__(self, const.UI_LOCATION + "/project_presets.ui") + + ## Overloaded QWizardPage methods ## + + def isComplete(self): + current_widget = self.pageContent.boardTabWidget.currentWidget() + preset_path = None + if current_widget: + current_item = current_widget.pageContent.presetList.currentItem() + if current_item: + preset_path = current_item.data(Qt.UserRole) + preset_path = qvariant_converter.getString(preset_path) + if preset_path: + self.setProjectInfo("PROJECT_PRESET", preset_path) + return True + else: + self.setProjectInfo("PROJECT_PRESET", None) + return False + #### + + ## Overloaded BWizardPage methods ## + + def reloadData(self): + preset_path = self.projectInfo("PROJECT_BOARD") + preset_tree = self.projectInfo("PRESET_TREE") + preset_list = preset_tree["children"][preset_path]["children"] + def _cmp(x, y): + return cmp(x["info"].get('ord', 0), y["info"].get('ord', 0)) + preset_list = sorted(preset_list.values(), _cmp) + self.setupTabs(preset_list) + + def connectSignals(self): + self.connect(self.pageContent.boardTabWidget, SIGNAL("currentChanged(int)"), self, SIGNAL("completeChanged()")) + + #### + + ## Slots ## + #### + + def setupTabs(self, preset_list): + self.pageContent.boardTabWidget.clear() + for preset in preset_list: + icon = os.path.join(preset["info"]["path"], ".icon.png") + preset_page = BProjectPresetsPage(preset) + if os.path.exists(icon): + self.pageContent.boardTabWidget.addTab(preset_page, QIcon(icon), preset["info"].get("name", preset["info"]["filename"])) + else: + self.pageContent.boardTabWidget.addTab(preset_page, preset["info"].get("name", preset["info"]["filename"])) + self.connect(preset_page, SIGNAL("completeChanged()"), self, SIGNAL("completeChanged()")) \ No newline at end of file diff --git a/wizard/bertos.py b/wizard/bertos.py index 65e578cc..abee435b 100755 --- a/wizard/bertos.py +++ b/wizard/bertos.py @@ -50,6 +50,7 @@ from BIntroPage import BIntroPage from BFolderPage import BFolderPage from BTypePage import BTypePage from BBoardPage import BBoardPage +from BProjectPresets import BProjectPresets from BRoutePage import BRoutePage from BOpenPage import BOpenPage from BVersionPage import BVersionPage @@ -68,7 +69,7 @@ from LoadException import VersionException, ToolchainException def newProject(): QApplication.instance().project = BProject() - page_list = [BIntroPage, BFolderPage, BVersionPage, BTypePage, BBoardPage, BRoutePage, BCpuPage, BToolchainPage, BModulePage, BOutputPage, BCreationPage, BFinalPage] + page_list = [BIntroPage, BFolderPage, BVersionPage, BTypePage, BBoardPage, BProjectPresets, BRoutePage, BCpuPage, BToolchainPage, BModulePage, BOutputPage, BCreationPage, BFinalPage] wizard = BWizard(page_list) wizard.show() wizard.exec_() diff --git a/wizard/bertos.qrc b/wizard/bertos.qrc index 34f8ccc5..e7376c7f 100644 --- a/wizard/bertos.qrc +++ b/wizard/bertos.qrc @@ -12,5 +12,7 @@ images/logo.png images/default_dir_icon.png images/default_project_icon.png + images/default_board_image.png + images/default_board_icon.png diff --git a/wizard/const.py b/wizard/const.py index e048e685..863f45da 100644 --- a/wizard/const.py +++ b/wizard/const.py @@ -44,10 +44,13 @@ del _tmp PREDEFINED_BOARDS_DIR = 'boards' PREDEFINED_BOARD_SPEC_FILE = '.spec' PREDEFINED_BOARD_ICON_FILE = '.icon.png' +PREDEFINED_BOARD_IMAGE_FILE = '.image.png' # Predefined icons in resouces PREDEFINED_BOARD_DEFAULT_DIR_ICON = ':images/default_dir_icon.png' PREDEFINED_BOARD_DEFAULT_PROJECT_ICON = ':images/default_project_icon.png' +PREDEFINED_BOARD_DEFAULT_ICON = ':images/default_board_icon.png' +PREDEFINED_BOARD_DEFAULT_IMAGE = ':images/default_board_image.png' # PREDEFINED_BOARD_SPEC_INFO = { # 'name': , # 'description': , diff --git a/wizard/images/default_board_icon.png b/wizard/images/default_board_icon.png new file mode 100755 index 00000000..c7989f74 Binary files /dev/null and b/wizard/images/default_board_icon.png differ diff --git a/wizard/images/default_board_image.png b/wizard/images/default_board_image.png new file mode 100755 index 00000000..c7989f74 Binary files /dev/null and b/wizard/images/default_board_image.png differ diff --git a/wizard/ui/board_select.ui b/wizard/ui/board_select.ui index 48da3589..cca3695f 100644 --- a/wizard/ui/board_select.ui +++ b/wizard/ui/board_select.ui @@ -33,13 +33,6 @@ - - - - - - - @@ -53,6 +46,13 @@ + + + + + + + diff --git a/wizard/ui/preset_page.ui b/wizard/ui/preset_page.ui new file mode 100644 index 00000000..3418f120 --- /dev/null +++ b/wizard/ui/preset_page.ui @@ -0,0 +1,55 @@ + + + Form + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + + diff --git a/wizard/ui/project_presets.ui b/wizard/ui/project_presets.ui new file mode 100644 index 00000000..2925c82c --- /dev/null +++ b/wizard/ui/project_presets.ui @@ -0,0 +1,28 @@ + + + Form + + + + 0 + 0 + 501 + 403 + + + + Form + + + + + + -1 + + + + + + + +