Remove the base/advance choice page.
[bertos.git] / wizard / BBoardPage.py
index 0877ea50194bc372c667974bc9df5d01ba37abce..6d7fc89b4d0347261ded550efb51f19b52f07202 100644 (file)
@@ -46,7 +46,7 @@ from BRoutePage import BRoutePage
 
 import const
 import qvariant_converter
-from bertos_utils import presetList
+from bertos_utils import presetList, _cmp
 
 class BBoardPage(BWizardPage):
     """
@@ -69,10 +69,18 @@ class BBoardPage(BWizardPage):
             preset_path = qvariant_converter.getStringDict(preset_path["info"])
             preset_path = preset_path["path"]
             self.setProjectInfo("PROJECT_BOARD", preset_path)
+            self.setProjectInfo("PROJECT_FROM_PRESET", True)
             return True
         else:
             return False
 
+    def nextId(self):
+        wizard = self.wizard()
+        if not self.projectInfo("PROJECT_FROM_PRESET"):
+            return wizard.pageIndex(BCpuPage)
+        else:
+            return QWizardPage.nextId(self)
+
     ####
 
     ## Overloaded BWizardPage methods ##
@@ -89,15 +97,15 @@ class BBoardPage(BWizardPage):
         """
         self.connect(self.pageContent.boardList, SIGNAL("itemSelectionChanged()"), self.updateUi)
         self.connect(self.pageContent.boardList, SIGNAL("itemSelectionChanged()"), self, SIGNAL("completeChanged()"))
+        self.connect(self.pageContent.customButton, SIGNAL("clicked()"), self.customButtonClicked)
 
     def reloadData(self):
         """
         Overload of the BWizardPage reloadData method.
         """
+        self.project.loadProjectPresets()
         preset_list = self.projectInfo("PRESET_TREE")
         preset_list = preset_list["children"]
-        def _cmp(x, y):
-            return cmp(x["info"].get('ord', 0), y["info"].get('ord', 0))
         preset_list = sorted(preset_list.values(), _cmp)
         self.setItems(preset_list)
 
@@ -111,10 +119,16 @@ class BBoardPage(BWizardPage):
             info_dict = qvariant_converter.getStringDict(info_dict["info"])
             description = info_dict.get("description", "")
             image = os.path.join(info_dict["path"], ".image.png")
-            if not os.path.exists(image):
-                image = ":/images/default_board_image.png"
+            if os.path.exists(image):
+                self.pageContent.imageLabel.setPixmap(QPixmap(image))
+                self.pageContent.imageLabel.setVisible(True)
+            else:
+                self.pageContent.imageLabel.setVisible(False)
             self.pageContent.descriptionLabel.setText(description)
-            self.pageContent.imageLabel.setPixmap(QPixmap(image))
+
+    def customButtonClicked(self):
+        self.setProjectInfo("PROJECT_FROM_PRESET", False)
+        self.wizard().next()
 
     ####
 
@@ -125,7 +139,7 @@ class BBoardPage(BWizardPage):
             item_name = item_data["info"].get("name", item_data["info"]["filename"])
             item_icon = os.path.join(item_data["info"]["path"], const.PREDEFINED_BOARD_ICON_FILE)
             if not os.path.exists(item_icon):
-                item_icon = ":/images/default_board_icon.png"
+                item_icon = const.PREDEFINED_BOARD_DEFAULT_ICON
             item = QListWidgetItem(QIcon(item_icon), item_name)
             item.setData(Qt.UserRole, qvariant_converter.convertDict(item_data))
             self.pageContent.boardList.addItem(item)