Add the project editing functionality
authorduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 1 Apr 2009 17:28:54 +0000 (17:28 +0000)
committerduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 1 Apr 2009 17:28:54 +0000 (17:28 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2461 38d2e660-2303-0410-9eaa-f027e97ec537

wizard/BOpenPage.py [new file with mode: 0644]
wizard/BVersionPage.py
wizard/bertos.py
wizard/ui/project_select.ui [new file with mode: 0644]

diff --git a/wizard/BOpenPage.py b/wizard/BOpenPage.py
new file mode 100644 (file)
index 0000000..b35a965
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+# encoding: utf-8
+#
+# Copyright 2009 Develer S.r.l. (http://www.develer.com/)
+# All rights reserved.
+#
+# $Id:$
+#
+# Author: Lorenzo Berni <duplo@develer.com>
+#
+
+import os
+import pickle
+
+from PyQt4.QtGui import *
+from PyQt4.QtCore import *
+
+from BWizardPage import *
+import bertos_utils
+
+from const import *
+
+class BOpenPage(BWizardPage):
+    """
+    Initial page of the wizard. Permit to select the project name and the directory
+    where the project will be created.
+    """
+    
+    def __init__(self):
+        BWizardPage.__init__(self, UI_LOCATION + "/project_select.ui")
+        self.setTitle(self.tr("Open an existing BeRTOS project"))
+    
+    ## Overloaded BWizardPage methods ##
+    
+    def reloadData(self):
+        project = unicode(QFileDialog.getOpenFileName(self, self.tr("Open project file"), os.path.expanduser("~"), self.tr("Project file (project.bertos)")))
+        if project == "":
+            QApplication.instance().quit()
+        else:
+            QApplication.instance().project = pickle.loads(open(project, "r").read())
+            self.pageContent.nameLabel.setText(os.path.basename(project.replace(os.sep + "project.bertos", "")))
+            self.pageContent.dirLabel.setText(project)
+    
+    ####
+    
index e7da3bc54724eb69d9d57cb82b3f632a1cbc3e64..e4cb8d2ca90a2b52779ba56f3c0ebca2d04bc10f 100644 (file)
@@ -48,13 +48,6 @@ class BVersionPage(BWizardPage):
     
     ## Overloaded BWizardPage methods ##
 
-    def setupUi(self):
-        """
-        Overload of the BWizardPage setupUi method.
-        """
-        self.fillVersionList()
-        self.pageContent.versionList.setCurrentRow(-1)
-
     def connectSignals(self):
         """
         Overload of the BWizardPage connectSignals method.
@@ -65,6 +58,13 @@ class BVersionPage(BWizardPage):
         # Fake signal connection for the update button
         self.connect(self.pageContent.updateButton, SIGNAL("clicked()"), self.updateClicked)
     
+    def reloadData(self):
+        """
+        Overload of the BWizardPage reloadData method.
+        """
+        self.pageContent.versionList.setCurrentRow(-1)
+        self.fillVersionList()
+    
     ####
     
     ## Slots ##
@@ -121,21 +121,33 @@ class BVersionPage(BWizardPage):
         
     def insertListElement(self, directory):
         """
-        Inserts the given directory in the version list.
+        Inserts the given directory in the version list and returns the
+        inserted item.
         """
         if bertos_utils.isBertosDir(directory):
             item = QListWidgetItem(QIcon(":/images/ok.png"), bertos_utils.bertosVersion(directory) + " (\"" + os.path.normpath(directory) + "\")")
             item.setData(Qt.UserRole, qvariant_converter.convertString(directory))
             self.pageContent.versionList.addItem(item)
+            return item
         elif len(directory) > 0:
             item = QListWidgetItem(QIcon(":/images/warning.png"), "UNKNOWN" + " (\"" + os.path.normpath(directory) + "\")")
             item.setData(Qt.UserRole, qvariant_converter.convertString(directory))
             self.pageContent.versionList.addItem(item)
+            return item
     
     def fillVersionList(self):
         """
         Fills the version list with all the BeRTOS versions founded in the QSettings.
         """
         versions = self.versions()
+        selected = self.projectInfo("SOURCES_PATH")
         for directory in versions:
-            self.insertListElement(directory)
\ No newline at end of file
+            item = self.insertListElement(directory)
+            if not selected is None and selected == directory:
+                self.setCurrentItem(item)
+    
+    def setCurrentItem(self, item):
+        """
+        Select the given item in the version list.
+        """
+        self.pageContent.versionList.setCurrentItem(item)
\ No newline at end of file
index 0c110b97c291339e50d7be7440334481253b616c..594587be23dd923643246398c14199c15843f805 100755 (executable)
@@ -22,6 +22,7 @@ import BStartPage
 import BWizard
 
 from BFolderPage import BFolderPage
+from BOpenPage import BOpenPage
 from BVersionPage import BVersionPage
 from BCpuPage import BCpuPage
 from BToolchainPage import BToolchainPage
@@ -39,7 +40,7 @@ def newProject():
     wizard.exec_()
     
 def editProject():
-    page_list = [BVersionPage, BCpuPage, BToolchainPage, BModulePage, BOutputPage, BCreationPage, BFinalPage]
+    page_list = [BOpenPage, BVersionPage, BCpuPage, BToolchainPage, BModulePage, BOutputPage, BCreationPage, BFinalPage]
     wizard = BWizard.BWizard(page_list)
     wizard.show()
     wizard.exec_()
diff --git a/wizard/ui/project_select.ui b/wizard/ui/project_select.ui
new file mode 100644 (file)
index 0000000..36995c6
--- /dev/null
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Form</class>
+ <widget class="QWidget" name="Form">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>397</width>
+    <height>143</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <layout class="QVBoxLayout" name="verticalLayout_2">
+     <property name="sizeConstraint">
+      <enum>QLayout::SetDefaultConstraint</enum>
+     </property>
+     <item>
+      <widget class="QLabel" name="label">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="text">
+        <string>Project name:</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLabel" name="label_2">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="text">
+        <string>Project folder:</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <layout class="QVBoxLayout" name="verticalLayout">
+     <item>
+      <widget class="QLabel" name="nameLabel">
+       <property name="text">
+        <string/>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLabel" name="dirLabel">
+       <property name="text">
+        <string/>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>