X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=wizard%2FBEditingDialog.py;h=d177d4d19e52581cef2c6516edfd815e62315f2e;hb=57dfb183e24175bc782647d4e6aebe31063f3881;hp=0bf8ea68b39a09c3630925d9073494da54c53c22;hpb=0177979cf7775a8244c071bd87fcc953063f548c;p=bertos.git diff --git a/wizard/BEditingDialog.py b/wizard/BEditingDialog.py index 0bf8ea68..d177d4d1 100644 --- a/wizard/BEditingDialog.py +++ b/wizard/BEditingDialog.py @@ -28,7 +28,6 @@ # # Copyright 2008 Develer S.r.l. (http://www.develer.com/) # -# $Id$ # # Author: Lorenzo Berni # @@ -39,10 +38,15 @@ import os from PyQt4.QtCore import * from PyQt4.QtGui import * -from bertos_utils import loadBertosProject, bertosVersion, getToolchainName -from toolchain_validation import validateToolchain +from bertos_utils import bertosVersion, getToolchainName +from BToolchainPage import BToolchainPage +from BVersionPage import BVersionPage + +from BProject import BProject + import qvariant_converter -import BModulePage +from BModulePage import BModulePage +import bertos_utils class BEditingDialog(QDialog): @@ -51,11 +55,22 @@ class BEditingDialog(QDialog): self.setupUi() self.connectSignals() self.module_page.reloadData() + self.setFrequency() def setupUi(self): layout = QVBoxLayout() - self.module_page = BModulePage.BModulePage() + self.module_page = BModulePage() layout.addWidget(self.module_page) + frequency_layout = QHBoxLayout() + frequency_layout.addWidget(QLabel(self.tr("CPU frequency"))) + self.cpu_frequency_spinbox = QDoubleSpinBox() + self.cpu_frequency_spinbox.setSuffix("Hz") + self.cpu_frequency_spinbox.setRange(1, 1000000000) + self.cpu_frequency_spinbox.setSingleStep(1000) + self.cpu_frequency_spinbox.setDecimals(0) + frequency_layout.addWidget(self.cpu_frequency_spinbox) + frequency_layout.addStretch() + layout.addLayout(frequency_layout) button_layout = QHBoxLayout() self.advanced_button = QToolButton() self.setupMenu() @@ -70,63 +85,81 @@ class BEditingDialog(QDialog): button_layout.addWidget(self.apply_button) layout.addLayout(button_layout) self.setLayout(layout) + self.setWindowTitle(self.tr("Edit \"%1\" project").arg(os.path.basename(self.module_page.projectInfo("PROJECT_PATH")))) + self.setWindowIcon(QIcon(":/images/appicon.png")) def setupMenu(self): self.menu = QMenu(self.tr("Advanced options")) - self.setupToolchainMenu() - self.menu.addMenu(self.toolchain_menu) - self.setupVersionMenu() - self.menu.addMenu(self.version_menu) - - def setupToolchainMenu(self): - self.toolchain_menu = QMenu(self.tr("select toolchain")) - self.toolchain_actions = [] - action_group = QActionGroup(self.toolchain_menu) - for toolchain in sorted(self.toolchains()): - info = validateToolchain(toolchain) - if info[0]: - name = getToolchainName(info[1]) - else: - name = toolchain - action = self.toolchain_menu.addAction(name) - action_group.addAction(action) - action.setCheckable(True) - action.setChecked(True if toolchain == self.currentToolchain()["path"] else False) - action.setData(qvariant_converter.convertString(toolchain)) - self.toolchain_actions.append(action) - - def setupVersionMenu(self): - self.version_menu = QMenu(self.tr("select BeRTOS version")) - self.version_actions = [] - action_group = QActionGroup(self.version_menu) - versions = [(path, bertosVersion(path)) for path in self.versions()] - for path, version in versions: - action = self.version_menu.addAction(version) - action_group.addAction(action) - action.setCheckable(True) - action.setChecked(True if path == self.currentVersion() else False) - action.setData(qvariant_converter.convertString(path)) - self.version_actions.append(action) + self.change_toolchain = QAction(self.tr("Change toolchain"), self) + self.change_bertos_version = QAction(self.tr("Change BeRTOS version"), self) + self.menu.addAction(self.change_toolchain) + self.menu.addAction(self.change_bertos_version) def connectSignals(self): - for toolchain_action in self.toolchain_actions: - self.connect(toolchain_action, SIGNAL("toggled(bool)"), lambda x, toolchain_action=toolchain_action: self.toolchainChanged( - qvariant_converter.getString(toolchain_action.data()), - x - )) - for version_action in self.version_actions: - self.connect(version_action, SIGNAL("toggled(bool)"), lambda x, version_action=version_action: self.versionChanged( - qvariant_converter.getString(version_action.data()), - x - )) - - def toolchainChanged(self, toolchain, activated): - if activated: - self.setCurrentToolchain(toolchain) - - def versionChanged(self, version, activated): - if activated: - self.setCurrentVersion(version) + self.connect(self.change_toolchain, SIGNAL("triggered(bool)"), self.changeToolchain) + self.connect(self.change_bertos_version, SIGNAL("triggered(bool)"), self.changeBertosVersion) + self.connect(self.apply_button, SIGNAL("clicked()"), self.apply) + self.connect(self.cancel_button, SIGNAL("clicked()"), self.reject) + self.connect(self.cpu_frequency_spinbox, SIGNAL("valueChanged(double)"), self.frequencyChanged) + + def setFrequency(self): + frequency = long(self.module_page.projectInfo("SELECTED_FREQ")) + self.cpu_frequency_spinbox.setValue(frequency) + + def frequencyChanged(self, frequency): + frequency = unicode(long(frequency)) + self.module_page.setProjectInfo("SELECTED_FREQ", frequency) + + def changeToolchain(self): + dialog = BToolchainDialog() + if dialog.exec_(): + toolchain = qvariant_converter.getStringDict(dialog.toolchain_page.currentItem().data(Qt.UserRole)) + dialog.toolchain_page.setProjectInfo("TOOLCHAIN", toolchain) + + def changeBertosVersion(self): + current_version = self.module_page.projectInfo("BERTOS_PATH") + dialog = BVersionDialog() + if dialog.exec_(): + version = qvariant_converter.getString(dialog.version_page.currentItem().data(Qt.UserRole)) + if QMessageBox.question( + dialog.version_page, + self.tr("BeRTOS version update"), + self.tr("Changing the BeRTOS version will destroy all the modification done on the BeRTOS sources"), + QMessageBox.Ok | QMessageBox.Cancel + ) == QMessageBox.Ok: + try: + qApp.setOverrideCursor(QCursor(Qt.WaitCursor)) + dialog.version_page.setProjectInfo("BERTOS_PATH", version) + dialog.version_page.setProjectInfo("OLD_BERTOS_PATH", current_version) + enabled_modules = bertos_utils.enabledModules(dialog.version_page.project) + old_configuration = dialog.version_page.projectInfo("CONFIGURATIONS") + dialog.version_page.project.loadSourceTree() + QApplication.instance().project.reloadCpuInfo() + QApplication.instance().project.loadModuleData() + new_configuration = dialog.version_page.projectInfo("CONFIGURATIONS") + merged_configuration = {} + for conf in new_configuration: + if conf in old_configuration: + configuration = bertos_utils.updateConfigurationValues(new_configuration[conf], old_configuration[conf]) + else: + configuration = new_configuration[conf] + merged_configuration[conf] = configuration + dialog.version_page.setProjectInfo("CONFIGURATIONS", merged_configuration) + dialog.version_page.project.setEnabledModules(enabled_modules) + self.module_page.fillModuleTree() + finally: + qApp.restoreOverrideCursor() + else: + # Rollback version to the previous selected one. + dialog.version_page.setProjectInfo("BERTOS_PATH", current_version) + + def apply(self): + try: + qApp.setOverrideCursor(QCursor(Qt.WaitCursor)) + QApplication.instance().project.createBertosProject() + finally: + qApp.restoreOverrideCursor() + self.accept() def toolchains(self): return self.module_page.toolchains() @@ -141,11 +174,61 @@ class BEditingDialog(QDialog): return self.module_page.versions() def currentVersion(self): - return self.module_page.projectInfo("SOURCES_PATH") + return self.module_page.projectInfo("BERTOS_PATH") def setCurrentVersion(self, version): - self.module_page.setProjectInfo("SOURCES_PATH", version) + self.module_page.setProjectInfo("BERTOS_PATH", version) + +class BToolchainDialog(QDialog): + def __init__(self): + QDialog.__init__(self) + self.setWindowIcon(QIcon(":/images/appicon.png")) + layout = QVBoxLayout() + toolchain_page = BToolchainPage() + current_toolchain = toolchain_page.projectInfo("TOOLCHAIN") + toolchain_page.reloadData() + # TODO: to be moved in BToolchainPage + for toolchain_row in range(toolchain_page.pageContent.toolchainList.count()): + toolchain = qvariant_converter.getStringDict(toolchain_page.pageContent.toolchainList.item(toolchain_row).data(Qt.UserRole)) + if current_toolchain and toolchain["path"] == current_toolchain["path"]: + toolchain_page.pageContent.toolchainList.setCurrentRow(toolchain_row) + toolchain_page.selectionChanged() + break + self.toolchain_page = toolchain_page + layout.addWidget(toolchain_page) + button_layout = QHBoxLayout() + button_layout.addStretch() + cancel_button = QPushButton(self.tr("Cancel")) + button_layout.addWidget(cancel_button) + ok_button = QPushButton(self.tr("Ok")) + button_layout.addWidget(ok_button) + self.connect(cancel_button, SIGNAL("clicked()"), self.reject) + layout.addLayout(button_layout) + self.setLayout(layout) + self.connect(ok_button, SIGNAL("clicked()"), self.accept) + self.setWindowTitle(self.tr("Change toolchain")) +class BVersionDialog(QDialog): + def __init__(self): + QDialog.__init__(self) + self.setWindowIcon(QIcon(":/images/appicon.png")) + layout = QVBoxLayout() + version_page = BVersionPage(edit=True) + version_page.reloadData() + self.version_page = version_page + layout.addWidget(version_page) + button_layout = QHBoxLayout() + button_layout.addStretch() + cancel_button = QPushButton(self.tr("Cancel")) + button_layout.addWidget(cancel_button) + ok_button = QPushButton(self.tr("Ok")) + button_layout.addWidget(ok_button) + self.connect(cancel_button, SIGNAL("clicked()"), self.reject) + layout.addLayout(button_layout) + self.setLayout(layout) + self.connect(ok_button, SIGNAL("clicked()"), self.accept) + current_version = version_page.projectInfo("BERTOS_PATH") + self.setWindowTitle(self.tr("Change BeRTOS version")) def main(): @@ -155,7 +238,7 @@ def main(): print "Invalid usage: use project_file" sys.exit() app = QApplication([]) - app.project = loadBertosProject(project_file) + app.project = BProject(project_file) app.settings = QSettings("Develer", "Bertos Configurator") dialog = BEditingDialog() dialog.show()