"""
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
####
"""
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):
"""
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
_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"
--- /dev/null
+#!/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 <duplo@develer.com>
+#
+
+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
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
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_()
<file>images/logo.png</file>
<file>images/default_dir_icon.png</file>
<file>images/default_project_icon.png</file>
+ <file>images/default_board_image.png</file>
+ <file>images/default_board_icon.png</file>
</qresource>
</RCC>
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': <name of the board/directory>,
# 'description': <description of the board/directory>,
</property>
</widget>
</item>
- <item>
- <widget class="QLabel" name="imageLabel">
- <property name="text">
- <string/>
- </property>
- </widget>
- </item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
</property>
</spacer>
</item>
+ <item>
+ <widget class="QLabel" name="imageLabel">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
</layout>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Form</class>
+ <widget class="QWidget" name="Form">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QListWidget" name="presetList"/>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QLabel" name="imageLabel">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="descriptionLabel">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Form</class>
+ <widget class="QWidget" name="Form">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>501</width>
+ <height>403</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QTabWidget" name="boardTabWidget">
+ <property name="currentIndex">
+ <number>-1</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>