204 Private slot to flash a custom MicroPython firmware to the device. |
204 Private slot to flash a custom MicroPython firmware to the device. |
205 """ |
205 """ |
206 downloadsPath = QStandardPaths.standardLocations( |
206 downloadsPath = QStandardPaths.standardLocations( |
207 QStandardPaths.DownloadLocation)[0] |
207 QStandardPaths.DownloadLocation)[0] |
208 firmware = E5FileDialog.getOpenFileName( |
208 firmware = E5FileDialog.getOpenFileName( |
209 None, |
209 self.microPython, |
210 self.tr("Flash Custom MicroPython Firmware"), |
210 self.tr("Flash Custom MicroPython Firmware"), |
211 downloadsPath, |
211 downloadsPath, |
212 self.tr("MicroPython Firmware Files (*.hex);;All Files (*)")) |
212 self.tr("MicroPython Firmware Files (*.hex);;All Files (*)")) |
213 if firmware and os.path.exists(firmware): |
213 if firmware and os.path.exists(firmware): |
214 flashArgs = [ |
214 flashArgs = [ |
232 if not aw: |
232 if not aw: |
233 return |
233 return |
234 |
234 |
235 if not (aw.isPy3File() or aw.isPy2File()): |
235 if not (aw.isPy3File() or aw.isPy2File()): |
236 yes = E5MessageBox.yesNo( |
236 yes = E5MessageBox.yesNo( |
237 None, |
237 self.microPython, |
238 self.tr("Flash Script"), |
238 self.tr("Flash Script"), |
239 self.tr("""The current editor does not contain a Python""" |
239 self.tr("""The current editor does not contain a Python""" |
240 """ script. Flash it anyway?""")) |
240 """ script. Flash it anyway?""")) |
241 if not yes: |
241 if not yes: |
242 return |
242 return |
243 |
243 |
244 script = aw.text().strip() |
244 script = aw.text().strip() |
245 if not script: |
245 if not script: |
246 E5MessageBox.warning( |
246 E5MessageBox.warning( |
247 self, |
247 self.microPython, |
248 self.tr("Flash Script"), |
248 self.tr("Flash Script"), |
249 self.tr("""The script is empty. Aborting.""")) |
249 self.tr("""The script is empty. Aborting.""")) |
250 return |
250 return |
251 |
251 |
252 if aw.checkDirty(): |
252 if aw.checkDirty(): |
272 if not aw: |
272 if not aw: |
273 return |
273 return |
274 |
274 |
275 if not (aw.isPy3File() or aw.isPy2File()): |
275 if not (aw.isPy3File() or aw.isPy2File()): |
276 yes = E5MessageBox.yesNo( |
276 yes = E5MessageBox.yesNo( |
277 None, |
277 self.microPython, |
278 self.tr("Save Script as 'main.py'"), |
278 self.tr("Save Script as 'main.py'"), |
279 self.tr("""The current editor does not contain a Python""" |
279 self.tr("""The current editor does not contain a Python""" |
280 """ script. Write it anyway?""")) |
280 """ script. Write it anyway?""")) |
281 if not yes: |
281 if not yes: |
282 return |
282 return |
283 |
283 |
284 script = aw.text().strip() |
284 script = aw.text().strip() |
285 if not script: |
285 if not script: |
286 E5MessageBox.warning( |
286 E5MessageBox.warning( |
287 self, |
287 self.microPython, |
288 self.tr("Save Script as 'main.py'"), |
288 self.tr("Save Script as 'main.py'"), |
289 self.tr("""The script is empty. Aborting.""")) |
289 self.tr("""The script is empty. Aborting.""")) |
290 return |
290 return |
291 |
291 |
292 commands = [ |
292 commands = [ |
297 commands.append("f(" + repr(line + "\n") + ")") |
297 commands.append("f(" + repr(line + "\n") + ")") |
298 commands.append("fd.close()") |
298 commands.append("fd.close()") |
299 out, err = self.microPython.commandsInterface().execute(commands) |
299 out, err = self.microPython.commandsInterface().execute(commands) |
300 if err: |
300 if err: |
301 E5MessageBox.critical( |
301 E5MessageBox.critical( |
302 self, |
302 self.microPython, |
303 self.tr("Save Script as 'main.py'"), |
303 self.tr("Save Script as 'main.py'"), |
304 self.tr("""<p>The script could not be saved to the""" |
304 self.tr("""<p>The script could not be saved to the""" |
305 """ device.</p><p>Reason: {0}</p>""") |
305 """ device.</p><p>Reason: {0}</p>""") |
306 .format(err.decode("utf-8"))) |
306 .format(err.decode("utf-8"))) |
307 |
307 |