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 2008 Develer S.r.l. (http://www.develer.com/)
33 # Author: Lorenzo Berni <duplo@develer.com>
39 from PyQt4.QtCore import *
40 from PyQt4.QtGui import *
42 from bertos_utils import bertosVersion, getToolchainName, createBertosProject
43 from BToolchainPage import BToolchainPage
44 from BVersionPage import BVersionPage
46 from BProject import BProject
48 import qvariant_converter
49 from BModulePage import BModulePage
52 class BEditingDialog(QDialog):
54 def __init__(self, parent=None):
55 QDialog.__init__(self, parent)
58 self.module_page.reloadData()
62 layout = QVBoxLayout()
63 self.module_page = BModulePage()
64 layout.addWidget(self.module_page)
65 frequency_layout = QHBoxLayout()
66 frequency_layout.addWidget(QLabel(self.tr("CPU frequency")))
67 self.cpu_frequency_spinbox = QDoubleSpinBox()
68 self.cpu_frequency_spinbox.setSuffix("Hz")
69 self.cpu_frequency_spinbox.setRange(1, 1000000000)
70 self.cpu_frequency_spinbox.setSingleStep(1000)
71 self.cpu_frequency_spinbox.setDecimals(0)
72 frequency_layout.addWidget(self.cpu_frequency_spinbox)
73 frequency_layout.addStretch()
74 layout.addLayout(frequency_layout)
75 button_layout = QHBoxLayout()
76 self.advanced_button = QToolButton()
78 self.advanced_button.setMenu(self.menu)
79 self.advanced_button.setPopupMode(QToolButton.InstantPopup)
80 self.advanced_button.setText(self.tr("Advanced"))
81 button_layout.addWidget(self.advanced_button)
82 button_layout.addStretch()
83 self.cancel_button = QPushButton(self.tr("Cancel"))
84 button_layout.addWidget(self.cancel_button)
85 self.apply_button = QPushButton(self.tr("Apply"))
86 button_layout.addWidget(self.apply_button)
87 layout.addLayout(button_layout)
88 self.setLayout(layout)
89 self.setWindowTitle(self.tr("Edit \"%1\" project").arg(os.path.basename(self.module_page.projectInfo("PROJECT_PATH"))))
90 self.setWindowIcon(QIcon(":/images/appicon.png"))
93 self.menu = QMenu(self.tr("Advanced options"))
94 self.change_toolchain = QAction(self.tr("Change toolchain"), self)
95 self.change_bertos_version = QAction(self.tr("Change BeRTOS version"), self)
96 self.menu.addAction(self.change_toolchain)
97 self.menu.addAction(self.change_bertos_version)
99 def connectSignals(self):
100 self.connect(self.change_toolchain, SIGNAL("triggered(bool)"), self.changeToolchain)
101 self.connect(self.change_bertos_version, SIGNAL("triggered(bool)"), self.changeBertosVersion)
102 self.connect(self.apply_button, SIGNAL("clicked()"), self.apply)
103 self.connect(self.cancel_button, SIGNAL("clicked()"), self.reject)
104 self.connect(self.cpu_frequency_spinbox, SIGNAL("valueChanged(double)"), self.frequencyChanged)
106 def setFrequency(self):
107 frequency = long(self.module_page.projectInfo("SELECTED_FREQ"))
108 self.cpu_frequency_spinbox.setValue(frequency)
110 def frequencyChanged(self, frequency):
111 frequency = unicode(long(frequency))
112 self.module_page.setProjectInfo("SELECTED_FREQ", frequency)
114 def changeToolchain(self):
115 dialog = BToolchainDialog()
117 toolchain = qvariant_converter.getStringDict(dialog.toolchain_page.currentItem().data(Qt.UserRole))
118 dialog.toolchain_page.setProjectInfo("TOOLCHAIN", toolchain)
120 def changeBertosVersion(self):
121 current_version = self.module_page.projectInfo("SOURCES_PATH")
122 dialog = BVersionDialog()
124 version = qvariant_converter.getString(dialog.version_page.currentItem().data(Qt.UserRole))
125 if QMessageBox.question(
127 self.tr("BeRTOS version update"),
128 self.tr("Changing the BeRTOS version will destroy all the modification done on the BeRTOS sources"),
129 QMessageBox.Ok | QMessageBox.Cancel
132 qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
133 dialog.version_page.setProjectInfo("SOURCES_PATH", version)
134 dialog.version_page.setProjectInfo("OLD_SOURCES_PATH", current_version)
135 enabled_modules = bertos_utils.enabledModules(dialog.version_page.project())
136 old_configuration = dialog.version_page.projectInfo("CONFIGURATIONS")
137 dialog.version_page.project().loadSourceTree()
138 QApplication.instance().project.loadModuleData()
139 new_configuration = dialog.version_page.projectInfo("CONFIGURATIONS")
140 merged_configuration = {}
141 for conf in new_configuration:
142 if conf in old_configuration:
143 configuration = bertos_utils.updateConfigurationValues(new_configuration[conf], old_configuration[conf])
145 configuration = new_configuration[conf]
146 merged_configuration[conf] = configuration
147 dialog.version_page.setProjectInfo("CONFIGURATIONS", merged_configuration)
148 bertos_utils.setEnabledModules(dialog.version_page.project(), enabled_modules)
149 self.module_page.fillModuleTree()
151 qApp.restoreOverrideCursor()
153 # Rollback version to the previous selected one.
154 dialog.version_page.setProjectInfo("SOURCES_PATH", current_version)
158 qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
159 createBertosProject(self.module_page.project(), edit=True)
161 qApp.restoreOverrideCursor()
164 def toolchains(self):
165 return self.module_page.toolchains()
167 def currentToolchain(self):
168 return self.module_page.projectInfo("TOOLCHAIN")
170 def setCurrentToolchain(self, toolchain):
171 self.module_page.setProjectInfo("TOOLCHAIN", toolchain)
174 return self.module_page.versions()
176 def currentVersion(self):
177 return self.module_page.projectInfo("SOURCES_PATH")
179 def setCurrentVersion(self, version):
180 self.module_page.setProjectInfo("SOURCES_PATH", version)
182 class BToolchainDialog(QDialog):
184 QDialog.__init__(self)
185 self.setWindowIcon(QIcon(":/images/appicon.png"))
186 layout = QVBoxLayout()
187 toolchain_page = BToolchainPage()
188 current_toolchain = toolchain_page.projectInfo("TOOLCHAIN")
189 toolchain_page.reloadData()
190 # TODO: to be moved in BToolchainPage
191 for toolchain_row in range(toolchain_page.pageContent.toolchainList.count()):
192 toolchain = qvariant_converter.getStringDict(toolchain_page.pageContent.toolchainList.item(toolchain_row).data(Qt.UserRole))
193 if current_toolchain and toolchain["path"] == current_toolchain["path"]:
194 toolchain_page.pageContent.toolchainList.setCurrentRow(toolchain_row)
195 toolchain_page.selectionChanged()
197 self.toolchain_page = toolchain_page
198 layout.addWidget(toolchain_page)
199 button_layout = QHBoxLayout()
200 button_layout.addStretch()
201 cancel_button = QPushButton(self.tr("Cancel"))
202 button_layout.addWidget(cancel_button)
203 ok_button = QPushButton(self.tr("Ok"))
204 button_layout.addWidget(ok_button)
205 self.connect(cancel_button, SIGNAL("clicked()"), self.reject)
206 layout.addLayout(button_layout)
207 self.setLayout(layout)
208 self.connect(ok_button, SIGNAL("clicked()"), self.accept)
209 self.setWindowTitle(self.tr("Change toolchain"))
211 class BVersionDialog(QDialog):
213 QDialog.__init__(self)
214 self.setWindowIcon(QIcon(":/images/appicon.png"))
215 layout = QVBoxLayout()
216 version_page = BVersionPage(edit=True)
217 version_page.reloadData()
218 self.version_page = version_page
219 layout.addWidget(version_page)
220 button_layout = QHBoxLayout()
221 button_layout.addStretch()
222 cancel_button = QPushButton(self.tr("Cancel"))
223 button_layout.addWidget(cancel_button)
224 ok_button = QPushButton(self.tr("Ok"))
225 button_layout.addWidget(ok_button)
226 self.connect(cancel_button, SIGNAL("clicked()"), self.reject)
227 layout.addLayout(button_layout)
228 self.setLayout(layout)
229 self.connect(ok_button, SIGNAL("clicked()"), self.accept)
230 current_version = version_page.projectInfo("SOURCES_PATH")
231 self.setWindowTitle(self.tr("Change BeRTOS version"))
235 if len(sys.argv) > 1:
236 project_file = sys.argv[1]
238 print "Invalid usage: use <command> project_file"
240 app = QApplication([])
241 app.project = BProject(project_file)
242 app.settings = QSettings("Develer", "Bertos Configurator")
243 dialog = BEditingDialog()
245 sys.exit(app.exec_())
247 if __name__ == "__main__":