Remove basic/advanced page. (You need to specify advanced projects directly into...
[bertos.git] / wizard / BBoardPage.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # This file is part of bertos.
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 import os
37
38 from PyQt4.QtCore import *
39 from PyQt4.QtGui import *
40
41 from BWizardPage import BWizardPage
42
43 from BCpuPage import BCpuPage
44
45 import const
46 import qvariant_converter
47 from bertos_utils import presetList, _cmp
48
49 class BBoardPage(BWizardPage):
50     """
51     Initial page of the alternative route. Permit to select one of the
52     predefined projects for supported board.
53     """
54     
55     def __init__(self):
56         BWizardPage.__init__(self, const.UI_LOCATION + "/board_select.ui")
57         self.setTitle(self.tr("Select the board from the predefined ones"))
58
59     ## Overloaded QWizardPage methods ##
60
61     def isComplete(self):
62         """
63         Overload of the QWizardPage isComplete method.
64         """
65         if self.selected:
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             return True
72         else:
73             return False
74
75     def nextId(self):
76         wizard = self.wizard()
77         if not self.projectInfo("PROJECT_FROM_PRESET"):
78             return wizard.pageIndex(BCpuPage)
79         else:
80             return QWizardPage.nextId(self)
81
82     ####
83
84     ## Overloaded BWizardPage methods ##
85
86     def setupUi(self):
87         """
88         Overload of the BWizardPage setupUi method.
89         """
90         pass
91
92     def connectSignals(self):
93         """
94         Overload of the BWizardPage connectSignals method.
95         """
96         self.connect(self.pageContent.boardList, SIGNAL("itemSelectionChanged()"), self.updateUi)
97         self.connect(self.pageContent.boardList, SIGNAL("itemSelectionChanged()"), self, SIGNAL("completeChanged()"))
98         self.connect(self.pageContent.customButton, SIGNAL("clicked()"), self.customButtonClicked)
99
100     def reloadData(self):
101         """
102         Overload of the BWizardPage reloadData method.
103         """
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
110     ####
111
112     ## Slots ##
113
114     def updateUi(self):
115         if self.selected:
116             info_dict = qvariant_converter.getDict(self.selected.data(Qt.UserRole))
117             info_dict = qvariant_converter.getStringDict(info_dict["info"])
118             description = info_dict.get("description", "")
119             image = os.path.join(info_dict["path"], ".image.png")
120             if os.path.exists(image):
121                 self.pageContent.imageLabel.setPixmap(QPixmap(image))
122                 self.pageContent.imageLabel.setVisible(True)
123             else:
124                 self.pageContent.imageLabel.setVisible(False)
125             self.pageContent.descriptionLabel.setText(description)
126
127     def customButtonClicked(self):
128         self.setProjectInfo("PROJECT_FROM_PRESET", False)
129         self.wizard().next()
130
131     ####
132
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)
146
147     @property
148     def selected(self):
149         return self.pageContent.boardList.currentItem()