4 # This file is part of BeRTOS.
6 # Bertos is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # As a special exception, you may use this file as part of a free software
21 # library without restriction. Specifically, if other files instantiate
22 # templates or use macros or inline functions from this file, or you compile
23 # this file and link it with other files to produce an executable, this
24 # file does not by itself cause the resulting executable to be covered by
25 # the GNU General Public License. This exception does not however
26 # invalidate any other reasons why the executable file might be covered by
27 # the GNU General Public License.
29 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
33 # Author: Lorenzo Berni <duplo@develer.com>
38 from PyQt4.QtCore import *
39 from PyQt4.QtGui import *
40 import PyQt4.uic as uic
42 import qvariant_converter
46 class BToolchainSearch(QDialog):
48 Dialog that permits to choice the settings for the toolchain search procedure.
52 QDialog.__init__(self)
54 self._connectSignals()
55 self.setWindowTitle(self.tr("Toolchain search page"))
59 Sets up the user interface.
61 self.content = uic.loadUi(os.path.join(const.DATA_DIR, const.UI_LOCATION, "toolchain_search.ui"), None)
62 layout = QVBoxLayout()
63 layout.addWidget(self.content)
64 self.setLayout(layout)
65 self._populateDirList()
67 self._setSearchButton()
69 def _connectSignals(self):
71 Connects the signals with the related slots.
73 self.connect(self.content.pathBox, SIGNAL("stateChanged(int)"), self._stateChanged)
74 self.connect(self.content.addButton, SIGNAL("clicked()"), self._addDir)
75 self.connect(self.content.removeButton, SIGNAL("clicked()"), self._removeDir)
76 self.connect(self.content.cancelButton, SIGNAL("clicked()"), self.reject)
77 self.connect(self.content.searchButton, SIGNAL("clicked()"), self.accept)
79 def _setSearchButton(self):
81 Toggles the 'searchButton' evaluating the settings.
83 self.content.searchButton.setDefault(True)
84 self.content.searchButton.setEnabled(self.content.pathBox.isChecked() or self.content.customDirList.count() != 0)
86 def _populateDirList(self):
88 Fills the dir list with the directories stored in the QSettings.
90 search_dir_list = qvariant_converter.getStringList(QApplication.instance().settings.value("search_dir_list"))
91 for element in search_dir_list:
92 item = QListWidgetItem(element)
93 self.content.customDirList.addItem(item)
95 def _setPathSearch(self):
97 Sets the path search checkbox to the stored value.
99 pathSearch = qvariant_converter.getBool(QApplication.instance().settings.value(QString("path_search")))
100 self.content.pathBox.setChecked(pathSearch)
102 def _stateChanged(self, state):
104 Slot called when the path search checkbox state changes. Stores the value in the QSettings.
106 QApplication.instance().settings.setValue(QString("path_search"), QVariant(state != 0))
107 self._setSearchButton()
111 Slot called when the user adds a dir.
113 directory = QFileDialog.getExistingDirectory(self, self.tr("Open Directory"), "", QFileDialog.ShowDirsOnly)
114 if not directory.isEmpty():
115 directory = unicode(directory)
116 item = QListWidgetItem(directory)
117 self.content.customDirList.addItem(item)
118 search_dir_list = qvariant_converter.getStringList(QApplication.instance().settings.value("search_dir_list"))
119 search_dir_list = set(search_dir_list + [directory])
120 QApplication.instance().settings.setValue(QString("search_dir_list"), qvariant_converter.convertStringList(list(search_dir_list)))
121 self._setSearchButton()
123 def _removeDir(self):
125 Slot called when the user removes a dir.
127 if self.content.customDirList.currentRow() != -1:
128 item = self.content.customDirList.takeItem(self.content.customDirList.currentRow())
129 search_dir_list = qvariant_converter.getStringList(QApplication.instance().settings.value(QString("search_dir_list")))
130 search_dir_list = set(search_dir_list)
131 search_dir_list.remove(unicode(item.text()))
132 QApplication.instance().settings.setValue(QString("search_dir_list"), qvariant_converter.convertStringList(list(search_dir_list)))
133 self._setSearchButton()