|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2008 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Spelling Properties dialog. |
|
8 """ |
|
9 |
|
10 import os |
|
11 |
|
12 from PyQt4.QtCore import * |
|
13 from PyQt4.QtGui import * |
|
14 |
|
15 from E4Gui.E4Completers import E4FileCompleter |
|
16 |
|
17 from QScintilla.SpellChecker import SpellChecker |
|
18 |
|
19 from Ui_SpellingPropertiesDialog import Ui_SpellingPropertiesDialog |
|
20 |
|
21 import Utilities |
|
22 import Preferences |
|
23 |
|
24 class SpellingPropertiesDialog(QDialog, Ui_SpellingPropertiesDialog): |
|
25 """ |
|
26 Class implementing the Spelling Properties dialog. |
|
27 """ |
|
28 def __init__(self, project, new, parent): |
|
29 """ |
|
30 Constructor |
|
31 |
|
32 @param project reference to the project object |
|
33 @param new flag indicating the generation of a new project |
|
34 @param parent parent widget of this dialog (QWidget) |
|
35 """ |
|
36 QDialog.__init__(self, parent) |
|
37 self.setupUi(self) |
|
38 |
|
39 self.project = project |
|
40 self.parent = parent |
|
41 |
|
42 self.pwlCompleter = E4FileCompleter(self.pwlEdit) |
|
43 self.pelCompleter = E4FileCompleter(self.pelEdit) |
|
44 |
|
45 self.spellingComboBox.addItem(self.trUtf8("<default>")) |
|
46 self.spellingComboBox.addItems(sorted(SpellChecker.getAvailableLanguages())) |
|
47 |
|
48 if not new: |
|
49 self.initDialog() |
|
50 |
|
51 def initDialog(self): |
|
52 """ |
|
53 Public method to initialize the dialogs data. |
|
54 """ |
|
55 index = self.spellingComboBox.findText(self.project.pdata["SPELLLANGUAGE"][0]) |
|
56 if index == -1: |
|
57 index = 0 |
|
58 self.spellingComboBox.setCurrentIndex(index) |
|
59 if self.project.pdata["SPELLWORDS"][0]: |
|
60 self.pwlEdit.setText( |
|
61 os.path.join(self.project.ppath, self.project.pdata["SPELLWORDS"][0])) |
|
62 if self.project.pdata["SPELLEXCLUDES"][0]: |
|
63 self.pelEdit.setText( |
|
64 os.path.join(self.project.ppath, self.project.pdata["SPELLEXCLUDES"][0])) |
|
65 |
|
66 @pyqtSlot() |
|
67 def on_pwlButton_clicked(self): |
|
68 """ |
|
69 Private slot to select the project word list file. |
|
70 """ |
|
71 pwl = self.pwlEdit.text() |
|
72 if not pwl: |
|
73 pwl = self.project.ppath |
|
74 file = QFileDialog.getOpenFileName(\ |
|
75 self, |
|
76 self.trUtf8("Select project word list"), |
|
77 pwl, |
|
78 self.trUtf8("Dictionary File (*.dic);;All Files (*)")) |
|
79 |
|
80 if file: |
|
81 self.pwlEdit.setText(Utilities.toNativeSeparators(file)) |
|
82 |
|
83 @pyqtSlot() |
|
84 def on_pelButton_clicked(self): |
|
85 """ |
|
86 Private slot to select the project exclude list file. |
|
87 """ |
|
88 pel = self.pelEdit.text() |
|
89 if not pel: |
|
90 pel = self.project.ppath |
|
91 file = QFileDialog.getOpenFileName(\ |
|
92 self, |
|
93 self.trUtf8("Select project exclude list"), |
|
94 pel, |
|
95 self.trUtf8("Dictionary File (*.dic);;All Files (*)")) |
|
96 |
|
97 if file: |
|
98 self.pelEdit.setText(Utilities.toNativeSeparators(file)) |
|
99 |
|
100 def storeData(self): |
|
101 """ |
|
102 Public method to store the entered/modified data. |
|
103 """ |
|
104 if self.spellingComboBox.currentIndex() == 0: |
|
105 self.project.pdata["SPELLLANGUAGE"] = \ |
|
106 [Preferences.getEditor("SpellCheckingDefaultLanguage")] |
|
107 else: |
|
108 self.project.pdata["SPELLLANGUAGE"] = \ |
|
109 [self.spellingComboBox.currentText()] |
|
110 self.project.pdata["SPELLWORDS"] = \ |
|
111 [self.pwlEdit.text().replace(self.project.ppath + os.sep, "")] |
|
112 self.project.pdata["SPELLEXCLUDES"] = \ |
|
113 [self.pelEdit.text().replace(self.project.ppath + os.sep, "")] |