Separate toolchain search from toolchain selection
[bertos.git] / wizard / BToolchainPage.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
5 # All rights reserved.
6 #
7 # $Id:$
8 #
9 # Author: Lorenzo Berni <duplo@develer.com>
10 #
11
12 from BWizardPage import *
13 import BToolchainSearch
14 import bertos_utils
15
16 class BToolchainPage(BWizardPage):
17     
18     def __init__(self):
19         BWizardPage.__init__(self, "toolchain_select.ui")
20         self.setTitle(self.tr("Select toolchain"))
21         self._populateToolchainList()
22         self._connectSignals()
23     
24     def _updateUi(self):
25         if self.pageContent.customDirBox.isChecked():
26             self._enableCustomDir()
27         else:
28             self._disableCustomDir()
29         if self.pageContent.pathBox.isChecked() or (self.pageContent.customDirBox.isChecked() and self.pageContent.customDirList.count() != 0):
30             self.pageContent.doSearchButton.setEnabled(True)
31         else:
32             self.pageContent.doSearchButton.setEnabled(False)
33     
34     def _populateToolchainList(self):
35         toolchains = self._settingsRetrieve("toolchains").toList()
36         for element in toolchains:
37             item = QListWidgetItem(element.toString())
38             item.setData(Qt.UserRole, element)
39             self.pageContent.toolchainList.addItem(item)
40             
41     def _clearList(self):
42         self.pageContent.toolchainList.clear()
43     
44     def _selectionChanged(self):
45         self.emit(SIGNAL("completeChanged()"))
46     
47     def _search(self):
48         pass
49         
50     
51     def _connectSignals(self):
52         self.connect(self.pageContent.toolchainList, SIGNAL("itemSelectionChanged()"), self._selectionChanged)
53         self.connect(self.pageContent.addButton, SIGNAL("clicked()"), self.addToolchain)
54         self.connect(self.pageContent.removeButton, SIGNAL("clicked()"), self.removeToolchain)
55         self.connect(self.pageContent.searchButton, SIGNAL("clicked()"), self.searchToolchain)
56     
57     def addToolchain(self):
58         sel_toolchain = QFileDialog.getOpenFileName(self, self.tr("Choose the toolchain"), "")
59         if not sel_toolchain.isEmpty():
60             item = QListWidgetItem(sel_toolchain)
61             item.setData(Qt.UserRole, QVariant(sel_toolchain))
62             self.pageContent.toolchainList.addItem(item)
63             toolchains = self._settingsRetrieve("toolchains").toList()
64             toolchains = set([toolchain.toString() for toolchain in toolchains] + [sel_toolchain])
65             self._settingsStore("toolchains", list(toolchains))
66     
67     def removeToolchain(self):
68         if self.pageContent.toolchainList.currentRow() != -1:
69             item = self.pageContent.toolchainList.takeItem(self.pageContent.toolchainList.currentRow())
70             item = item.data(Qt.UserRole).toString()
71             toolchains = self._settingsRetrieve("toolchains").toList()
72             toolchains = [toolchain.toString() for toolchain in toolchains]
73             toolchains.remove(unicode(item))
74             self._settingsStore("toolchains", toolchains)
75     
76     def searchToolchain(self):
77         search = BToolchainSearch.BToolchainSearch()
78         self.connect(search, SIGNAL("accepted()"), self._search)
79         search.exec_()
80     
81     def isComplete(self):
82         if self.pageContent.toolchainList.currentRow() != -1:
83             self._projectInfoStore("TOOLCHAIN", self.pageContent.toolchainList.item(self.pageContent.toolchainList.currentRow()).data(Qt.UserRole).toString())
84             return True
85         else:
86             return False