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 bertos_utils import _cmp
48 import qvariant_converter
50 class BProjectPresetsPage(QWidget):
51 def __init__(self, preset_data, parent=None):
52 QWidget.__init__(self, parent)
53 self.pageContent = uic.loadUi(os.path.join(const.DATA_DIR, const.UI_LOCATION, "preset_page.ui"), None)
54 self.project = QApplication.instance().project
55 self.settings = QApplication.instance().settings
56 self.preset_data = preset_data
57 layout = QVBoxLayout()
58 layout.addWidget(self.pageContent)
59 self.setLayout(layout)
64 self.pageContent.presetList.clear()
65 self.pageContent.categoryDescription.setText(self.preset_data["info"].get("description", ""))
66 for preset in sorted(self.preset_data["children"].values(), _cmp):
67 item_name = preset["info"].get("name", preset["info"]["filename"])
68 item_icon = os.path.join(preset["info"]["path"], const.PREDEFINED_BOARD_ICON_FILE)
69 if not os.path.exists(item_icon):
70 item_icon = const.PREDEFINED_BOARD_DEFAULT_PROJECT_ICON
71 item_icon = QIcon(item_icon)
72 item = QListWidgetItem(item_icon, item_name)
73 item.setData(Qt.UserRole, qvariant_converter.convertString(preset["info"]["path"]))
74 self.pageContent.presetList.addItem(item)
75 self.pageContent.presetList.setCurrentRow(0)
78 def connectSignals(self):
79 self.connect(self.pageContent.presetList, SIGNAL("itemSelectionChanged()"), self.updateUi)
80 self.connect(self.pageContent.presetList, SIGNAL("itemSelectionChanged()"), self, SIGNAL("completeChanged()"))
84 preset_path = qvariant_converter.getString(self.selected.data(Qt.UserRole))
85 preset = self.preset_data["children"][preset_path]
86 self.pageContent.descriptionLabel.setText(preset["info"].get("description", ""))
87 image = os.path.join(preset["info"]["path"], const.PREDEFINED_BOARD_IMAGE_FILE)
88 if os.path.exists(image):
89 self.pageContent.imageLabel.setPixmap(QPixmap(image))
90 self.pageContent.imageLabel.setVisible(True)
92 self.pageContent.imageLabel.setVisible(False)
96 return self.pageContent.presetList.currentItem()
99 class BProjectPresets(BWizardPage):
101 BWizardPage.__init__(self, const.UI_LOCATION + "/project_presets.ui")
103 ## Overloaded QWizardPage methods ##
105 def isComplete(self):
106 current_widget = self.pageContent.boardTabWidget.currentWidget()
109 current_item = current_widget.pageContent.presetList.currentItem()
111 preset_path = current_item.data(Qt.UserRole)
112 preset_path = qvariant_converter.getString(preset_path)
114 self.setProjectInfo("PROJECT_PRESET", preset_path)
117 self.setProjectInfo("PROJECT_PRESET", None)
121 ## Overloaded BWizardPage methods ##
123 def reloadData(self):
124 preset_path = self.projectInfo("PROJECT_BOARD")
125 preset_tree = self.projectInfo("PRESET_TREE")
126 preset_list = preset_tree["children"][preset_path]["children"]
127 preset_list = sorted(preset_list.values(), _cmp)
128 self.setTitle(self.tr("Select the template/demo for %1").arg(preset_tree["children"][preset_path]["info"].get("name", preset_tree["children"][preset_path]["info"]["filename"])))
129 self.setupTabs(preset_list)
131 def connectSignals(self):
132 self.connect(self.pageContent.boardTabWidget, SIGNAL("currentChanged(int)"), self, SIGNAL("completeChanged()"))
139 def setupTabs(self, preset_list):
140 self.pageContent.boardTabWidget.clear()
141 for preset in preset_list:
142 icon = os.path.join(preset["info"]["path"], ".icon.png")
143 preset_page = BProjectPresetsPage(preset)
144 if os.path.exists(icon):
145 self.pageContent.boardTabWidget.addTab(preset_page, QIcon(icon), preset["info"].get("name", preset["info"]["filename"]))
147 self.pageContent.boardTabWidget.addTab(preset_page, preset["info"].get("name", preset["info"]["filename"]))
148 self.connect(preset_page, SIGNAL("completeChanged()"), self, SIGNAL("completeChanged()"))