src/eric7/QScintilla/SpellingDictionaryEditDialog.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2012 - 2022 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 PyQt6.QtCore import pyqtSlot, Qt, QSortFilterProxyModel, QStringListModel
13 from PyQt6.QtWidgets import QDialog
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
21 dictionaries.
22 """
23 def __init__(self, data, info, parent=None):
24 """
25 Constructor
26
27 @param data contents to be edited (string)
28 @param info info string to show at the header (string)
29 @param parent reference to the parent widget (QWidget)
30 """
31 super().__init__(parent)
32 self.setupUi(self)
33
34 self.infoLabel.setText(info)
35
36 self.__model = QStringListModel(
37 [line.strip() for line in data.splitlines() if line.strip()],
38 self)
39 self.__model.sort(0)
40 self.__proxyModel = QSortFilterProxyModel(self)
41 self.__proxyModel.setFilterCaseSensitivity(
42 Qt.CaseSensitivity.CaseInsensitive)
43 self.__proxyModel.setDynamicSortFilter(True)
44 self.__proxyModel.setSourceModel(self.__model)
45 self.wordList.setModel(self.__proxyModel)
46
47 self.searchEdit.textChanged.connect(
48 self.__proxyModel.setFilterFixedString)
49
50 self.removeButton.clicked.connect(self.wordList.removeSelected)
51 self.removeAllButton.clicked.connect(self.wordList.removeAll)
52
53 @pyqtSlot()
54 def on_addButton_clicked(self):
55 """
56 Private slot to handle adding an entry.
57 """
58 self.__model.insertRow(self.__model.rowCount())
59 self.wordList.edit(
60 self.__proxyModel.index(self.__model.rowCount() - 1, 0))
61
62 def getData(self):
63 """
64 Public method to get the data.
65
66 @return data of the dialog (string)
67 """
68 return os.linesep.join(
69 [line.strip() for line in self.__model.stringList()
70 if line.strip()]) + os.linesep

eric ide

mercurial