4 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
9 # Author: Lorenzo Berni <duplo@develer.com>
12 from PyQt4.QtCore import *
13 from PyQt4.QtGui import *
14 import PyQt4.uic as uic
16 import qvariant_converter
20 class BToolchainSearch(QDialog):
22 Dialog that permits to choice the settings for the toolchain search procedure.
26 QDialog.__init__(self)
28 self._connectSignals()
29 self.setWindowTitle(self.tr("Toolchain search page"))
33 Sets up the user interface.
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()
41 self._setSearchButton()
43 def _connectSignals(self):
45 Connects the signals with the related slots.
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)
53 def _setSearchButton(self):
55 Toggles the 'searchButton' evaluating the settings.
57 self.content.searchButton.setDefault(True)
58 self.content.searchButton.setEnabled(self.content.pathBox.isChecked() or self.content.customDirList.count() != 0)
60 def _populateDirList(self):
62 Fills the dir list with the directories stored in the QSettings.
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)
69 def _setPathSearch(self):
71 Sets the path search checkbox to the stored value.
73 pathSearch = qvariant_converter.getBool(QApplication.instance().settings.value(QString("path_search")))
74 self.content.pathBox.setChecked(pathSearch)
76 def _stateChanged(self, state):
78 Slot called when the path search checkbox state changes. Stores the value in the QSettings.
80 QApplication.instance().settings.setValue(QString("path_search"), QVariant(state != 0))
81 self._setSearchButton()
85 Slot called when the user adds a dir.
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()
99 Slot called when the user removes a dir.
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()