|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2007 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Editor Typing configuration page. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot |
|
13 |
|
14 from .ConfigurationPageBase import ConfigurationPageBase |
|
15 from .Ui_EditorTypingPage import Ui_EditorTypingPage |
|
16 |
|
17 import Preferences |
|
18 |
|
19 |
|
20 class EditorTypingPage(ConfigurationPageBase, Ui_EditorTypingPage): |
|
21 """ |
|
22 Class implementing the Editor Typing configuration page. |
|
23 """ |
|
24 def __init__(self): |
|
25 """ |
|
26 Constructor |
|
27 """ |
|
28 super(EditorTypingPage, self).__init__() |
|
29 self.setupUi(self) |
|
30 self.setObjectName("EditorTypingPage") |
|
31 |
|
32 # set initial values |
|
33 self.pageIds = {} |
|
34 self.pageIds[' '] = self.stackedWidget.indexOf(self.emptyPage) |
|
35 self.pageIds['Python'] = self.stackedWidget.indexOf(self.pythonPage) |
|
36 self.pageIds['Ruby'] = self.stackedWidget.indexOf(self.rubyPage) |
|
37 languages = sorted(list(self.pageIds.keys())) |
|
38 for language in languages: |
|
39 self.languageCombo.addItem(language, self.pageIds[language]) |
|
40 |
|
41 # Python |
|
42 self.pythonGroup.setChecked( |
|
43 Preferences.getEditorTyping("Python/EnabledTypingAids")) |
|
44 self.pythonInsertClosingBraceCheckBox.setChecked( |
|
45 Preferences.getEditorTyping("Python/InsertClosingBrace")) |
|
46 self.pythonSkipBraceCheckBox.setChecked( |
|
47 Preferences.getEditorTyping("Python/SkipBrace")) |
|
48 self.pythonIndentBraceCheckBox.setChecked( |
|
49 Preferences.getEditorTyping("Python/IndentBrace")) |
|
50 self.pythonInsertQuoteCheckBox.setChecked( |
|
51 Preferences.getEditorTyping("Python/InsertQuote")) |
|
52 self.pythonDedentElseCheckBox.setChecked( |
|
53 Preferences.getEditorTyping("Python/DedentElse")) |
|
54 self.pythonDedentExceptCheckBox.setChecked( |
|
55 Preferences.getEditorTyping("Python/DedentExcept")) |
|
56 self.pythonDedentExceptPy24CheckBox.setChecked( |
|
57 Preferences.getEditorTyping("Python/Py24StyleTry")) |
|
58 self.pythonInsertImportCheckBox.setChecked( |
|
59 Preferences.getEditorTyping("Python/InsertImport")) |
|
60 self.pythonInsertSelfCheckBox.setChecked( |
|
61 Preferences.getEditorTyping("Python/InsertSelf")) |
|
62 self.pythonInsertBlankCheckBox.setChecked( |
|
63 Preferences.getEditorTyping("Python/InsertBlank")) |
|
64 self.pythonColonDetectionCheckBox.setChecked( |
|
65 Preferences.getEditorTyping("Python/ColonDetection")) |
|
66 self.pythonDedentDefCheckBox.setChecked( |
|
67 Preferences.getEditorTyping("Python/DedentDef")) |
|
68 |
|
69 # Ruby |
|
70 self.rubyGroup.setChecked( |
|
71 Preferences.getEditorTyping("Ruby/EnabledTypingAids")) |
|
72 self.rubyInsertClosingBraceCheckBox.setChecked( |
|
73 Preferences.getEditorTyping("Ruby/InsertClosingBrace")) |
|
74 self.rubySkipBraceCheckBox.setChecked( |
|
75 Preferences.getEditorTyping("Ruby/SkipBrace")) |
|
76 self.rubyIndentBraceCheckBox.setChecked( |
|
77 Preferences.getEditorTyping("Ruby/IndentBrace")) |
|
78 self.rubyInsertQuoteCheckBox.setChecked( |
|
79 Preferences.getEditorTyping("Ruby/InsertQuote")) |
|
80 self.rubyInsertBlankCheckBox.setChecked( |
|
81 Preferences.getEditorTyping("Ruby/InsertBlank")) |
|
82 self.rubyInsertHereDocCheckBox.setChecked( |
|
83 Preferences.getEditorTyping("Ruby/InsertHereDoc")) |
|
84 self.rubyInsertInlineDocCheckBox.setChecked( |
|
85 Preferences.getEditorTyping("Ruby/InsertInlineDoc")) |
|
86 |
|
87 self.on_languageCombo_activated(' ') |
|
88 |
|
89 def save(self): |
|
90 """ |
|
91 Public slot to save the Editor Typing configuration. |
|
92 """ |
|
93 # Python |
|
94 Preferences.setEditorTyping( |
|
95 "Python/EnabledTypingAids", |
|
96 self.pythonGroup.isChecked()) |
|
97 Preferences.setEditorTyping( |
|
98 "Python/InsertClosingBrace", |
|
99 self.pythonInsertClosingBraceCheckBox.isChecked()) |
|
100 Preferences.setEditorTyping( |
|
101 "Python/SkipBrace", |
|
102 self.pythonSkipBraceCheckBox.isChecked()) |
|
103 Preferences.setEditorTyping( |
|
104 "Python/IndentBrace", |
|
105 self.pythonIndentBraceCheckBox.isChecked()) |
|
106 Preferences.setEditorTyping( |
|
107 "Python/InsertQuote", |
|
108 self.pythonInsertQuoteCheckBox.isChecked()) |
|
109 Preferences.setEditorTyping( |
|
110 "Python/DedentElse", |
|
111 self.pythonDedentElseCheckBox.isChecked()) |
|
112 Preferences.setEditorTyping( |
|
113 "Python/DedentExcept", |
|
114 self.pythonDedentExceptCheckBox.isChecked()) |
|
115 Preferences.setEditorTyping( |
|
116 "Python/Py24StyleTry", |
|
117 self.pythonDedentExceptPy24CheckBox.isChecked()) |
|
118 Preferences.setEditorTyping( |
|
119 "Python/InsertImport", |
|
120 self.pythonInsertImportCheckBox.isChecked()) |
|
121 Preferences.setEditorTyping( |
|
122 "Python/InsertSelf", |
|
123 self.pythonInsertSelfCheckBox.isChecked()) |
|
124 Preferences.setEditorTyping( |
|
125 "Python/InsertBlank", |
|
126 self.pythonInsertBlankCheckBox.isChecked()) |
|
127 Preferences.setEditorTyping( |
|
128 "Python/ColonDetection", |
|
129 self.pythonColonDetectionCheckBox.isChecked()) |
|
130 Preferences.setEditorTyping( |
|
131 "Python/DedentDef", |
|
132 self.pythonDedentDefCheckBox.isChecked()) |
|
133 |
|
134 # Ruby |
|
135 Preferences.setEditorTyping( |
|
136 "Ruby/EnabledTypingAids", |
|
137 self.rubyGroup.isChecked()) |
|
138 Preferences.setEditorTyping( |
|
139 "Ruby/InsertClosingBrace", |
|
140 self.rubyInsertClosingBraceCheckBox.isChecked()) |
|
141 Preferences.setEditorTyping( |
|
142 "Ruby/SkipBrace", |
|
143 self.rubySkipBraceCheckBox.isChecked()) |
|
144 Preferences.setEditorTyping( |
|
145 "Ruby/IndentBrace", |
|
146 self.rubyIndentBraceCheckBox.isChecked()) |
|
147 Preferences.setEditorTyping( |
|
148 "Ruby/InsertQuote", |
|
149 self.rubyInsertQuoteCheckBox.isChecked()) |
|
150 Preferences.setEditorTyping( |
|
151 "Ruby/InsertBlank", |
|
152 self.rubyInsertBlankCheckBox.isChecked()) |
|
153 Preferences.setEditorTyping( |
|
154 "Ruby/InsertHereDoc", |
|
155 self.rubyInsertHereDocCheckBox.isChecked()) |
|
156 Preferences.setEditorTyping( |
|
157 "Ruby/InsertInlineDoc", |
|
158 self.rubyInsertInlineDocCheckBox.isChecked()) |
|
159 |
|
160 @pyqtSlot(str) |
|
161 def on_languageCombo_activated(self, language): |
|
162 """ |
|
163 Private slot to select the page related to the selected language. |
|
164 |
|
165 @param language name of the selected language (string) |
|
166 """ |
|
167 try: |
|
168 index = self.pageIds[language] |
|
169 except KeyError: |
|
170 index = self.pageIds[' '] |
|
171 self.stackedWidget.setCurrentIndex(index) |
|
172 |
|
173 |
|
174 def create(dlg): |
|
175 """ |
|
176 Module function to create the configuration page. |
|
177 |
|
178 @param dlg reference to the configuration dialog |
|
179 @return reference to the instantiated page (ConfigurationPageBase) |
|
180 """ |
|
181 page = EditorTypingPage() |
|
182 return page |