If the user select the same version he's using the Wizard will replace it with the...
[bertos.git] / wizard / BEditingDialog.py
index 1b297d3879ce84d8015b984abb8f23c58954099b..4fae34231e1bc1557158bcde35dcb875a91a86a9 100644 (file)
@@ -53,11 +53,22 @@ class BEditingDialog(QDialog):
         self.setupUi()
         self.connectSignals()
         self.module_page.reloadData()
+       self.setFrequency()
     
     def setupUi(self):
         layout = QVBoxLayout()
         self.module_page = BModulePage.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()
@@ -73,6 +84,7 @@ class BEditingDialog(QDialog):
         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"))
@@ -86,9 +98,84 @@ class BEditingDialog(QDialog):
         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 = QDialog()
+        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("SOURCES_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:
+                qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
+                dialog.version_page.setProjectInfo("SOURCES_PATH", version)
+                dialog.version_page.setProjectInfo("OLD_SOURCES_PATH", current_version)
+                enabled_modules = bertos_utils.enabledModules(dialog.version_page.project())
+                old_configuration = dialog.version_page.projectInfo("CONFIGURATIONS")
+                bertos_utils.loadSourceTree(dialog.version_page.project())
+                bertos_utils.loadModuleData(dialog.version_page.project())
+                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)
+                bertos_utils.setEnabledModules(dialog.version_page.project(), enabled_modules)
+                self.module_page.fillModuleTree()
+                qApp.restoreOverrideCursor()
+            else:
+                # Rollback version to the previous selected one.
+                dialog.version_page.setProjectInfo("SOURCES_PATH", current_version)
+
+    def apply(self):
+        qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
+        createBertosProject(self.module_page.project(), edit=True)
+        qApp.restoreOverrideCursor()
+        self.accept()
+
+    def toolchains(self):
+        return self.module_page.toolchains()
+    
+    def currentToolchain(self):
+        return self.module_page.projectInfo("TOOLCHAIN")
+    
+    def setCurrentToolchain(self, toolchain):
+        self.module_page.setProjectInfo("TOOLCHAIN", toolchain)
+
+    def versions(self):
+        return self.module_page.versions()
+
+    def currentVersion(self):
+        return self.module_page.projectInfo("SOURCES_PATH")
+    
+    def setCurrentVersion(self, version):
+        self.module_page.setProjectInfo("SOURCES_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")
@@ -96,10 +183,11 @@ class BEditingDialog(QDialog):
        # 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 toolchain["path"] == current_toolchain["path"]:
+           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()
@@ -107,20 +195,20 @@ class BEditingDialog(QDialog):
         button_layout.addWidget(cancel_button)
         ok_button = QPushButton(self.tr("Ok"))
         button_layout.addWidget(ok_button)
-        dialog.connect(cancel_button, SIGNAL("clicked()"), dialog.reject)
+        self.connect(cancel_button, SIGNAL("clicked()"), self.reject)
         layout.addLayout(button_layout)
-        dialog.setLayout(layout)
-        dialog.connect(ok_button, SIGNAL("clicked()"), dialog.accept)
-        dialog.setWindowTitle(self.tr("Change toolchain"))
-        if dialog.exec_():
-            toolchain = qvariant_converter.getStringDict(toolchain_page.currentItem().data(Qt.UserRole))
-            toolchain_page.setProjectInfo("TOOLCHAIN", toolchain)
-    
-    def changeBertosVersion(self):
-        dialog = QDialog()
+        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()
         version_page.reloadData()
+       self.version_page = version_page
         layout.addWidget(version_page)
         button_layout = QHBoxLayout()
         button_layout.addStretch()
@@ -128,64 +216,12 @@ class BEditingDialog(QDialog):
         button_layout.addWidget(cancel_button)
         ok_button = QPushButton(self.tr("Ok"))
         button_layout.addWidget(ok_button)
-        dialog.connect(cancel_button, SIGNAL("clicked()"), dialog.reject)
+        self.connect(cancel_button, SIGNAL("clicked()"), self.reject)
         layout.addLayout(button_layout)
-        dialog.setLayout(layout)
-        dialog.connect(ok_button, SIGNAL("clicked()"), dialog.accept)
+        self.setLayout(layout)
+        self.connect(ok_button, SIGNAL("clicked()"), self.accept)
         current_version = version_page.projectInfo("SOURCES_PATH")
-        dialog.setWindowTitle(self.tr("Change BeRTOS version"))
-        if dialog.exec_():
-            version = qvariant_converter.getString(version_page.currentItem().data(Qt.UserRole))
-            if version != current_version:
-                if QMessageBox.question(
-                    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:
-                    version_page.setProjectInfo("SOURCES_PATH", version)
-                    version_page.setProjectInfo("OLD_SOURCES_PATH", current_version)
-                    enabled_modules = bertos_utils.enabledModules(version_page.project())
-                    old_configuration = version_page.projectInfo("CONFIGURATIONS")
-                    bertos_utils.loadSourceTree(version_page.project())
-                    bertos_utils.loadModuleData(version_page.project())
-                    new_configuration = 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
-                    version_page.setProjectInfo("CONFIGURATIONS", merged_configuration)
-                    bertos_utils.setEnabledModules(version_page.project(), enabled_modules)
-                    self.module_page.fillModuleTree()
-               else:
-                   # Rollback version to the previous selected one.
-                   version_page.setProjectInfo("SOURCES_PATH", current_version)
-
-    def apply(self):
-        createBertosProject(self.module_page.project(), edit=True)
-        self.accept()
-
-    def toolchains(self):
-        return self.module_page.toolchains()
-    
-    def currentToolchain(self):
-        return self.module_page.projectInfo("TOOLCHAIN")
-    
-    def setCurrentToolchain(self, toolchain):
-        self.module_page.setProjectInfo("TOOLCHAIN", toolchain)
-
-    def versions(self):
-        return self.module_page.versions()
-
-    def currentVersion(self):
-        return self.module_page.projectInfo("SOURCES_PATH")
-    
-    def setCurrentVersion(self, version):
-        self.module_page.setProjectInfo("SOURCES_PATH", version)
-
+        self.setWindowTitle(self.tr("Change BeRTOS version"))
 
 
 def main():