Add infrastructure for recognize modules supported by the selected cpu
[bertos.git] / wizard / BToolchainSearch.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 PyQt4.QtCore import *
13 from PyQt4.QtGui import *
14 import PyQt4.uic as uic
15
16 import qvariant_converter
17
18 from const import *
19
20 class BToolchainSearch(QDialog):
21     """
22     Dialog that permits to choice the settings for the toolchain search procedure.
23     """
24     
25     def __init__(self):
26         QDialog.__init__(self)
27         self._setupUi()
28         self._connectSignals()
29         self.setWindowTitle(self.tr("Toolchain search page"))
30     
31     def _setupUi(self):
32         """
33         Sets up the user interface.
34         """
35         self.content = uic.loadUi(UI_LOCATION + "/toolchain_search.ui", None)
36         layout = QVBoxLayout()
37         layout.addWidget(self.content)
38         self.setLayout(layout)
39         self._populateDirList()
40         self._setPathSearch()
41         self._setSearchButton()
42     
43     def _connectSignals(self):
44         """
45         Connects the signals with the related slots.
46         """
47         self.connect(self.content.pathBox, SIGNAL("stateChanged(int)"), self._stateChanged)
48         self.connect(self.content.addButton, SIGNAL("clicked()"), self._addDir)
49         self.connect(self.content.removeButton, SIGNAL("clicked()"), self._removeDir)
50         self.connect(self.content.cancelButton, SIGNAL("clicked()"), self.reject)
51         self.connect(self.content.searchButton, SIGNAL("clicked()"), self.accept)
52         
53     def _setSearchButton(self):
54         """
55         Toggles the 'searchButton' evaluating the settings.
56         """
57         self.content.searchButton.setDefault(True)
58         self.content.searchButton.setEnabled(self.content.pathBox.isChecked() or self.content.customDirList.count() != 0)
59     
60     def _populateDirList(self):
61         """
62         Fills the dir list with the directories stored in the QSettings.
63         """
64         search_dir_list = qvariant_converter.getStringList(QApplication.instance().settings.value("search_dir_list"))
65         for element in search_dir_list:
66             item = QListWidgetItem(element)
67             self.content.customDirList.addItem(item)
68     
69     def _setPathSearch(self):
70         """
71         Sets the path search checkbox to the stored value.
72         """
73         pathSearch = qvariant_converter.getBool(QApplication.instance().settings.value(QString("path_search")))
74         self.content.pathBox.setChecked(pathSearch)
75     
76     def _stateChanged(self, state):
77         """
78         Slot called when the path search checkbox state changes. Stores the value in the QSettings.
79         """
80         QApplication.instance().settings.setValue(QString("path_search"), QVariant(state != 0))
81         self._setSearchButton()
82     
83     def _addDir(self):
84         """
85         Slot called when the user adds a dir.
86         """
87         directory = QFileDialog.getExistingDirectory(self, self.tr("Open Directory"), "", QFileDialog.ShowDirsOnly)
88         if not directory.isEmpty():
89             directory = unicode(directory)
90             item = QListWidgetItem(directory)
91             self.content.customDirList.addItem(item)
92             search_dir_list = qvariant_converter.getStringList(QApplication.instance().settings.value("search_dir_list"))
93             search_dir_list = set(search_dir_list + [directory])
94             QApplication.instance().settings.setValue(QString("search_dir_list"), qvariant_converter.convertStringList(list(search_dir_list)))
95             self._setSearchButton()
96     
97     def _removeDir(self):
98         """
99         Slot called when the user removes a dir.
100         """
101         if self.content.customDirList.currentRow() != -1:
102             item = self.content.customDirList.takeItem(self.content.customDirList.currentRow())
103             search_dir_list = qvariant_converter.getStringList(QApplication.instance().settings.value(QString("search_dir_list")))
104             search_dir_list = set(search_dir_list)
105             search_dir_list.remove(unicode(item.text()))
106             QApplication.instance().settings.setValue(QString("search_dir_list"), qvariant_converter.convertStringList(list(search_dir_list)))
107             self._setSearchButton()
108