Add a stub of the code that will fill all the fields of the board selection Wizard...
authorduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 1 Apr 2010 12:54:31 +0000 (12:54 +0000)
committerduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 1 Apr 2010 12:54:31 +0000 (12:54 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3371 38d2e660-2303-0410-9eaa-f027e97ec537

wizard/BBoardPage.py
wizard/bertos_utils.py
wizard/const.py

index 6b8dddfff2bcc84723cc27848afd27460c00d9a2..80631b598f2c7cbd51b3b53348886661251da28e 100644 (file)
 # Author: Lorenzo Berni <duplo@develer.com>
 #
 
+from PyQt4.QtCore import *
+from PyQt4.QtGui import *
+
 from BWizardPage import BWizardPage
 
-from const import *
+import const
+import qvariant_converter
+from bertos_utils import presetList
 
 class BBoardPage(BWizardPage):
     """
@@ -44,5 +49,62 @@ class BBoardPage(BWizardPage):
     """
     
     def __init__(self):
-        BWizardPage.__init__(self, UI_LOCATION + "/board_select.ui")
+        BWizardPage.__init__(self, const.UI_LOCATION + "/board_select.ui")
         self.setTitle(self.tr("Select the board from the predefined ones"))
+        self._last_selected = None
+
+    ## Overloaded QWizardPage methods ##
+
+    def isComplete(self):
+        """
+        Overload of the QWizardPage isComplete method.
+        """
+        return False
+
+    ####
+
+    ## Overloaded BWizardPage methods ##
+
+    def setupUi(self):
+        """
+        Overload of the BWizardPage setupUi method.
+        """
+        pass
+
+    def connectSignals(self):
+        """
+        Overload of the BWizardPage connectSignals method.
+        """
+        self.connect(self.pageContent.boardList, SIGNAL('itemSelectionChanged()'), self.itemSelectionChanged)
+
+    def reloadData(self):
+        """
+        Overload of the BWizardPage reloadData method.
+        """
+        presets = presetList("/Users/duplo/Development/bertos")
+        self.setProjectInfo("PRESETS", presets)
+        self.populatePresetList()
+
+    def populatePresetList(self):
+        presets = self.projectInfo("PRESETS")
+        for preset, info in presets.items():
+            board_list = self.pageContent.boardList
+            item = QListWidgetItem(info["name"], board_list)
+            item.setData(Qt.UserRole, qvariant_converter.convertString(preset))
+            if self._last_selected == preset:
+                self.pageContent.boardList.setCurrentItem(item)
+        if not self._last_selected and self.pageContent.boardList.count():
+            self.pageContent.boardList.setCurrentRow(0)
+
+    ####
+
+    ## Slots ##
+
+    def itemSelectionChanged(self):
+        preset_path = qvariant_converter.getString(self.pageContent.boardList.currentItem().data(Qt.UserRole))
+        presets = self.projectInfo("PRESETS")
+        selected_preset = presets[preset_path]
+        self.pageContent.descriptionLabel.setText(selected_preset['description'])
+        self._last_selected = preset_path
+
+    ####
index c19f3d5322503c356394d1f1a25d246ea8dec788..a30aaed4cdb37f0a3f4c234d67c801ae4f587dfd 100644 (file)
@@ -45,7 +45,6 @@ import pickle
 import const
 import plugins
 import DefineException
-import BProject
 
 from _wizard_version import WIZARD_VERSION
 
@@ -76,6 +75,26 @@ def enabledModules(project_info):
             enabled_modules.append(name)
     return enabled_modules
 
+def presetList(directory):
+    """
+    Return the list of the preset found in the selected BeRTOS Version.
+    """
+    def getPresetInfo(preset_dir):
+        # Find and returns information about the preset
+        # Keys needed for BBoardPage:
+        #  - "name": <name of the board/preset>
+        #  - "description": <description of the preset>
+
+        # NOTE: this is only a test stub.
+        preset_info = pickle.loads(open(os.path.join(preset_dir, 'info'), "r").read())
+        return preset_info
+    abspath = os.path.join(directory, const.PREDEFINED_BOARDS_DIR)
+    preset_list = dict([
+        (os.path.join(abspath, preset_dir), getPresetInfo(os.path.join(abspath, preset_dir)))
+        for preset_dir in os.listdir(os.path.join(directory, const.PREDEFINED_BOARDS_DIR))
+    ])
+    return preset_list
+
 def mergeSources(srcdir, new_sources, old_sources):
     # The current mergeSources function provide only a raw copy of the sources in the
     # created project.
index 697cd4637c0db2cb44b3d500e5f14203ca5d69c9..3b6add0de74d5c77592669bc6e55c27a4d5911bf 100644 (file)
@@ -41,6 +41,8 @@ if os.path.islink(_tmp):
 DATA_DIR = os.path.dirname(os.path.abspath(_tmp))
 del _tmp
 
+PREDEFINED_BOARDS_DIR = 'predefined_boards'
+
 CPU_DEF = {
     "CPU_NAME": "",
     "CPU_DIR": "",