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/)
32 # Author: Lorenzo Berni <duplo@develer.com>
37 from PyQt4.QtCore import *
38 from PyQt4.QtGui import *
40 from BWizardPage import BWizardPage
42 from BCpuPage import BCpuPage
45 import qvariant_converter
46 from bertos_utils import presetList, _cmp
48 class BBoardPage(BWizardPage):
50 Initial page of the alternative route. Permit to select one of the
51 predefined projects for supported board.
55 BWizardPage.__init__(self, const.UI_LOCATION + "/board_select.ui")
56 self.setTitle(self.tr("Select your development board"))
58 ## Overloaded QWizardPage methods ##
62 Overload of the QWizardPage isComplete method.
65 preset_path = qvariant_converter.getDict(self.selected.data(Qt.UserRole))
66 preset_path = qvariant_converter.getStringDict(preset_path["info"])
67 preset_path = preset_path["path"]
68 self.setProjectInfo("PROJECT_BOARD", preset_path)
69 self.setProjectInfo("PROJECT_FROM_PRESET", True)
70 self.setProjectInfo("PRESET_LOADED", False)
76 wizard = self.wizard()
77 if not self.projectInfo("PROJECT_FROM_PRESET"):
78 return wizard.pageIndex(BCpuPage)
80 return QWizardPage.nextId(self)
84 ## Overloaded BWizardPage methods ##
88 Overload of the BWizardPage setupUi method.
92 def connectSignals(self):
94 Overload of the BWizardPage connectSignals method.
96 self.connect(self.pageContent.boardList, SIGNAL("currentItemChanged(QListWidgetItem*,QListWidgetItem*)"), self.updateUi)
97 self.connect(self.pageContent.boardList, SIGNAL("currentItemChanged(QListWidgetItem*,QListWidgetItem*)"), self, SIGNAL("completeChanged()"))
98 self.connect(self.pageContent.customButton, SIGNAL("clicked()"), self.customButtonClicked)
100 def reloadData(self, previous_id=None):
102 Overload of the BWizardPage reloadData method.
104 self.project.loadProjectPresets()
105 preset_list = self.projectInfo("PRESET_TREE")
106 preset_list = preset_list["children"]
107 preset_list = sorted(preset_list.values(), _cmp)
108 self.setItems(preset_list)
109 project_from_preset = self.projectInfo("PROJECT_FROM_PRESET")
110 project_board = self.projectInfo("PROJECT_BOARD")
111 if not (project_from_preset and project_board):
112 self.pageContent.boardList.setCurrentRow(0)
120 info_dict = qvariant_converter.getDict(self.selected.data(Qt.UserRole))
121 info_dict = qvariant_converter.getStringDict(info_dict["info"])
122 description = info_dict.get("description", "")
123 path = unicode(QUrl.fromLocalFile(info_dict["path"]).toString())
124 description = description.replace("$path", path)
125 self.pageContent.descriptionArea.setHtml(description)
127 def customButtonClicked(self):
128 self.setProjectInfo("PROJECT_FROM_PRESET", False)
133 def setItems(self, preset_list):
134 self.pageContent.boardList.clear()
135 selected_board = self.projectInfo("PROJECT_BOARD")
136 for item_data in preset_list:
137 item_name = item_data["info"].get("name", item_data["info"]["filename"])
138 item_icon = os.path.join(item_data["info"]["path"], const.PREDEFINED_BOARD_ICON_FILE)
139 if not os.path.exists(item_icon):
140 item_icon = const.PREDEFINED_BOARD_DEFAULT_ICON
141 item = QListWidgetItem(QIcon(item_icon), item_name)
142 item.setData(Qt.UserRole, qvariant_converter.convertDict(item_data))
143 self.pageContent.boardList.addItem(item)
144 if selected_board and selected_board == item_data["info"]["path"]:
145 self.pageContent.boardList.setCurrentItem(item)
149 return self.pageContent.boardList.currentItem()