From 107cf69bcaae23a972ff33a805c60a37bd0a1238 Mon Sep 17 00:00:00 2001 From: duplo Date: Wed, 1 Apr 2009 17:28:54 +0000 Subject: [PATCH] Add the project editing functionality git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2461 38d2e660-2303-0410-9eaa-f027e97ec537 --- wizard/BOpenPage.py | 45 +++++++++++++++++++++++ wizard/BVersionPage.py | 30 +++++++++++----- wizard/bertos.py | 3 +- wizard/ui/project_select.ui | 72 +++++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+), 10 deletions(-) create mode 100644 wizard/BOpenPage.py create mode 100644 wizard/ui/project_select.ui diff --git a/wizard/BOpenPage.py b/wizard/BOpenPage.py new file mode 100644 index 00000000..b35a9655 --- /dev/null +++ b/wizard/BOpenPage.py @@ -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 +# + +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) + + #### + diff --git a/wizard/BVersionPage.py b/wizard/BVersionPage.py index e7da3bc5..e4cb8d2c 100644 --- a/wizard/BVersionPage.py +++ b/wizard/BVersionPage.py @@ -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 diff --git a/wizard/bertos.py b/wizard/bertos.py index 0c110b97..594587be 100755 --- a/wizard/bertos.py +++ b/wizard/bertos.py @@ -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 index 00000000..36995c61 --- /dev/null +++ b/wizard/ui/project_select.ui @@ -0,0 +1,72 @@ + + + Form + + + + 0 + 0 + 397 + 143 + + + + Form + + + + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + Project name: + + + + + + + + 0 + 0 + + + + Project folder: + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.25.1