7 Module implementing a dialog to flash any UF2 capable device. |
7 Module implementing a dialog to flash any UF2 capable device. |
8 """ |
8 """ |
9 |
9 |
10 import os |
10 import os |
11 import shutil |
11 import shutil |
|
12 import contextlib |
12 |
13 |
13 from PyQt5.QtCore import pyqtSlot, Qt, QCoreApplication, QThread, QEventLoop |
14 from PyQt5.QtCore import pyqtSlot, Qt, QCoreApplication, QThread, QEventLoop |
14 from PyQt5.QtWidgets import QDialog |
15 from PyQt5.QtWidgets import QDialog |
15 |
16 |
16 from E5Gui.E5PathPicker import E5PathPickerModes |
17 from E5Gui.E5PathPicker import E5PathPickerModes |
477 )) |
478 )) |
478 |
479 |
479 # second run for boards needing special treatment (e.g. RP2040) |
480 # second run for boards needing special treatment (e.g. RP2040) |
480 for board in SupportedUF2Boards: |
481 for board in SupportedUF2Boards: |
481 if not boardType or (board == boardType): |
482 if not boardType or (board == boardType): |
482 try: |
483 with contextlib.suppress(KeyError): |
483 # find mounted volume |
484 # find mounted volume |
484 volumes = SupportedUF2Boards[board]["volumes"][(0, 0)] |
485 volumes = SupportedUF2Boards[board]["volumes"][(0, 0)] |
485 foundVolumes = [] |
486 foundVolumes = [] |
486 for volume in volumes: |
487 for volume in volumes: |
487 foundVolumes += Utilities.findVolume(volume, findAll=True) |
488 foundVolumes += Utilities.findVolume(volume, findAll=True) |
490 board, |
491 board, |
491 QCoreApplication.translate( |
492 QCoreApplication.translate( |
492 "UF2FlashDialog", "'{0}' Board").format(board), |
493 "UF2FlashDialog", "'{0}' Board").format(board), |
493 (0, 0), # VID/PID of (0, 0) is special |
494 (0, 0), # VID/PID of (0, 0) is special |
494 )) |
495 )) |
495 except KeyError: |
|
496 # no special treatment required, carry on |
|
497 pass |
|
498 |
496 |
499 return foundDevices |
497 return foundDevices |
500 |
498 |
501 |
499 |
502 class UF2FlashDialog(QDialog, Ui_UF2FlashDialog): |
500 class UF2FlashDialog(QDialog, Ui_UF2FlashDialog): |