|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to edit the various spell checking dictionaries. |
|
8 """ |
|
9 |
|
10 import os |
|
11 |
|
12 from PyQt4.QtCore import pyqtSlot, Qt |
|
13 from PyQt4.QtGui import QDialog, QStringListModel, QSortFilterProxyModel |
|
14 |
|
15 from .Ui_SpellingDictionaryEditDialog import Ui_SpellingDictionaryEditDialog |
|
16 |
|
17 |
|
18 class SpellingDictionaryEditDialog(QDialog, Ui_SpellingDictionaryEditDialog): |
|
19 """ |
|
20 Class implementing a dialog to edit the various spell checking dictionaries. |
|
21 """ |
|
22 def __init__(self, data, info, parent=None): |
|
23 """ |
|
24 Constructor |
|
25 |
|
26 @param data contents to be edited (string) |
|
27 @param info info string to show at the header (string) |
|
28 @param parent reference to the parent widget (QWidget) |
|
29 """ |
|
30 super().__init__(parent) |
|
31 self.setupUi(self) |
|
32 |
|
33 self.infoLabel.setText(info) |
|
34 |
|
35 self.__model = QStringListModel(data.splitlines(), self) |
|
36 self.__model.sort(0) |
|
37 self.__proxyModel = QSortFilterProxyModel(self) |
|
38 self.__proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive) |
|
39 self.__proxyModel.setDynamicSortFilter(True) |
|
40 self.__proxyModel.setSourceModel(self.__model) |
|
41 self.wordList.setModel(self.__proxyModel) |
|
42 |
|
43 self.searchEdit.textChanged.connect(self.__proxyModel.setFilterFixedString) |
|
44 |
|
45 self.removeButton.clicked[()].connect(self.wordList.removeSelected) |
|
46 self.removeAllButton.clicked[()].connect(self.wordList.removeAll) |
|
47 |
|
48 @pyqtSlot() |
|
49 def on_addButton_clicked(self): |
|
50 """ |
|
51 Private slot to handle adding an entry. |
|
52 """ |
|
53 self.__model.insertRow(self.__model.rowCount()) |
|
54 self.wordList.edit(self.__proxyModel.index(self.__model.rowCount() - 1, 0)) |
|
55 |
|
56 def getData(self): |
|
57 """ |
|
58 Public method to get the data. |
|
59 |
|
60 @return data of the dialog (string) |
|
61 """ |
|
62 return os.linesep.join([line for line in self.__model.stringList() if line]) |