4 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
9 # Author: Lorenzo Berni <duplo@develer.com>
14 from PyQt4.QtGui import *
15 from BWizardPage import *
17 import qvariant_converter
21 class BVersionPage(BWizardPage):
23 Page of the wizard that permits to choose which BeRTOS version the user wants
24 to use. This page show some pieces of information about the version.
28 BWizardPage.__init__(self, UI_LOCATION + "/bertos_versions.ui")
29 self.setTitle(self.tr("Select the BeRTOS directory"))
30 self.setSubTitle(self.tr("The project created will be based on the BeRTOS version found"))
32 ## Overloaded QWizardPage methods ##
36 Overload of the QWizardPage isComplete method.
38 if self.pageContent.versionList.currentRow() != -1:
39 sources_path = qvariant_converter.getString(self.pageContent.versionList.currentItem().data(Qt.UserRole))
40 # Remove the trailing slash
41 if sources_path.endswith(os.sep):
42 sources_path = sources_path[:-1]
43 self.setProjectInfo("SOURCES_PATH", sources_path)
50 ## Overloaded BWizardPage methods ##
52 def connectSignals(self):
54 Overload of the BWizardPage connectSignals method.
56 self.connect(self.pageContent.versionList, SIGNAL("itemSelectionChanged()"), self.rowChanged)
57 self.connect(self.pageContent.addButton, SIGNAL("clicked()"), self.addVersion)
58 self.connect(self.pageContent.removeButton, SIGNAL("clicked()"), self.removeVersion)
59 # Fake signal connection for the update button
60 self.connect(self.pageContent.updateButton, SIGNAL("clicked()"), self.updateClicked)
64 Overload of the BWizardPage reloadData method.
66 self.resetVersionList()
67 self.pageContent.versionList.setCurrentRow(-1)
68 self.fillVersionList()
72 Overload of the BWizardPage setupUi method.
74 self.pageContent.updateButton.setVisible(False)
82 Slot called when the user add a BeRTOS version.
84 directory = QFileDialog.getExistingDirectory(self, self.tr("Choose a directory"), "", QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks)
85 if not directory.isEmpty():
86 self.storeVersion(unicode(directory))
87 self.pageContent.versionList.clear()
88 self.fillVersionList()
89 self.emit(SIGNAL("completeChanged()"))
91 def removeVersion(self):
93 Slot called when the user remove a BeRTOS version.
95 item = self.pageContent.versionList.takeItem(self.pageContent.versionList.currentRow())
96 self.deleteVersion(qvariant_converter.getString(item.data(Qt.UserRole)))
97 self.emit(SIGNAL("completeChanged()"))
101 Slot called when the user select an entry from the version list.
103 self.emit(SIGNAL("completeChanged()"))
105 def updateClicked(self):
107 Slot called when the user clicks on the 'update' button. It checks for
108 update (TO BE IMPLEMENTED).
114 def storeVersion(self, directory):
116 Stores the directory selected by the user in the QSettings.
118 versions = self.versions()
119 versions = set(versions + [directory])
120 self.setVersions(list(versions))
122 def deleteVersion(self, directory):
124 Removes the given directory from the QSettings.
126 versions = self.versions()
127 versions.remove(directory)
128 self.setVersions(versions)
130 def resetVersionList(self):
132 Remove all the version entries from the list.
134 self.pageContent.versionList.clear()
136 def insertListElement(self, directory):
138 Inserts the given directory in the version list and returns the
141 if bertos_utils.isBertosDir(directory):
142 item = QListWidgetItem(QIcon(":/images/ok.png"), bertos_utils.bertosVersion(directory) + " (\"" + os.path.normpath(directory) + "\")")
143 item.setData(Qt.UserRole, qvariant_converter.convertString(directory))
144 self.pageContent.versionList.addItem(item)
146 elif len(directory) > 0:
147 item = QListWidgetItem(QIcon(":/images/warning.png"), "UNKNOWN" + " (\"" + os.path.normpath(directory) + "\")")
148 item.setData(Qt.UserRole, qvariant_converter.convertString(directory))
149 self.pageContent.versionList.addItem(item)
152 def fillVersionList(self):
154 Fills the version list with all the BeRTOS versions founded in the QSettings.
158 import winreg_importer
159 versions |= set(winreg_importer.getBertosDirs())
160 versions |= set(self.versions())
161 selected = self.projectInfo("SOURCES_PATH")
162 for directory in versions:
163 item = self.insertListElement(directory)
164 if selected and selected == directory:
165 self.setCurrentItem(item)
167 self.setCurrentItem(self.latestVersionItem())
169 def latestVersionItem(self):
171 Returns the latest BeRTOS version founded.
173 latest_version_item = QTableWidgetItem("")
174 for index in range(self.pageContent.versionList.count()):
175 item = self.pageContent.versionList.item(index)
176 version = item.text().split(" (")[0]
177 latest = latest_version_item.text().split(" (")[0]
178 if version != "UNKNOWN" and version > latest:
179 latest_version_item = item
180 return latest_version_item
182 def setCurrentItem(self, item):
184 Select the given item in the version list.
186 self.pageContent.versionList.setCurrentItem(item)