|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2008 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Editor Spellchecking configuration page. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSlot |
|
11 from PyQt4.QtGui import QPixmap, QIcon, QFileDialog |
|
12 |
|
13 from E4Gui.E4Completers import E4FileCompleter |
|
14 |
|
15 from ConfigurationPageBase import ConfigurationPageBase |
|
16 from Ui_EditorSpellCheckingPage import Ui_EditorSpellCheckingPage |
|
17 |
|
18 import Preferences |
|
19 import Utilities |
|
20 |
|
21 from QScintilla.SpellChecker import SpellChecker |
|
22 |
|
23 class EditorSpellCheckingPage(ConfigurationPageBase, Ui_EditorSpellCheckingPage): |
|
24 """ |
|
25 Class implementing the Editor Spellchecking configuration page. |
|
26 """ |
|
27 def __init__(self): |
|
28 """ |
|
29 Constructor |
|
30 """ |
|
31 ConfigurationPageBase.__init__(self) |
|
32 self.setupUi(self) |
|
33 self.setObjectName("EditorSpellCheckingPage") |
|
34 |
|
35 self.editorColours = {} |
|
36 |
|
37 languages = sorted(SpellChecker.getAvailableLanguages()) |
|
38 self.defaultLanguageCombo.addItems(languages) |
|
39 if languages: |
|
40 self.errorLabel.hide() |
|
41 else: |
|
42 self.spellingFrame.setEnabled(False) |
|
43 |
|
44 self.pwlFileCompleter = E4FileCompleter(self.pwlEdit, showHidden = True) |
|
45 self.pelFileCompleter = E4FileCompleter(self.pelEdit, showHidden = True) |
|
46 |
|
47 # set initial values |
|
48 self.checkingEnabledCheckBox.setChecked( |
|
49 Preferences.getEditor("SpellCheckingEnabled")) |
|
50 |
|
51 self.defaultLanguageCombo.setCurrentIndex( |
|
52 self.defaultLanguageCombo.findText( |
|
53 Preferences.getEditor("SpellCheckingDefaultLanguage"))) |
|
54 |
|
55 self.stringsOnlyCheckBox.setChecked( |
|
56 Preferences.getEditor("SpellCheckStringsOnly")) |
|
57 self.minimumWordSizeSlider.setValue( |
|
58 Preferences.getEditor("SpellCheckingMinWordSize")) |
|
59 |
|
60 self.editorColours["SpellingMarkers"] = \ |
|
61 self.initColour("SpellingMarkers", self.spellingMarkerButton, |
|
62 Preferences.getEditorColour) |
|
63 |
|
64 self.pwlEdit.setText(Preferences.getEditor("SpellCheckingPersonalWordList")) |
|
65 self.pelEdit.setText(Preferences.getEditor("SpellCheckingPersonalExcludeList")) |
|
66 |
|
67 if self.spellingFrame.isEnabled(): |
|
68 self.enabledCheckBox.setChecked(\ |
|
69 Preferences.getEditor("AutoSpellCheckingEnabled")) |
|
70 else: |
|
71 self.enabledCheckBox.setChecked(False) # not available |
|
72 self.chunkSizeSpinBox.setValue(Preferences.getEditor("AutoSpellCheckChunkSize")) |
|
73 |
|
74 def save(self): |
|
75 """ |
|
76 Public slot to save the Editor Search configuration. |
|
77 """ |
|
78 Preferences.setEditor("SpellCheckingEnabled", |
|
79 int(self.checkingEnabledCheckBox.isChecked())) |
|
80 |
|
81 Preferences.setEditor("SpellCheckingDefaultLanguage", |
|
82 self.defaultLanguageCombo.currentText()) |
|
83 |
|
84 Preferences.setEditor("SpellCheckStringsOnly", |
|
85 int(self.stringsOnlyCheckBox.isChecked())) |
|
86 Preferences.setEditor("SpellCheckingMinWordSize", |
|
87 self.minimumWordSizeSlider.value()) |
|
88 |
|
89 for key in self.editorColours.keys(): |
|
90 Preferences.setEditorColour(key, self.editorColours[key]) |
|
91 |
|
92 Preferences.setEditor("SpellCheckingPersonalWordList", self.pwlEdit.text()) |
|
93 Preferences.setEditor("SpellCheckingPersonalExcludeList", self.pelEdit.text()) |
|
94 |
|
95 Preferences.setEditor("AutoSpellCheckingEnabled", |
|
96 int(self.enabledCheckBox.isChecked())) |
|
97 Preferences.setEditor("AutoSpellCheckChunkSize", self.chunkSizeSpinBox.value()) |
|
98 |
|
99 @pyqtSlot() |
|
100 def on_spellingMarkerButton_clicked(self): |
|
101 """ |
|
102 Private slot to set the colour of the spelling markers. |
|
103 """ |
|
104 self.editorColours["SpellingMarkers"] = \ |
|
105 self.selectColour(self.spellingMarkerButton, |
|
106 self.editorColours["SpellingMarkers"]) |
|
107 |
|
108 @pyqtSlot() |
|
109 def on_pwlButton_clicked(self): |
|
110 """ |
|
111 Private method to select the personal word list file. |
|
112 """ |
|
113 file = QFileDialog.getOpenFileName(\ |
|
114 self, |
|
115 self.trUtf8("Select personal word list"), |
|
116 self.pwlEdit.text(), |
|
117 self.trUtf8("Dictionary File (*.dic);;All Files (*)")) |
|
118 |
|
119 if file: |
|
120 self.pwlEdit.setText(Utilities.toNativeSeparators(file)) |
|
121 |
|
122 @pyqtSlot() |
|
123 def on_pelButton_clicked(self): |
|
124 """ |
|
125 Private method to select the personal exclude list file. |
|
126 """ |
|
127 file = QFileDialog.getOpenFileName(\ |
|
128 self, |
|
129 self.trUtf8("Select personal exclude list"), |
|
130 self.pelEdit.text(), |
|
131 self.trUtf8("Dictionary File (*.dic);;All Files (*)")) |
|
132 |
|
133 if file: |
|
134 self.pelEdit.setText(Utilities.toNativeSeparators(file)) |
|
135 |
|
136 def create(dlg): |
|
137 """ |
|
138 Module function to create the configuration page. |
|
139 |
|
140 @param dlg reference to the configuration dialog |
|
141 """ |
|
142 page = EditorSpellCheckingPage() |
|
143 return page |