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
46 import qvariant_converter
48 class BProjectPresetsPage(QWidget):
49 def __init__(self, preset_data, parent=None):
50 QWidget.__init__(self, parent)
51 self.pageContent = uic.loadUi(os.path.join(const.DATA_DIR, const.UI_LOCATION, "preset_page.ui"), None)
52 self.project = QApplication.instance().project
53 self.settings = QApplication.instance().settings
54 self.preset_data = preset_data
55 layout = QVBoxLayout()
56 layout.addWidget(self.pageContent)
57 self.setLayout(layout)
62 self.pageContent.presetList.clear()
64 return cmp(x["info"].get('ord', 0), y["info"].get('ord', 0))
65 for preset in sorted(self.preset_data["children"].values(), _cmp):
66 item_name = preset["info"].get("name", preset["info"]["filename"])
67 item_icon = os.path.join(preset["info"]["path"], const.PREDEFINED_BOARD_ICON_FILE)
68 if not os.path.exists(item_icon):
69 item_icon = const.PREDEFINED_BOARD_DEFAULT_ICON
70 item_icon = QIcon(item_icon)
71 item = QListWidgetItem(item_icon, item_name)
72 item.setData(Qt.UserRole, qvariant_converter.convertString(preset["info"]["path"]))
73 self.pageContent.presetList.addItem(item)
74 self.pageContent.presetList.setCurrentRow(0)
77 def connectSignals(self):
78 self.connect(self.pageContent.presetList, SIGNAL("itemSelectionChanged()"), self.updateUi)
79 self.connect(self.pageContent.presetList, SIGNAL("itemSelectionChanged()"), self, SIGNAL("completeChanged()"))
83 preset_path = qvariant_converter.getString(self.selected.data(Qt.UserRole))
84 preset = self.preset_data["children"][preset_path]
85 self.pageContent.descriptionLabel.setText(preset["info"].get("description", ""))
86 image = os.path.join(preset["info"]["path"], const.PREDEFINED_BOARD_IMAGE_FILE)
87 if not os.path.exists(image):
88 image = const.PREDEFINED_BOARD_DEFAULT_IMAGE
89 self.pageContent.imageLabel.setPixmap(QPixmap(image))
93 return self.pageContent.presetList.currentItem()
96 class BProjectPresets(BWizardPage):
98 BWizardPage.__init__(self, const.UI_LOCATION + "/project_presets.ui")
100 ## Overloaded QWizardPage methods ##
102 def isComplete(self):
103 current_widget = self.pageContent.boardTabWidget.currentWidget()
106 current_item = current_widget.pageContent.presetList.currentItem()
108 preset_path = current_item.data(Qt.UserRole)
109 preset_path = qvariant_converter.getString(preset_path)
111 self.setProjectInfo("PROJECT_PRESET", preset_path)
114 self.setProjectInfo("PROJECT_PRESET", None)
118 ## Overloaded BWizardPage methods ##
120 def reloadData(self):
121 preset_path = self.projectInfo("PROJECT_BOARD")
122 preset_tree = self.projectInfo("PRESET_TREE")
123 preset_list = preset_tree["children"][preset_path]["children"]
125 return cmp(x["info"].get('ord', 0), y["info"].get('ord', 0))
126 preset_list = sorted(preset_list.values(), _cmp)
127 self.setupTabs(preset_list)
129 def connectSignals(self):
130 self.connect(self.pageContent.boardTabWidget, SIGNAL("currentChanged(int)"), self, SIGNAL("completeChanged()"))
137 def setupTabs(self, preset_list):
138 self.pageContent.boardTabWidget.clear()
139 for preset in preset_list:
140 icon = os.path.join(preset["info"]["path"], ".icon.png")
141 preset_page = BProjectPresetsPage(preset)
142 if os.path.exists(icon):
143 self.pageContent.boardTabWidget.addTab(preset_page, QIcon(icon), preset["info"].get("name", preset["info"]["filename"]))
145 self.pageContent.boardTabWidget.addTab(preset_page, preset["info"].get("name", preset["info"]["filename"]))
146 self.connect(preset_page, SIGNAL("completeChanged()"), self, SIGNAL("completeChanged()"))