src/eric7/MicroPython/UF2FlashDialog.py

branch
mpy_network
changeset 9815
6cbe3948044c
parent 9759
4543b7876047
child 9821
6b1b06d74532
equal deleted inserted replaced
9814:1445ca4be40d 9815:6cbe3948044c
11 import os 11 import os
12 import shutil 12 import shutil
13 13
14 from PyQt6.QtCore import QCoreApplication, QEventLoop, Qt, QThread, pyqtSlot 14 from PyQt6.QtCore import QCoreApplication, QEventLoop, Qt, QThread, pyqtSlot
15 from PyQt6.QtSerialPort import QSerialPortInfo 15 from PyQt6.QtSerialPort import QSerialPortInfo
16 from PyQt6.QtWidgets import QDialog 16 from PyQt6.QtWidgets import QDialog, QInputDialog
17 17
18 from eric7.EricGui import EricPixmapCache 18 from eric7.EricGui import EricPixmapCache
19 from eric7.EricWidgets.EricApplication import ericApp 19 from eric7.EricWidgets.EricApplication import ericApp
20 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes 20 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes
21 from eric7.SystemUtilities import FileSystemUtilities 21 from eric7.SystemUtilities import FileSystemUtilities
718 ) 718 )
719 719
720 self.bootPicker.setMode(EricPathPickerModes.DIRECTORY_SHOW_FILES_MODE) 720 self.bootPicker.setMode(EricPathPickerModes.DIRECTORY_SHOW_FILES_MODE)
721 self.bootPicker.setEnabled(False) 721 self.bootPicker.setEnabled(False)
722 722
723 self.searchBootButton.setIcon(EricPixmapCache.getIcon("question"))
724 self.searchBootButton.setEnabled(False)
725
723 self.__mandatoryStyleSheet = ( 726 self.__mandatoryStyleSheet = (
724 "QLineEdit {border: 2px solid; border-color: #dd8888}" 727 "QLineEdit {border: 2px solid; border-color: #dd8888}"
725 if ericApp().usesDarkPalette() 728 if ericApp().usesDarkPalette()
726 else "QLineEdit {border: 2px solid; border-color: #800000}" 729 else "QLineEdit {border: 2px solid; border-color: #800000}"
727 ) 730 )
1000 ).format(firmwareType) 1003 ).format(firmwareType)
1001 ) 1004 )
1002 QCoreApplication.processEvents( 1005 QCoreApplication.processEvents(
1003 QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents 1006 QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents
1004 ) 1007 )
1005 shutil.copy2(firmwarePath, volumePath) 1008 shutil.copy(firmwarePath, volumePath)
1006 QThread.sleep(1) 1009 QThread.sleep(1)
1007 self.on_refreshButton_clicked() 1010 self.on_refreshButton_clicked()
1008 1011
1009 @pyqtSlot() 1012 @pyqtSlot()
1010 def on_refreshButton_clicked(self): 1013 def on_refreshButton_clicked(self):
1026 @type int 1029 @type int
1027 """ 1030 """
1028 vidpid = self.devicesComboBox.itemData(index, self.DeviceVidPidRole) 1031 vidpid = self.devicesComboBox.itemData(index, self.DeviceVidPidRole)
1029 boardType = self.devicesComboBox.itemData(index, self.DeviceTypeRole) 1032 boardType = self.devicesComboBox.itemData(index, self.DeviceTypeRole)
1030 1033
1034 self.searchBootButton.setEnabled(boardType == self.__manualType)
1031 self.bootPicker.setEnabled(boardType == self.__manualType) 1035 self.bootPicker.setEnabled(boardType == self.__manualType)
1032 if boardType == self.__manualType: 1036 if boardType == self.__manualType:
1033 self.__showManualInstructions() 1037 self.__showManualInstructions()
1034 1038
1035 if vidpid is None: 1039 if vidpid is None:
1069 1073
1070 @param text current text of the boot volume edit 1074 @param text current text of the boot volume edit
1071 @type str 1075 @type str
1072 """ 1076 """
1073 self.__updateFlashButton() 1077 self.__updateFlashButton()
1078
1079 @pyqtSlot()
1080 def on_searchBootButton_clicked(self):
1081 """
1082 Private slot to look for all known boot paths and present a list to select from.
1083 """
1084 foundBootVolumes = set()
1085 for boardType in SupportedUF2Boards:
1086 for volumes in SupportedUF2Boards[boardType]["volumes"].values():
1087 for volume in volumes:
1088 foundBootVolumes.update(
1089 FileSystemUtilities.findVolume(volume, findAll=True)
1090 )
1091
1092 if len(foundBootVolumes) == 0:
1093 selectedVolume = ""
1094 elif len(foundBootVolumes) == 1:
1095 selectedVolume = list(foundBootVolumes)[0]
1096 else:
1097 result, ok = QInputDialog.getItem(
1098 None,
1099 QCoreApplication.translate("UF2FlashDialog", "Flash UF2 Device"),
1100 QCoreApplication.translate(
1101 "UF2FlashDialog", "Select the Boot Volume of the device:"
1102 ),
1103 list(foundBootVolumes),
1104 0, True,
1105 )
1106 selectedVolume = result if ok else ""
1107
1108 self.bootPicker.setText(selectedVolume)

eric ide

mercurial