Add preset feature.
authorduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 24 May 2010 13:25:15 +0000 (13:25 +0000)
committerduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 24 May 2010 13:25:15 +0000 (13:25 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3806 38d2e660-2303-0410-9eaa-f027e97ec537

wizard/BBoardPage.py
wizard/BProject.py
wizard/BProjectPresets.py [new file with mode: 0644]
wizard/bertos.py
wizard/bertos.qrc
wizard/const.py
wizard/images/default_board_icon.png [new file with mode: 0755]
wizard/images/default_board_image.png [new file with mode: 0755]
wizard/ui/board_select.ui
wizard/ui/preset_page.ui [new file with mode: 0644]
wizard/ui/project_presets.ui [new file with mode: 0644]

index 5d83fda38ddab5a030171e445baee875e5f2b597..0877ea50194bc372c667974bc9df5d01ba37abce 100644 (file)
@@ -64,13 +64,14 @@ class BBoardPage(BWizardPage):
         """
         Overload of the QWizardPage isComplete method.
         """
-        return False
-
-    # def nextId(self):
-    #     """
-    #     Overload of the QWizardPage nextId method.
-    #     """
-    #     return self.wizard().pageIndex(BRoutePage)
+        if self.selected:
+            preset_path = qvariant_converter.getDict(self.selected.data(Qt.UserRole))
+            preset_path = qvariant_converter.getStringDict(preset_path["info"])
+            preset_path = preset_path["path"]
+            self.setProjectInfo("PROJECT_BOARD", preset_path)
+            return True
+        else:
+            return False
 
     ####
 
@@ -86,6 +87,8 @@ class BBoardPage(BWizardPage):
         """
         Overload of the BWizardPage connectSignals method.
         """
+        self.connect(self.pageContent.boardList, SIGNAL("itemSelectionChanged()"), self.updateUi)
+        self.connect(self.pageContent.boardList, SIGNAL("itemSelectionChanged()"), self, SIGNAL("completeChanged()"))
 
     def reloadData(self):
         """
@@ -95,17 +98,40 @@ class BBoardPage(BWizardPage):
         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, _cmp)
+        preset_list = sorted(preset_list.values(), _cmp)
         self.setItems(preset_list)
 
     ####
 
     ## Slots ##
 
+    def updateUi(self):
+        if self.selected:
+            info_dict = qvariant_converter.getDict(self.selected.data(Qt.UserRole))
+            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"
+            self.pageContent.descriptionLabel.setText(description)
+            self.pageContent.imageLabel.setPixmap(QPixmap(image))
 
     ####
 
     def setItems(self, preset_list):
         self.pageContent.boardList.clear()
-        for item in preset_list:
-            self.pageContent.boardList.addItem(item["info"].get("name", item["info"]["filename"]))
\ No newline at end of file
+        selected_board = self.projectInfo("PROJECT_BOARD")
+        for item_data in preset_list:
+            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 = QListWidgetItem(QIcon(item_icon), item_name)
+            item.setData(Qt.UserRole, qvariant_converter.convertDict(item_data))
+            self.pageContent.boardList.addItem(item)
+            if selected_board and selected_board == item_data["info"]["path"]:
+                self.pageContent.boardList.setCurrentItem(item)
+
+    @property
+    def selected(self):
+        return self.pageContent.boardList.currentItem()
\ No newline at end of file
index c2f6613a5f5fe0557ae8837f2bace3dc1f7e3e04..4564f79d418bbf2561164809c6b0fd62e020b6bb 100644 (file)
@@ -209,14 +209,14 @@ class BProject(object):
         _tree["info"] = self._loadPresetInfo(os.path.join(path, const.PREDEFINED_BOARD_SPEC_FILE))
         _tree["info"]["filename"] = os.path.basename(path)
         _tree["info"]["path"] = path
-        _tree["children"] = []
+        _tree["children"] = {}
         entries = set(os.listdir(path))
         for entry in entries:
             _path = os.path.join(path, entry)
             if os.path.isdir(_path):
                 sub_entries = set(os.listdir(_path))
                 if const.PREDEFINED_BOARD_SPEC_FILE in sub_entries:
-                    _tree["children"].append(self._loadProjectPresetTree(_path))
+                    _tree["children"][_path] = self._loadProjectPresetTree(_path)
         # Add into the info dict the dir type (dir/project)
         if _tree["children"]:
             _tree["info"]["type"] = "dir"
diff --git a/wizard/BProjectPresets.py b/wizard/BProjectPresets.py
new file mode 100644 (file)
index 0000000..c0381a5
--- /dev/null
@@ -0,0 +1,146 @@
+#!/usr/bin/env python
+# encoding: utf-8
+#
+# This file is part of slimqc.
+#
+# Bertos is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+# As a special exception, you may use this file as part of a free software
+# library without restriction.  Specifically, if other files instantiate
+# templates or use macros or inline functions from this file, or you compile
+# this file and link it with other files to produce an executable, this
+# file does not by itself cause the resulting executable to be covered by
+# the GNU General Public License.  This exception does not however
+# invalidate any other reasons why the executable file might be covered by
+# the GNU General Public License.
+#
+# Copyright 2010 Develer S.r.l. (http://www.develer.com/)
+#
+# $Id$
+#
+# Author: Lorenzo Berni <duplo@develer.com>
+#
+
+import os
+
+from PyQt4 import uic
+
+from PyQt4.QtCore import *
+from PyQt4.QtGui import *
+
+from BWizardPage import BWizardPage
+
+import const
+import qvariant_converter
+
+class BProjectPresetsPage(QWidget):
+    def __init__(self, preset_data, parent=None):
+        QWidget.__init__(self, parent)
+        self.pageContent = uic.loadUi(os.path.join(const.DATA_DIR, const.UI_LOCATION, "preset_page.ui"), None)
+        self.project = QApplication.instance().project
+        self.settings = QApplication.instance().settings
+        self.preset_data = preset_data
+        layout = QVBoxLayout()
+        layout.addWidget(self.pageContent)
+        self.setLayout(layout)
+        self.setupUi()
+        self.connectSignals()
+
+    def setupUi(self):
+        self.pageContent.presetList.clear()
+        def _cmp(x, y):
+            return cmp(x["info"].get('ord', 0), y["info"].get('ord', 0))
+        for preset in sorted(self.preset_data["children"].values(), _cmp):
+            item_name = preset["info"].get("name", preset["info"]["filename"])
+            item_icon = os.path.join(preset["info"]["path"], const.PREDEFINED_BOARD_ICON_FILE)
+            if not os.path.exists(item_icon):
+                item_icon = const.PREDEFINED_BOARD_DEFAULT_ICON
+            item_icon = QIcon(item_icon)
+            item = QListWidgetItem(item_icon, item_name)
+            item.setData(Qt.UserRole, qvariant_converter.convertString(preset["info"]["path"]))
+            self.pageContent.presetList.addItem(item)
+        self.pageContent.presetList.setCurrentRow(0)
+        self.updateUi()
+
+    def connectSignals(self):
+        self.connect(self.pageContent.presetList, SIGNAL("itemSelectionChanged()"), self.updateUi)
+        self.connect(self.pageContent.presetList, SIGNAL("itemSelectionChanged()"), self, SIGNAL("completeChanged()"))
+
+    def updateUi(self):
+        if self.selected:
+            preset_path = qvariant_converter.getString(self.selected.data(Qt.UserRole))
+            preset = self.preset_data["children"][preset_path]
+            self.pageContent.descriptionLabel.setText(preset["info"].get("description", ""))
+            image = os.path.join(preset["info"]["path"], const.PREDEFINED_BOARD_IMAGE_FILE)
+            if not os.path.exists(image):
+                image = const.PREDEFINED_BOARD_DEFAULT_IMAGE
+            self.pageContent.imageLabel.setPixmap(QPixmap(image))
+    
+    @property
+    def selected(self):
+        return self.pageContent.presetList.currentItem()
+        
+
+class BProjectPresets(BWizardPage):
+    def __init__(self):
+        BWizardPage.__init__(self, const.UI_LOCATION + "/project_presets.ui")
+
+    ## Overloaded QWizardPage methods ##
+
+    def isComplete(self):
+        current_widget = self.pageContent.boardTabWidget.currentWidget()
+        preset_path = None
+        if current_widget:
+            current_item = current_widget.pageContent.presetList.currentItem()
+            if current_item:
+                preset_path = current_item.data(Qt.UserRole)
+                preset_path = qvariant_converter.getString(preset_path)
+        if preset_path:
+            self.setProjectInfo("PROJECT_PRESET", preset_path)
+            return True
+        else:
+            self.setProjectInfo("PROJECT_PRESET", None)
+            return False
+    ####
+    
+    ## Overloaded BWizardPage methods ##
+    
+    def reloadData(self):
+        preset_path = self.projectInfo("PROJECT_BOARD")
+        preset_tree = self.projectInfo("PRESET_TREE")
+        preset_list = preset_tree["children"][preset_path]["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.setupTabs(preset_list)
+
+    def connectSignals(self):
+        self.connect(self.pageContent.boardTabWidget, SIGNAL("currentChanged(int)"), self, SIGNAL("completeChanged()"))
+
+    ####
+    
+    ## Slots ##
+    ####
+
+    def setupTabs(self, preset_list):
+        self.pageContent.boardTabWidget.clear()
+        for preset in preset_list:
+            icon = os.path.join(preset["info"]["path"], ".icon.png")
+            preset_page = BProjectPresetsPage(preset)
+            if os.path.exists(icon):
+                self.pageContent.boardTabWidget.addTab(preset_page, QIcon(icon), preset["info"].get("name", preset["info"]["filename"]))
+            else:
+                self.pageContent.boardTabWidget.addTab(preset_page, preset["info"].get("name", preset["info"]["filename"]))
+            self.connect(preset_page, SIGNAL("completeChanged()"), self, SIGNAL("completeChanged()"))
\ No newline at end of file
index 65e578ccdaa4e787a4f5d4731a89b3b44ce464fe..abee435b7f05a033f0cf030bb17b2b99ce08a3b4 100755 (executable)
@@ -50,6 +50,7 @@ from BIntroPage import BIntroPage
 from BFolderPage import BFolderPage
 from BTypePage import BTypePage
 from BBoardPage import BBoardPage
+from BProjectPresets import BProjectPresets
 from BRoutePage import BRoutePage
 from BOpenPage import BOpenPage
 from BVersionPage import BVersionPage
@@ -68,7 +69,7 @@ from LoadException import VersionException, ToolchainException
 
 def newProject():
     QApplication.instance().project = BProject()
-    page_list = [BIntroPage, BFolderPage, BVersionPage, BTypePage, BBoardPage, BRoutePage, BCpuPage, BToolchainPage, BModulePage, BOutputPage, BCreationPage, BFinalPage]
+    page_list = [BIntroPage, BFolderPage, BVersionPage, BTypePage, BBoardPage, BProjectPresets, BRoutePage, BCpuPage, BToolchainPage, BModulePage, BOutputPage, BCreationPage, BFinalPage]
     wizard = BWizard(page_list)
     wizard.show()
     wizard.exec_()
index 34f8ccc597ca0a9a4ad49e1e10c0a9198c68654c..e7376c7faabbde4e9460352611d56c504e523c22 100644 (file)
@@ -12,5 +12,7 @@
        <file>images/logo.png</file>
        <file>images/default_dir_icon.png</file>
        <file>images/default_project_icon.png</file>
+       <file>images/default_board_image.png</file>
+       <file>images/default_board_icon.png</file>
   </qresource>
 </RCC>
index e048e685055b5297830c4d968cb19bd296ca7c0c..863f45da3b1e3593067f171df8e5ef51c686763d 100644 (file)
@@ -44,10 +44,13 @@ del _tmp
 PREDEFINED_BOARDS_DIR = 'boards'
 PREDEFINED_BOARD_SPEC_FILE = '.spec'
 PREDEFINED_BOARD_ICON_FILE = '.icon.png'
+PREDEFINED_BOARD_IMAGE_FILE = '.image.png'
 
 # Predefined icons in resouces
 PREDEFINED_BOARD_DEFAULT_DIR_ICON = ':images/default_dir_icon.png'
 PREDEFINED_BOARD_DEFAULT_PROJECT_ICON = ':images/default_project_icon.png'
+PREDEFINED_BOARD_DEFAULT_ICON = ':images/default_board_icon.png'
+PREDEFINED_BOARD_DEFAULT_IMAGE = ':images/default_board_image.png'
 # PREDEFINED_BOARD_SPEC_INFO = {
 #    'name': <name of the board/directory>,
 #    'description': <description of the board/directory>,
diff --git a/wizard/images/default_board_icon.png b/wizard/images/default_board_icon.png
new file mode 100755 (executable)
index 0000000..c7989f7
Binary files /dev/null and b/wizard/images/default_board_icon.png differ
diff --git a/wizard/images/default_board_image.png b/wizard/images/default_board_image.png
new file mode 100755 (executable)
index 0000000..c7989f7
Binary files /dev/null and b/wizard/images/default_board_image.png differ
index 48da358947b2ecb09c51822e06cb2a1fec6b35b8..cca3695fa4f0a81766fa819f032d78a527330d61 100644 (file)
        </property>
       </widget>
      </item>
-     <item>
-      <widget class="QLabel" name="imageLabel">
-       <property name="text">
-        <string/>
-       </property>
-      </widget>
-     </item>
      <item>
       <spacer name="verticalSpacer">
        <property name="orientation">
        </property>
       </spacer>
      </item>
+     <item>
+      <widget class="QLabel" name="imageLabel">
+       <property name="text">
+        <string/>
+       </property>
+      </widget>
+     </item>
     </layout>
    </item>
   </layout>
diff --git a/wizard/ui/preset_page.ui b/wizard/ui/preset_page.ui
new file mode 100644 (file)
index 0000000..3418f12
--- /dev/null
@@ -0,0 +1,55 @@
+<?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>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <widget class="QListWidget" name="presetList"/>
+   </item>
+   <item>
+    <layout class="QVBoxLayout" name="verticalLayout">
+     <item>
+      <widget class="QLabel" name="imageLabel">
+       <property name="text">
+        <string/>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="verticalSpacer">
+       <property name="orientation">
+        <enum>Qt::Vertical</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>20</width>
+         <height>40</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QLabel" name="descriptionLabel">
+       <property name="text">
+        <string/>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/wizard/ui/project_presets.ui b/wizard/ui/project_presets.ui
new file mode 100644 (file)
index 0000000..2925c82
--- /dev/null
@@ -0,0 +1,28 @@
+<?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>501</width>
+    <height>403</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <widget class="QTabWidget" name="boardTabWidget">
+     <property name="currentIndex">
+      <number>-1</number>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>