eric6/QScintilla/SpellingDictionaryEditDialog.py

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

eric ide

mercurial