|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2019 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the MicroPython configuration page. |
|
8 """ |
|
9 |
|
10 from EricWidgets.EricPathPicker import EricPathPickerModes |
|
11 |
|
12 from .ConfigurationPageBase import ConfigurationPageBase |
|
13 from .Ui_MicroPythonPage import Ui_MicroPythonPage |
|
14 |
|
15 import Preferences |
|
16 import Utilities |
|
17 |
|
18 from MicroPython.MicroPythonWidget import AnsiColorSchemes |
|
19 |
|
20 |
|
21 class MicroPythonPage(ConfigurationPageBase, Ui_MicroPythonPage): |
|
22 """ |
|
23 Class implementing the MicroPython configuration page. |
|
24 """ |
|
25 def __init__(self, parent=None): |
|
26 """ |
|
27 Constructor |
|
28 |
|
29 @param parent reference to the parent widget |
|
30 @type QWidget |
|
31 """ |
|
32 super().__init__() |
|
33 self.setupUi(self) |
|
34 self.setObjectName("MicroPythonPage") |
|
35 |
|
36 self.workspacePicker.setMode(EricPathPickerModes.DIRECTORY_MODE) |
|
37 |
|
38 self.colorSchemeComboBox.addItems(sorted(AnsiColorSchemes.keys())) |
|
39 |
|
40 # populate the chart theme combobox |
|
41 try: |
|
42 from PyQt6.QtCharts import QChart |
|
43 |
|
44 self.chartThemeComboBox.addItem( |
|
45 self.tr("Automatic"), -1) |
|
46 self.chartThemeComboBox.addItem( |
|
47 self.tr("Light"), |
|
48 QChart.ChartTheme.ChartThemeLight) |
|
49 self.chartThemeComboBox.addItem( |
|
50 self.tr("Dark"), |
|
51 QChart.ChartTheme.ChartThemeDark) |
|
52 self.chartThemeComboBox.addItem( |
|
53 self.tr("Blue Cerulean"), |
|
54 QChart.ChartTheme.ChartThemeBlueCerulean) |
|
55 self.chartThemeComboBox.addItem( |
|
56 self.tr("Brown Sand"), |
|
57 QChart.ChartTheme.ChartThemeBrownSand) |
|
58 self.chartThemeComboBox.addItem( |
|
59 self.tr("Blue NCS"), |
|
60 QChart.ChartTheme.ChartThemeBlueNcs) |
|
61 self.chartThemeComboBox.addItem( |
|
62 self.tr("High Contrast"), |
|
63 QChart.ChartTheme.ChartThemeHighContrast) |
|
64 self.chartThemeComboBox.addItem( |
|
65 self.tr("Blue Icy"), |
|
66 QChart.ChartTheme.ChartThemeBlueIcy) |
|
67 self.chartThemeComboBox.addItem( |
|
68 self.tr("Qt"), |
|
69 QChart.ChartTheme.ChartThemeQt) |
|
70 except ImportError: |
|
71 self.chartThemeComboBox.setEnabled(False) |
|
72 |
|
73 self.mpyCrossPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) |
|
74 self.mpyCrossPicker.setFilters(self.tr("All Files (*)")) |
|
75 |
|
76 self.dfuUtilPathPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) |
|
77 self.dfuUtilPathPicker.setFilters(self.tr("All Files (*)")) |
|
78 |
|
79 # set initial values |
|
80 # workspace |
|
81 self.workspacePicker.setText( |
|
82 Utilities.toNativeSeparators( |
|
83 Preferences.getMicroPython("MpyWorkspace") or |
|
84 Utilities.getHomeDir())) |
|
85 |
|
86 # serial link parameters |
|
87 self.timeoutSpinBox.setValue( |
|
88 Preferences.getMicroPython("SerialTimeout") // 1000) |
|
89 # converted to seconds |
|
90 self.syncTimeCheckBox.setChecked( |
|
91 Preferences.getMicroPython("SyncTimeAfterConnect")) |
|
92 |
|
93 # REPL Pane |
|
94 self.colorSchemeComboBox.setCurrentIndex( |
|
95 self.colorSchemeComboBox.findText( |
|
96 Preferences.getMicroPython("ColorScheme"))) |
|
97 self.replWrapCheckBox.setChecked( |
|
98 Preferences.getMicroPython("ReplLineWrap")) |
|
99 |
|
100 # Chart Pane |
|
101 index = self.chartThemeComboBox.findData( |
|
102 Preferences.getMicroPython("ChartColorTheme")) |
|
103 if index < 0: |
|
104 index = 0 |
|
105 self.chartThemeComboBox.setCurrentIndex(index) |
|
106 |
|
107 # MPY Cross Compiler |
|
108 self.mpyCrossPicker.setText( |
|
109 Preferences.getMicroPython("MpyCrossCompiler")) |
|
110 |
|
111 # PyBoard specifics |
|
112 self.dfuUtilPathPicker.setText( |
|
113 Preferences.getMicroPython("DfuUtilPath")) |
|
114 |
|
115 # MicroPython URLs |
|
116 self.micropythonFirmwareUrlLineEdit.setText( |
|
117 Preferences.getMicroPython("MicroPythonFirmwareUrl")) |
|
118 self.micropythonDocuUrlLineEdit.setText( |
|
119 Preferences.getMicroPython("MicroPythonDocuUrl")) |
|
120 |
|
121 # CircuitPython URLs |
|
122 self.circuitpythonFirmwareUrlLineEdit.setText( |
|
123 Preferences.getMicroPython("CircuitPythonFirmwareUrl")) |
|
124 self.circuitpythonLibrariesUrlLineEdit.setText( |
|
125 Preferences.getMicroPython("CircuitPythonLibrariesUrl")) |
|
126 self.circuitpythonDocuUrlLineEdit.setText( |
|
127 Preferences.getMicroPython("CircuitPythonDocuUrl")) |
|
128 |
|
129 # BBC micro:bit URLs |
|
130 self.microbitFirmwareUrlLineEdit.setText( |
|
131 Preferences.getMicroPython("MicrobitFirmwareUrl")) |
|
132 self.microbitV1MicroPythonUrlLineEdit.setText( |
|
133 Preferences.getMicroPython("MicrobitMicroPythonUrl")) |
|
134 self.microbitV2MicroPythonUrlLineEdit.setText( |
|
135 Preferences.getMicroPython("MicrobitV2MicroPythonUrl")) |
|
136 self.microbitDocuUrlLineEdit.setText( |
|
137 Preferences.getMicroPython("MicrobitDocuUrl")) |
|
138 |
|
139 # Calliope mini URLs |
|
140 self.calliopeFirmwareUrlLineEdit.setText( |
|
141 Preferences.getMicroPython("CalliopeDAPLinkUrl")) |
|
142 self.calliopeMicroPythonUrlLineEdit.setText( |
|
143 Preferences.getMicroPython("CalliopeMicroPythonUrl")) |
|
144 self.calliopeDocuUrlLineEdit.setText( |
|
145 Preferences.getMicroPython("CalliopeDocuUrl")) |
|
146 |
|
147 def save(self): |
|
148 """ |
|
149 Public slot to save the MicroPython configuration. |
|
150 """ |
|
151 # workspace |
|
152 Preferences.setMicroPython( |
|
153 "MpyWorkspace", |
|
154 self.workspacePicker.text()) |
|
155 |
|
156 # serial link parameters |
|
157 Preferences.setMicroPython( |
|
158 "SerialTimeout", |
|
159 self.timeoutSpinBox.value() * 1000) |
|
160 # converted to milliseconds |
|
161 Preferences.setMicroPython( |
|
162 "SyncTimeAfterConnect", |
|
163 self.syncTimeCheckBox.isChecked()) |
|
164 |
|
165 # REPL Pane |
|
166 Preferences.setMicroPython( |
|
167 "ColorScheme", |
|
168 self.colorSchemeComboBox.currentText()) |
|
169 Preferences.setMicroPython( |
|
170 "ReplLineWrap", |
|
171 self.replWrapCheckBox.isChecked()) |
|
172 |
|
173 # Chart Pane |
|
174 Preferences.setMicroPython( |
|
175 "ChartColorTheme", |
|
176 self.chartThemeComboBox.currentData()) |
|
177 |
|
178 # MPY Cross Compiler |
|
179 Preferences.setMicroPython( |
|
180 "MpyCrossCompiler", |
|
181 self.mpyCrossPicker.text()) |
|
182 |
|
183 # PyBoard specifics |
|
184 Preferences.setMicroPython( |
|
185 "DfuUtilPath", |
|
186 self.dfuUtilPathPicker.text()) |
|
187 |
|
188 # MicroPython URLs |
|
189 Preferences.setMicroPython( |
|
190 "MicroPythonFirmwareUrl", |
|
191 self.micropythonFirmwareUrlLineEdit.text()) |
|
192 Preferences.setMicroPython( |
|
193 "MicroPythonDocuUrl", |
|
194 self.micropythonDocuUrlLineEdit.text()) |
|
195 |
|
196 # CircuitPython URLs |
|
197 Preferences.setMicroPython( |
|
198 "CircuitPythonFirmwareUrl", |
|
199 self.circuitpythonFirmwareUrlLineEdit.text()) |
|
200 Preferences.setMicroPython( |
|
201 "CircuitPythonLibrariesUrl", |
|
202 self.circuitpythonLibrariesUrlLineEdit.text()) |
|
203 Preferences.setMicroPython( |
|
204 "CircuitPythonDocuUrl", |
|
205 self.circuitpythonDocuUrlLineEdit.text()) |
|
206 |
|
207 # BBC micro:bit URLs |
|
208 Preferences.setMicroPython( |
|
209 "MicrobitFirmwareUrl", |
|
210 self.microbitFirmwareUrlLineEdit.text()) |
|
211 Preferences.setMicroPython( |
|
212 "MicrobitMicroPythonUrl", |
|
213 self.microbitV1MicroPythonUrlLineEdit.text()) |
|
214 Preferences.setMicroPython( |
|
215 "MicrobitV2MicroPythonUrl", |
|
216 self.microbitV2MicroPythonUrlLineEdit.text()) |
|
217 Preferences.setMicroPython( |
|
218 "MicrobitDocuUrl", |
|
219 self.microbitDocuUrlLineEdit.text()) |
|
220 |
|
221 # Calliope mini URLs |
|
222 Preferences.setMicroPython( |
|
223 "CalliopeDAPLinkUrl", |
|
224 self.calliopeFirmwareUrlLineEdit.text()) |
|
225 Preferences.setMicroPython( |
|
226 "CalliopeMicroPythonUrl", |
|
227 self.calliopeMicroPythonUrlLineEdit.text()) |
|
228 Preferences.setMicroPython( |
|
229 "CalliopeDocuUrl", |
|
230 self.calliopeDocuUrlLineEdit.text()) |
|
231 |
|
232 |
|
233 def create(dlg): |
|
234 """ |
|
235 Module function to create the configuration page. |
|
236 |
|
237 @param dlg reference to the configuration dialog |
|
238 @return reference to the instantiated page (ConfigurationPageBase) |
|
239 """ |
|
240 return MicroPythonPage() |