|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2008 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Spelling Properties dialog. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtWidgets import QDialog |
|
11 |
|
12 from EricWidgets.EricPathPicker import EricPathPickerModes |
|
13 |
|
14 from .Ui_SpellingPropertiesDialog import Ui_SpellingPropertiesDialog |
|
15 |
|
16 import Preferences |
|
17 |
|
18 |
|
19 class SpellingPropertiesDialog(QDialog, Ui_SpellingPropertiesDialog): |
|
20 """ |
|
21 Class implementing the Spelling Properties dialog. |
|
22 """ |
|
23 def __init__(self, project, new, parent): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param project reference to the project object |
|
28 @param new flag indicating the generation of a new project |
|
29 @param parent parent widget of this dialog (QWidget) |
|
30 """ |
|
31 super().__init__(parent) |
|
32 self.setupUi(self) |
|
33 |
|
34 self.pwlPicker.setMode(EricPathPickerModes.SAVE_FILE_MODE) |
|
35 self.pwlPicker.setDefaultDirectory(project.ppath) |
|
36 self.pwlPicker.setFilters(self.tr( |
|
37 "Dictionary File (*.dic);;All Files (*)")) |
|
38 |
|
39 self.pelPicker.setMode(EricPathPickerModes.SAVE_FILE_MODE) |
|
40 self.pelPicker.setDefaultDirectory(project.ppath) |
|
41 self.pelPicker.setFilters(self.tr( |
|
42 "Dictionary File (*.dic);;All Files (*)")) |
|
43 |
|
44 self.project = project |
|
45 self.parent = parent |
|
46 |
|
47 from QScintilla.SpellChecker import SpellChecker |
|
48 self.spellingComboBox.addItem(self.tr("<default>")) |
|
49 self.spellingComboBox.addItems( |
|
50 sorted(SpellChecker.getAvailableLanguages())) |
|
51 |
|
52 if not new: |
|
53 self.initDialog() |
|
54 |
|
55 msh = self.minimumSizeHint() |
|
56 self.resize(max(self.width(), msh.width()), msh.height()) |
|
57 |
|
58 def initDialog(self): |
|
59 """ |
|
60 Public method to initialize the dialogs data. |
|
61 """ |
|
62 index = self.spellingComboBox.findText( |
|
63 self.project.pdata["SPELLLANGUAGE"]) |
|
64 if index == -1: |
|
65 index = 0 |
|
66 self.spellingComboBox.setCurrentIndex(index) |
|
67 if self.project.pdata["SPELLWORDS"]: |
|
68 self.pwlPicker.setText(self.project.pdata["SPELLWORDS"]) |
|
69 if self.project.pdata["SPELLEXCLUDES"]: |
|
70 self.pelPicker.setText(self.project.pdata["SPELLEXCLUDES"]) |
|
71 |
|
72 def storeData(self): |
|
73 """ |
|
74 Public method to store the entered/modified data. |
|
75 """ |
|
76 if self.spellingComboBox.currentIndex() == 0: |
|
77 self.project.pdata["SPELLLANGUAGE"] = ( |
|
78 Preferences.getEditor("SpellCheckingDefaultLanguage") |
|
79 ) |
|
80 else: |
|
81 self.project.pdata["SPELLLANGUAGE"] = ( |
|
82 self.spellingComboBox.currentText() |
|
83 ) |
|
84 self.project.pdata["SPELLWORDS"] = self.project.getRelativePath( |
|
85 self.pwlPicker.text()) |
|
86 self.project.pdata["SPELLEXCLUDES"] = self.project.getRelativePath( |
|
87 self.pelPicker.text()) |