17 |
17 |
18 from eric7.EricGui import EricPixmapCache |
18 from eric7.EricGui import EricPixmapCache |
19 from eric7.EricWidgets import EricMessageBox |
19 from eric7.EricWidgets import EricMessageBox |
20 from eric7.EricWidgets.EricApplication import ericApp |
20 from eric7.EricWidgets.EricApplication import ericApp |
21 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes |
21 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes |
22 from eric7.SystemUtilities import FileSystemUtilities |
22 from eric7.SystemUtilities import FileSystemUtilities, OSUtilities |
23 |
23 |
24 from . import Devices |
24 from . import Devices |
25 from .Ui_UF2FlashDialog import Ui_UF2FlashDialog |
25 from .Ui_UF2FlashDialog import Ui_UF2FlashDialog |
26 |
26 |
27 SupportedUF2Boards = { |
27 SupportedUF2Boards = { |
669 @rtype list of tuple of (str, str, (int, int)) |
669 @rtype list of tuple of (str, str, (int, int)) |
670 """ |
670 """ |
671 foundDevices = set() |
671 foundDevices = set() |
672 |
672 |
673 # step 1: determine all known UF2 volumes that are mounted |
673 # step 1: determine all known UF2 volumes that are mounted |
|
674 if not OSUtilities.isWindowsPlatform(): |
|
675 userMounts = FileSystemUtilities.getUserMounts() |
|
676 |
674 boardTypes = [boardType] if boardType else list(SupportedUF2Boards.keys()) |
677 boardTypes = [boardType] if boardType else list(SupportedUF2Boards.keys()) |
675 for board in boardTypes: |
678 for board in boardTypes: |
676 for vidpid, volumes in SupportedUF2Boards[board]["volumes"].items(): |
679 for vidpid, volumes in SupportedUF2Boards[board]["volumes"].items(): |
677 for volume, description in volumes: |
680 for volume, description in volumes: |
678 if FileSystemUtilities.findVolume(volume, findAll=True): |
681 if OSUtilities.isWindowsPlatform(): |
679 foundDevices.add((board, description, vidpid)) |
682 if FileSystemUtilities.findVolume(volume, findAll=True): |
680 |
683 foundDevices.add((board, description, vidpid)) |
681 # set 2: determine all devices that have their UF2 volume not mounted |
684 else: |
|
685 # check only user mounted devices on non-Windows systems |
|
686 for userMount in userMounts: |
|
687 if os.path.basename(userMount).startswith(volume): |
|
688 foundDevices.add((board, description, vidpid)) |
|
689 break |
|
690 |
|
691 # step 2: determine all devices that have their UF2 volume not mounted |
682 availablePorts = QSerialPortInfo.availablePorts() |
692 availablePorts = QSerialPortInfo.availablePorts() |
683 for port in availablePorts: |
693 for port in availablePorts: |
684 vid = port.vendorIdentifier() |
694 vid = port.vendorIdentifier() |
685 pid = port.productIdentifier() |
695 pid = port.productIdentifier() |
686 |
696 |
781 if devices: |
790 if devices: |
782 self.__showSpecificInstructions(list(devices)) |
791 self.__showSpecificInstructions(list(devices)) |
783 else: |
792 else: |
784 self.__showAllInstructions() |
793 self.__showAllInstructions() |
785 self.devicesComboBox.addItem(self.tr("Manual Select")) |
794 self.devicesComboBox.addItem(self.tr("Manual Select")) |
786 self.devicesComboBox.setItemData(1, self.__manualType, self.DeviceTypeRole) |
795 self.devicesComboBox.setItemData(0, self.__manualType, self.DeviceTypeRole) |
787 elif len(devices) == 1: |
796 elif len(devices) == 1: |
788 # set the board type to the found one |
797 # set the board type to the found one |
789 self.__boardType = devices[0][0] |
798 self.__boardType = devices[0][0] |
790 |
799 |
791 self.devicesComboBox.addItem(devices[0][1]) |
800 self.devicesComboBox.addItem(devices[0][1]) |
1033 """ |
1042 """ |
1034 Private slot to refresh the dialog. |
1043 Private slot to refresh the dialog. |
1035 """ |
1044 """ |
1036 self.__populate() |
1045 self.__populate() |
1037 self.__updateFlashButton() |
1046 self.__updateFlashButton() |
|
1047 self.on_devicesComboBox_currentIndexChanged(0) |
1038 |
1048 |
1039 @pyqtSlot(int) |
1049 @pyqtSlot(int) |
1040 def on_devicesComboBox_currentIndexChanged(self, index): |
1050 def on_devicesComboBox_currentIndexChanged(self, index): |
1041 """ |
1051 """ |
1042 Private slot to handle the selection of a board. |
1052 Private slot to handle the selection of a board. |
1096 def on_searchBootButton_clicked(self): |
1106 def on_searchBootButton_clicked(self): |
1097 """ |
1107 """ |
1098 Private slot to look for all known boot paths and present a list to select from. |
1108 Private slot to look for all known boot paths and present a list to select from. |
1099 """ |
1109 """ |
1100 foundBootVolumes = set() |
1110 foundBootVolumes = set() |
|
1111 if not OSUtilities.isWindowsPlatform(): |
|
1112 userMounts = FileSystemUtilities.getUserMounts() |
|
1113 |
1101 for boardType in SupportedUF2Boards: |
1114 for boardType in SupportedUF2Boards: |
1102 for volumes in SupportedUF2Boards[boardType]["volumes"].values(): |
1115 for volumes in SupportedUF2Boards[boardType]["volumes"].values(): |
1103 for volume, _ in volumes: |
1116 for volume, _ in volumes: |
1104 foundBootVolumes.update( |
1117 if OSUtilities.isWindowsPlatform(): |
1105 FileSystemUtilities.findVolume(volume, findAll=True) |
1118 foundBootVolumes.update( |
1106 ) |
1119 FileSystemUtilities.findVolume(volume, findAll=True) |
|
1120 ) |
|
1121 else: |
|
1122 # check only user mounted devices on non-Windows systems |
|
1123 for userMount in userMounts: |
|
1124 if os.path.basename(userMount).startswith(volume): |
|
1125 foundBootVolumes.add(userMount) |
1107 |
1126 |
1108 if len(foundBootVolumes) == 0: |
1127 if len(foundBootVolumes) == 0: |
1109 selectedVolume = "" |
1128 selectedVolume = "" |
1110 EricMessageBox.information( |
1129 EricMessageBox.information( |
1111 self, |
1130 self, |