10 |
10 |
11 import os |
11 import os |
12 import shutil |
12 import shutil |
13 |
13 |
14 from PyQt5.QtCore import pyqtSlot, QStandardPaths |
14 from PyQt5.QtCore import pyqtSlot, QStandardPaths |
15 from PyQt5.QtWidgets import QInputDialog, QLineEdit, QDialog |
15 from PyQt5.QtWidgets import QInputDialog, QLineEdit |
16 |
16 |
17 from .MicroPythonDevices import MicroPythonDevice |
17 from .MicroPythonDevices import MicroPythonDevice |
18 from .MicroPythonWidget import HAS_QTCHART |
18 from .MicroPythonWidget import HAS_QTCHART |
19 |
19 |
20 from E5Gui import E5MessageBox, E5FileDialog |
20 from E5Gui import E5MessageBox, E5FileDialog |
214 deviceDirectory = Utilities.findVolume("MAINTENANCE") |
214 deviceDirectory = Utilities.findVolume("MAINTENANCE") |
215 else: |
215 else: |
216 deviceDirectory = Utilities.findVolume("MICROBIT") |
216 deviceDirectory = Utilities.findVolume("MICROBIT") |
217 else: |
217 else: |
218 # Calliope mini |
218 # Calliope mini |
219 deviceDirectory = Utilities.findVolume("MINI") |
219 if firmware: |
|
220 deviceDirectory = Utilities.findVolume("MAINTENANCE") |
|
221 else: |
|
222 deviceDirectory = Utilities.findVolume("MINI") |
220 if not deviceDirectory: |
223 if not deviceDirectory: |
221 if self.__deviceType == "bbc_microbit": |
224 if self.__deviceType == "bbc_microbit": |
222 # BBC micro:bit is not ready or not mounted |
225 # BBC micro:bit is not ready or not mounted |
223 if firmware: |
226 if firmware: |
224 E5MessageBox.critical( |
227 E5MessageBox.critical( |
251 '</p>' |
254 '</p>' |
252 ) |
255 ) |
253 ) |
256 ) |
254 else: |
257 else: |
255 # Calliope mini is not ready or not mounted |
258 # Calliope mini is not ready or not mounted |
256 E5MessageBox.warning( |
259 if firmware: |
257 self.microPython, |
260 E5MessageBox.critical( |
258 self.tr("Flash MicroPython/Firmware"), |
261 self.microPython, |
259 self.tr("Could not find an attached {0}.\n\n" |
262 self.tr("Flash MicroPython/Firmware"), |
260 "Please make sure the device is plugged " |
263 self.tr( |
261 "into this computer.").format(self.deviceName())) |
264 '<p>The "Calliope mini" is not ready for flashing' |
|
265 ' the DAPLink firmware. Follow these' |
|
266 ' instructions. </p>' |
|
267 '<ul>' |
|
268 '<li>unplug USB cable and any batteries</li>' |
|
269 '<li>keep RESET button pressed an plug USB cable' |
|
270 ' back in</li>' |
|
271 '<li>a drive called MAINTENANCE should be' |
|
272 ' available</li>' |
|
273 '</ul>' |
|
274 ) |
|
275 ) |
|
276 else: |
|
277 E5MessageBox.critical( |
|
278 self.microPython, |
|
279 self.tr("Flash MicroPython/Firmware"), |
|
280 self.tr( |
|
281 '<p>The "Calliope mini" is not ready for flashing' |
|
282 ' the MicroPython firmware. Please make sure,' |
|
283 ' that a drive called MINI is available.' |
|
284 '</p>' |
|
285 ) |
|
286 ) |
262 else: |
287 else: |
263 downloadsPath = QStandardPaths.standardLocations( |
288 downloadsPath = QStandardPaths.standardLocations( |
264 QStandardPaths.DownloadLocation)[0] |
289 QStandardPaths.DownloadLocation)[0] |
265 firmware = E5FileDialog.getOpenFileName( |
290 firmware = E5FileDialog.getOpenFileName( |
266 self.microPython, |
291 self.microPython, |
267 self.tr("Flash MicroPython/Firmware"), |
292 self.tr("Flash MicroPython/Firmware"), |
268 downloadsPath, |
293 downloadsPath, |
269 self.tr("MicroPython/Firmware Files (*.hex);;All Files (*)")) |
294 self.tr("MicroPython/Firmware Files (*.hex *.bin);;" |
|
295 "All Files (*)")) |
270 if firmware and os.path.exists(firmware): |
296 if firmware and os.path.exists(firmware): |
271 shutil.copy2(firmware, deviceDirectory) |
297 shutil.copy2(firmware, deviceDirectory) |
272 |
298 |
273 @pyqtSlot() |
299 @pyqtSlot() |
274 def __saveMain(self): |
300 def __saveMain(self): |
375 return Preferences.getMicroPython("MicrobitDocuUrl") |
401 return Preferences.getMicroPython("MicrobitDocuUrl") |
376 else: |
402 else: |
377 # Calliope mini |
403 # Calliope mini |
378 return Preferences.getMicroPython("CalliopeDocuUrl") |
404 return Preferences.getMicroPython("CalliopeDocuUrl") |
379 |
405 |
380 def getFirmwareUrl(self, fwtype="mpy"): |
406 def getDownloadMenuEntries(self): |
381 """ |
407 """ |
382 Public method to get the device firmware download URL. |
408 Public method to retrieve the entries for the downloads menu. |
383 |
409 |
384 @param fwtype type of firmware to download |
410 @return list of tuples with menu text and URL to be opened for each |
385 (valid values are "mpy" and "dap"; defaults to "mpy") |
411 entry |
386 @type str (optional) |
412 @rtype list of tuple of (str, str) |
387 @return firmware download URL of the device |
413 """ |
388 @rtype str |
414 if self.__deviceType == "bbc_microbit": |
389 """ |
415 return [ |
390 if self.__deviceType == "bbc_microbit": |
416 (self.tr("MicroPython Firmware"), |
391 # BBC micro:bit V1 |
417 Preferences.getMicroPython("MicrobitMicroPythonUrl")), |
392 if fwtype == "mpy": |
418 (self.tr("DAPLink Firmware"), |
393 return Preferences.getMicroPython("MicrobitMicroPythonUrl") |
419 Preferences.getMicroPython("MicrobitFirmwareUrl")) |
394 elif fwtype == "dap": |
420 ] |
395 return Preferences.getMicroPython("MicrobitFirmwareUrl") |
421 else: |
396 else: |
422 return [ |
397 return "" |
423 (self.tr("MicroPython Firmware"), |
398 else: |
424 Preferences.getMicroPython("CalliopeMicroPythonUrl")), |
399 # Calliope mini |
425 (self.tr("DAPLink Firmware"), |
400 return Preferences.getMicroPython("CalliopeFirmwareUrl") |
426 Preferences.getMicroPython("CalliopeDAPLinkUrl")) |
401 |
427 ] |
402 def downloadFirmware(self): |
|
403 """ |
|
404 Public method to download the device firmware. |
|
405 """ |
|
406 fwtype = "" |
|
407 if self.__deviceType == "bbc_microbit": |
|
408 # BBC micro:bit |
|
409 from E5Gui.E5ComboSelectionDialog import E5ComboSelectionDialog |
|
410 dlg = E5ComboSelectionDialog( |
|
411 [(self.tr("MicroPython"), "mpy"), (self.tr("DAPLink"), "dap")], |
|
412 title=self.tr("Firmware Type"), |
|
413 message=self.tr("Select the firmware type to download from" |
|
414 " the list below:") |
|
415 ) |
|
416 if dlg.exec() == QDialog.Accepted: |
|
417 fwtype = dlg.getSelection()[1] |
|
418 else: |
|
419 # user cancelled |
|
420 return |
|
421 |
|
422 url = self.getFirmwareUrl(fwtype) |
|
423 if url: |
|
424 e5App().getObject("UserInterface").launchHelpViewer(url) |
|