Add some logic to display the presets into the preset page.
[bertos.git] / wizard / BBoardPage.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # This file is part of slimqc.
5 #
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.
10 #
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.
15 #
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
19 #
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.
28 #
29 # Copyright 2010 Develer S.r.l. (http://www.develer.com/)
30 #
31 # $Id$
32 #
33 # Author: Lorenzo Berni <duplo@develer.com>
34 #
35
36 from PyQt4.QtCore import *
37 from PyQt4.QtGui import *
38
39 from BWizardPage import BWizardPage
40
41 from BCpuPage import BCpuPage
42 from BOutputPage import BOutputPage
43
44 import const
45 import qvariant_converter
46 from bertos_utils import presetList
47
48 class BBoardPage(BWizardPage):
49     """
50     Initial page of the alternative route. Permit to select one of the
51     predefined projects for supported board.
52     """
53     
54     def __init__(self):
55         BWizardPage.__init__(self, const.UI_LOCATION + "/board_select.ui")
56         self.setTitle(self.tr("Select the board from the predefined ones"))
57         self._last_selected = None
58
59     ## Overloaded QWizardPage methods ##
60
61     def isComplete(self):
62         """
63         Overload of the QWizardPage isComplete method.
64         """
65         return self.pageContent.boardList.currentItem() is not None
66
67     def nextId(self):
68         """
69         Overload of the QWizardPage nextId method.
70         """
71         # Stub of nextId logic
72         if self.advanced:
73             self.setProjectInfo("PRESET_ADVANCED_CONFIG", True)
74             return self.wizard().pageIndex(BCpuPage)
75         # Search for suitable toolchains. If there isn't one return 
76         # BToolchainPage id (BToolchainPage should then route to BOutputPage
77         # instead of BModulePage).
78
79         # If a suitable toolchain is found the user has to be prompted
80         # directly to the BOutputPage
81         else:
82             return self.wizard().pageIndex(BOutputPage)
83
84     ####
85
86     ## Overloaded BWizardPage methods ##
87
88     def setupUi(self):
89         """
90         Overload of the BWizardPage setupUi method.
91         """
92         pass
93
94     def connectSignals(self):
95         """
96         Overload of the BWizardPage connectSignals method.
97         """
98         self.connect(self.pageContent.boardList, SIGNAL('itemSelectionChanged()'), self.itemSelectionChanged)
99
100     def reloadData(self):
101         """
102         Overload of the BWizardPage reloadData method.
103         """
104         presets = presetList("/Users/duplo/Development/bertos")
105         self.setProjectInfo("PRESETS", presets)
106         self.populatePresetList()
107
108     def populatePresetList(self):
109         self.pageContent.boardList.clear()
110         presets = self.projectInfo("PRESETS")
111         for preset, info in presets.items():
112             board_list = self.pageContent.boardList
113             item = QListWidgetItem(info["PRESET_NAME"], board_list)
114             item.setData(Qt.UserRole, qvariant_converter.convertString(preset))
115             if self._last_selected == preset:
116                 self.pageContent.boardList.setCurrentItem(item)
117         if not self._last_selected and self.pageContent.boardList.count():
118             self.pageContent.boardList.setCurrentRow(0)
119
120     ####
121
122     ## Slots ##
123
124     def itemSelectionChanged(self):
125         preset_path = qvariant_converter.getString(self.pageContent.boardList.currentItem().data(Qt.UserRole))
126         presets = self.projectInfo("PRESETS")
127         selected_preset = presets[preset_path]
128         text_components = [
129             "Board: %s" %selected_preset["PRESET_NAME"],
130             "CPU: %s" %selected_preset["CPU_NAME"],
131         ]
132         if selected_preset["PRESET_DESCRIPTION"]:
133             text_components.append("Description: %s" %selected_preset["PRESET_DESCRIPTION"])
134         text = "\n".join(text_components)
135         self.pageContent.descriptionLabel.setText(text)
136         self._last_selected = preset_path
137         self.emit(SIGNAL("completeChanged()"))
138
139     ####
140
141     @property
142     def advanced(self):
143         return self.pageContent.advancedCheckBox.isChecked()