src/eric7/Preferences/ConfigurationPages/MicroPythonPage.py

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

eric ide

mercurial