4 # This file is part of bertos.
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>
38 from PyQt4.QtCore import *
39 from PyQt4.QtGui import *
41 from BWizardPage import BWizardPage
43 from BCpuPage import BCpuPage
46 import qvariant_converter
47 from bertos_utils import presetList, _cmp
49 class BBoardPage(BWizardPage):
51 Initial page of the alternative route. Permit to select one of the
52 predefined projects for supported board.
56 BWizardPage.__init__(self, const.UI_LOCATION + "/board_select.ui")
57 self.setTitle(self.tr("Select your development board"))
59 ## Overloaded QWizardPage methods ##
63 Overload of the QWizardPage isComplete method.
66 preset_path = qvariant_converter.getDict(self.selected.data(Qt.UserRole))
67 preset_path = qvariant_converter.getStringDict(preset_path["info"])
68 preset_path = preset_path["path"]
69 self.setProjectInfo("PROJECT_BOARD", preset_path)
70 self.setProjectInfo("PROJECT_FROM_PRESET", True)
71 self.setProjectInfo("PRESET_LOADED", False)
77 wizard = self.wizard()
78 if not self.projectInfo("PROJECT_FROM_PRESET"):
79 return wizard.pageIndex(BCpuPage)
81 return QWizardPage.nextId(self)
85 ## Overloaded BWizardPage methods ##
89 Overload of the BWizardPage setupUi method.
93 def connectSignals(self):
95 Overload of the BWizardPage connectSignals method.
97 self.connect(self.pageContent.boardList, SIGNAL("currentItemChanged(QListWidgetItem*,QListWidgetItem*)"), self.updateUi)
98 self.connect(self.pageContent.boardList, SIGNAL("currentItemChanged(QListWidgetItem*,QListWidgetItem*)"), self, SIGNAL("completeChanged()"))
99 self.connect(self.pageContent.customButton, SIGNAL("clicked()"), self.customButtonClicked)
101 def reloadData(self, previous_id=None):
103 Overload of the BWizardPage reloadData method.
105 self.project.loadProjectPresets()
106 preset_list = self.projectInfo("PRESET_TREE")
107 preset_list = preset_list["children"]
108 preset_list = sorted(preset_list.values(), _cmp)
109 self.setItems(preset_list)
117 info_dict = qvariant_converter.getDict(self.selected.data(Qt.UserRole))
118 info_dict = qvariant_converter.getStringDict(info_dict["info"])
119 description = info_dict.get("description", "")
120 path = unicode(QUrl.fromLocalFile(info_dict["path"]).toString())
121 description = description.replace("$path", path)
122 self.pageContent.descriptionArea.setHtml(description)
124 def customButtonClicked(self):
125 self.setProjectInfo("PROJECT_FROM_PRESET", False)
130 def setItems(self, preset_list):
131 self.pageContent.boardList.clear()
132 selected_board = self.projectInfo("PROJECT_BOARD")
133 for item_data in preset_list:
134 item_name = item_data["info"].get("name", item_data["info"]["filename"])
135 item_icon = os.path.join(item_data["info"]["path"], const.PREDEFINED_BOARD_ICON_FILE)
136 if not os.path.exists(item_icon):
137 item_icon = const.PREDEFINED_BOARD_DEFAULT_ICON
138 item = QListWidgetItem(QIcon(item_icon), item_name)
139 item.setData(Qt.UserRole, qvariant_converter.convertDict(item_data))
140 self.pageContent.boardList.addItem(item)
141 if selected_board and selected_board == item_data["info"]["path"]:
142 self.pageContent.boardList.setCurrentItem(item)
146 return self.pageContent.boardList.currentItem()