4 # This file is part of slimqc.
6 # Bertos is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # As a special exception, you may use this file as part of a free software
21 # library without restriction. Specifically, if other files instantiate
22 # templates or use macros or inline functions from this file, or you compile
23 # this file and link it with other files to produce an executable, this
24 # file does not by itself cause the resulting executable to be covered by
25 # the GNU General Public License. This exception does not however
26 # invalidate any other reasons why the executable file might be covered by
27 # the GNU General Public License.
29 # Copyright 2010 Develer S.r.l. (http://www.develer.com/)
33 # Author: Lorenzo Berni <duplo@develer.com>
40 from PyQt4.QtCore import *
41 from PyQt4.QtGui import *
43 from BWizardPage import BWizardPage
45 from BCreationPage import BCreationPage
46 from BToolchainPage import BToolchainPage
48 from bertos_utils import _cmp
49 from toolchain_manager import ToolchainManager
52 import qvariant_converter
54 class BProjectPresetsPage(QWidget):
55 def __init__(self, preset_data, parent=None):
56 QWidget.__init__(self, parent)
57 self.pageContent = uic.loadUi(os.path.join(const.DATA_DIR, const.UI_LOCATION, "preset_page.ui"), None)
58 self.project = QApplication.instance().project
59 self.settings = QApplication.instance().settings
60 self.preset_data = preset_data
61 layout = QVBoxLayout()
62 layout.addWidget(self.pageContent)
63 self.setLayout(layout)
68 self.pageContent.presetList.clear()
69 self.pageContent.categoryDescription.setText(self.preset_data["info"].get("description", ""))
70 for preset in sorted(self.preset_data["children"].values(), _cmp):
71 item_name = preset["info"].get("name", preset["info"]["filename"])
72 item_icon = os.path.join(preset["info"]["path"], const.PREDEFINED_BOARD_ICON_FILE)
73 if not os.path.exists(item_icon):
74 item_icon = const.PREDEFINED_BOARD_DEFAULT_PROJECT_ICON
75 item_icon = QIcon(item_icon)
76 item = QListWidgetItem(item_icon, item_name)
77 item.setData(Qt.UserRole, qvariant_converter.convertString(preset["info"]["path"]))
78 self.pageContent.presetList.addItem(item)
79 self.pageContent.presetList.setCurrentRow(0)
82 def connectSignals(self):
83 self.connect(self.pageContent.presetList, SIGNAL("currentItemChanged(QListWidgetItem *, QListWidgetItem*)"), self.updateUi)
84 self.connect(self.pageContent.presetList, SIGNAL("currentItemChanged(QListWidgetItem *, QListWidgetItem*)"), self, SIGNAL("completeChanged()"))
88 preset_path = qvariant_converter.getString(self.selected.data(Qt.UserRole))
89 preset = self.preset_data["children"][preset_path]
90 description = preset["info"].get("description", "")
91 path = unicode(QUrl.fromLocalFile(preset_path).toString())
92 description = description.replace("$path", path)
93 self.pageContent.descriptionArea.setHtml(description)
97 return self.pageContent.presetList.currentItem()
100 class BProjectPresets(BWizardPage):
102 BWizardPage.__init__(self, const.UI_LOCATION + "/project_presets.ui")
104 ## Overloaded QWizardPage methods ##
106 def isComplete(self):
107 preset_path = self.selected_path
109 self.setProjectInfo("PROJECT_PRESET", preset_path)
110 self.setProjectInfo("BASE_MODE", not self.advanced)
113 self.setProjectInfo("PROJECT_PRESET", None)
116 def validatePage(self):
118 This hack permits to load the preset once, when the user go press the
121 preset_path = self.selected_path
123 QApplication.instance().setOverrideCursor(Qt.WaitCursor)
124 self.project.loadProjectFromPreset(preset_path)
125 self.setProjectInfo("PRESET_LOADED", True)
127 QApplication.instance().restoreOverrideCursor()
128 # Return always True, this is a fake validation.
133 Overload of the QWizardPage nextId method.
135 # Route to Toolchain page if the user select advanced
136 # or to Output page if the user select base
138 return self.wizard().pageIndex(BToolchainPage)
140 cpu_info = self.projectInfo("CPU_INFOS")
142 target = cpu_info["TOOLCHAIN"]
143 # Try to find a suitable toolchain automatically
144 tm = ToolchainManager()
145 suitable_toolchains = tm.suitableToolchains(target)
146 if len(suitable_toolchains) == 1:
147 toolchain = suitable_toolchains.pop()
148 toolchain_info = tm._validateToolchain(toolchain)
149 toolchain_info["path"] = toolchain
150 self.setProjectInfo("TOOLCHAIN", toolchain_info)
151 return self.wizard().pageIndex(BCreationPage)
153 return self.wizard().pageIndex(BToolchainPage)
155 # It seems that the nextId method is called before the
156 # reloadData one (that is called after the page changing.
158 # TODO: fix this awful code lines
160 return self.wizard().pageIndex(BToolchainPage)
164 ## Overloaded BWizardPage methods ##
166 def reloadData(self, previous_id=None):
167 if not self.projectInfo("PRESET_LOADED"):
168 preset_path = self.projectInfo("PROJECT_BOARD")
169 preset_tree = self.projectInfo("PRESET_TREE")
170 preset_list = preset_tree["children"][preset_path]["children"]
171 preset_list = sorted(preset_list.values(), _cmp)
172 self.setTitle(self.tr("Select the project template for %1").arg(preset_tree["children"][preset_path]["info"].get("name", preset_tree["children"][preset_path]["info"]["filename"])))
173 self.setupTabs(preset_list)
175 def connectSignals(self):
176 self.connect(self.pageContent.boardTabWidget, SIGNAL("currentChanged(int)"), self, SIGNAL("completeChanged()"))
183 def setupTabs(self, preset_list):
184 self.pageContent.boardTabWidget.clear()
185 for preset in preset_list:
186 icon = os.path.join(preset["info"]["path"], ".icon.png")
187 preset_page = BProjectPresetsPage(preset)
188 if os.path.exists(icon):
189 self.pageContent.boardTabWidget.addTab(preset_page, QIcon(icon), preset["info"].get("name", preset["info"]["filename"]))
191 self.pageContent.boardTabWidget.addTab(preset_page, preset["info"].get("name", preset["info"]["filename"]))
192 self.connect(preset_page, SIGNAL("completeChanged()"), self, SIGNAL("completeChanged()"))
196 if self.selected_data:
197 return self.selected_data["info"].get("advanced", False)
202 def selected_path(self):
203 current_widget = self.pageContent.boardTabWidget.currentWidget()
206 current_item = current_widget.pageContent.presetList.currentItem()
208 preset_path = current_item.data(Qt.UserRole)
209 preset_path = qvariant_converter.getString(preset_path)
213 def selected_data(self):
214 if self.selected_path:
215 current_widget = self.pageContent.boardTabWidget.currentWidget()
216 return current_widget.preset_data["children"][self.selected_path]