src/eric7/QScintilla/SpellingDictionaryEditDialog.py

Wed, 13 Jul 2022 14:55:47 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 13 Jul 2022 14:55:47 +0200
branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
permissions
-rw-r--r--

Reformatted the source code using the 'Black' utility.

2211
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
8881
54e42bc2437a Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
3 # Copyright (c) 2012 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
2211
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to edit the various spell checking dictionaries.
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
12 from PyQt6.QtCore import pyqtSlot, Qt, QSortFilterProxyModel, QStringListModel
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
13 from PyQt6.QtWidgets import QDialog
2211
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from .Ui_SpellingDictionaryEditDialog import Ui_SpellingDictionaryEditDialog
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 class SpellingDictionaryEditDialog(QDialog, Ui_SpellingDictionaryEditDialog):
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
20 Class implementing a dialog to edit the various spell checking
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
21 dictionaries.
2211
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
23
2211
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 def __init__(self, data, info, parent=None):
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
27
2211
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 @param data contents to be edited (string)
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @param info info string to show at the header (string)
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @param parent reference to the parent widget (QWidget)
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
32 super().__init__(parent)
2211
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 self.setupUi(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
34
2211
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.infoLabel.setText(info)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
36
5439
7ae65fa937a3 Some improvements to the spell checker to deal with empty lines in user or project dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
37 self.__model = QStringListModel(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
38 [line.strip() for line in data.splitlines() if line.strip()], self
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
39 )
2211
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.__model.sort(0)
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 self.__proxyModel = QSortFilterProxyModel(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
42 self.__proxyModel.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
2211
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.__proxyModel.setDynamicSortFilter(True)
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.__proxyModel.setSourceModel(self.__model)
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.wordList.setModel(self.__proxyModel)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
46
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
47 self.searchEdit.textChanged.connect(self.__proxyModel.setFilterFixedString)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
48
3345
071afe8be2a1 Changed signal/slot usage to not use constructs like 'triggered[()].connect(...)' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
49 self.removeButton.clicked.connect(self.wordList.removeSelected)
071afe8be2a1 Changed signal/slot usage to not use constructs like 'triggered[()].connect(...)' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
50 self.removeAllButton.clicked.connect(self.wordList.removeAll)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
51
2211
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 @pyqtSlot()
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 def on_addButton_clicked(self):
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 Private slot to handle adding an entry.
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 """
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 self.__model.insertRow(self.__model.rowCount())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
58 self.wordList.edit(self.__proxyModel.index(self.__model.rowCount() - 1, 0))
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
59
2211
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 def getData(self):
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 """
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 Public method to get the data.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
63
2211
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 @return data of the dialog (string)
86bdcfac4a4a Added a dialog to edit the various spell checking dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
66 return (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
67 os.linesep.join(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
68 [line.strip() for line in self.__model.stringList() if line.strip()]
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
69 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
70 + os.linesep
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
71 )

eric ide

mercurial