|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2006 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Editor General configuration page. |
|
8 """ |
|
9 |
|
10 from PyQt4.Qsci import QsciScintilla |
|
11 |
|
12 import QScintilla.Lexers |
|
13 |
|
14 from ConfigurationPageBase import ConfigurationPageBase |
|
15 from Ui_EditorFilePage import Ui_EditorFilePage |
|
16 |
|
17 from Utilities import supportedCodecs |
|
18 import Preferences |
|
19 |
|
20 class EditorFilePage(ConfigurationPageBase, Ui_EditorFilePage): |
|
21 """ |
|
22 Class implementing the Editor File configuration page. |
|
23 """ |
|
24 def __init__(self): |
|
25 """ |
|
26 Constructor |
|
27 """ |
|
28 ConfigurationPageBase.__init__(self) |
|
29 self.setupUi(self) |
|
30 self.setObjectName("EditorFilePage") |
|
31 |
|
32 self.openFilesFilterComboBox.addItems(\ |
|
33 QScintilla.Lexers.getOpenFileFiltersList(True)) |
|
34 self.saveFilesFilterComboBox.addItems(\ |
|
35 QScintilla.Lexers.getSaveFileFiltersList(True)) |
|
36 |
|
37 self.defaultEncodingComboBox.addItems(sorted(supportedCodecs)) |
|
38 |
|
39 # set initial values |
|
40 self.autosaveSlider.setValue(\ |
|
41 Preferences.getEditor("AutosaveInterval")) |
|
42 self.createBackupFileCheckBox.setChecked(\ |
|
43 Preferences.getEditor("CreateBackupFile")) |
|
44 self.automaticSyntaxCheckCheckBox.setChecked(\ |
|
45 Preferences.getEditor("AutoCheckSyntax")) |
|
46 self.defaultEncodingComboBox.setCurrentIndex(\ |
|
47 self.defaultEncodingComboBox.findText(\ |
|
48 Preferences.getEditor("DefaultEncoding"))) |
|
49 self.advEncodingCheckBox.setChecked(\ |
|
50 Preferences.getEditor("AdvancedEncodingDetection")) |
|
51 self.warnFilesizeSpinBox.setValue(\ |
|
52 Preferences.getEditor("WarnFilesize")) |
|
53 self.clearBreakpointsCheckBox.setChecked(\ |
|
54 Preferences.getEditor("ClearBreaksOnClose")) |
|
55 self.automaticReopenCheckBox.setChecked(\ |
|
56 Preferences.getEditor("AutoReopen")) |
|
57 self.stripWhitespaceCheckBox.setChecked(\ |
|
58 Preferences.getEditor("StripTrailingWhitespace")) |
|
59 self.openFilesFilterComboBox.setCurrentIndex(\ |
|
60 self.openFilesFilterComboBox.findText(\ |
|
61 Preferences.getEditor("DefaultOpenFilter"))) |
|
62 self.saveFilesFilterComboBox.setCurrentIndex(\ |
|
63 self.saveFilesFilterComboBox.findText(\ |
|
64 Preferences.getEditor("DefaultSaveFilter"))) |
|
65 self.automaticEolConversionCheckBox.setChecked(\ |
|
66 Preferences.getEditor("AutomaticEOLConversion")) |
|
67 |
|
68 eolMode = Preferences.getEditor("EOLMode") |
|
69 if eolMode == QsciScintilla.EolWindows: |
|
70 self.crlfRadioButton.setChecked(True) |
|
71 elif eolMode == QsciScintilla.EolMac: |
|
72 self.crRadioButton.setChecked(True) |
|
73 elif eolMode == QsciScintilla.EolUnix: |
|
74 self.lfRadioButton.setChecked(True) |
|
75 |
|
76 def save(self): |
|
77 """ |
|
78 Public slot to save the Editor General configuration. |
|
79 """ |
|
80 Preferences.setEditor("AutosaveInterval", |
|
81 self.autosaveSlider.value()) |
|
82 Preferences.setEditor("CreateBackupFile", |
|
83 int(self.createBackupFileCheckBox.isChecked())) |
|
84 Preferences.setEditor("AutoCheckSyntax", |
|
85 int(self.automaticSyntaxCheckCheckBox.isChecked())) |
|
86 enc = unicode(self.defaultEncodingComboBox.currentText()) |
|
87 if not enc: |
|
88 enc = "utf-8" |
|
89 Preferences.setEditor("DefaultEncoding", enc) |
|
90 Preferences.setEditor("AdvancedEncodingDetection", |
|
91 int(self.advEncodingCheckBox.isChecked())) |
|
92 Preferences.setEditor("WarnFilesize", |
|
93 self.warnFilesizeSpinBox.value()) |
|
94 Preferences.setEditor("ClearBreaksOnClose", |
|
95 int(self.clearBreakpointsCheckBox.isChecked())) |
|
96 Preferences.setEditor("AutoReopen", |
|
97 int(self.automaticReopenCheckBox.isChecked())) |
|
98 Preferences.setEditor("StripTrailingWhitespace", |
|
99 int(self.stripWhitespaceCheckBox.isChecked())) |
|
100 Preferences.setEditor("DefaultOpenFilter", |
|
101 self.openFilesFilterComboBox.currentText()) |
|
102 Preferences.setEditor("DefaultSaveFilter", |
|
103 self.saveFilesFilterComboBox.currentText()) |
|
104 Preferences.setEditor("AutomaticEOLConversion", |
|
105 int(self.automaticEolConversionCheckBox.isChecked())) |
|
106 |
|
107 if self.crlfRadioButton.isChecked(): |
|
108 Preferences.setEditor("EOLMode", QsciScintilla.EolWindows) |
|
109 elif self.crRadioButton.isChecked(): |
|
110 Preferences.setEditor("EOLMode", QsciScintilla.EolMac) |
|
111 elif self.lfRadioButton.isChecked(): |
|
112 Preferences.setEditor("EOLMode", QsciScintilla.EolUnix) |
|
113 |
|
114 def create(dlg): |
|
115 """ |
|
116 Module function to create the configuration page. |
|
117 |
|
118 @param dlg reference to the configuration dialog |
|
119 """ |
|
120 page = EditorFilePage() |
|
121 return page |