eric6/MicroPython/MicrobitDevices.py

changeset 8062
8dc5acb30a8b
parent 8051
b78279548993
child 8067
a467ab075be0
equal deleted inserted replaced
8061:979562f350bf 8062:8dc5acb30a8b
40 @type QObject 40 @type QObject
41 """ 41 """
42 super(MicrobitDevice, self).__init__(microPythonWidget, parent) 42 super(MicrobitDevice, self).__init__(microPythonWidget, parent)
43 43
44 self.__deviceType = deviceType 44 self.__deviceType = deviceType
45
46 self.__workspace = self.__findWorkspace()
45 47
46 def setButtons(self): 48 def setButtons(self):
47 """ 49 """
48 Public method to enable the supported action buttons. 50 Public method to enable the supported action buttons.
49 """ 51 """
130 Public method to get the workspace directory. 132 Public method to get the workspace directory.
131 133
132 @return workspace directory used for saving files 134 @return workspace directory used for saving files
133 @rtype str 135 @rtype str
134 """ 136 """
137 if self.__workspace:
138 # return cached entry
139 return self.__workspace
140 else:
141 self.__workspace = self.__findWorkspace()
142 return self.__workspace
143
144 def __findWorkspace(self):
145 """
146 Public method to find the workspace directory.
147
148 @return workspace directory used for saving files
149 @rtype str
150 """
135 # Attempts to find the path on the filesystem that represents the 151 # Attempts to find the path on the filesystem that represents the
136 # plugged in MICROBIT or MINI board. 152 # plugged in MICROBIT or MINI board.
137 if self.__deviceType == "bbc_microbit": 153 if self.__deviceType == "bbc_microbit":
138 # BBC micro:bit 154 # BBC micro:bit
139 deviceDirectory = Utilities.findVolume("MICROBIT") 155 deviceDirectories = Utilities.findVolume("MICROBIT", all=True)
140 else: 156 else:
141 # Calliope mini 157 # Calliope mini
142 deviceDirectory = Utilities.findVolume("MINI") 158 deviceDirectories = Utilities.findVolume("MINI", all=True)
143 159
144 if deviceDirectory: 160 if deviceDirectories:
145 return deviceDirectory 161 if len(deviceDirectories) == 1:
162 return deviceDirectories[0]
163 else:
164 return self.selectDeviceDirectory(deviceDirectories)
146 else: 165 else:
147 # return the default workspace and give the user a warning 166 # return the default workspace and give the user a warning
148 E5MessageBox.warning( 167 E5MessageBox.warning(
149 self.microPython, 168 self.microPython,
150 self.tr("Workspace Directory"), 169 self.tr("Workspace Directory"),
205 @type bool 224 @type bool
206 """ 225 """
207 # Attempts to find the path on the file system that represents the 226 # Attempts to find the path on the file system that represents the
208 # plugged in micro:bit board. To flash the DAPLink firmware, it must be 227 # plugged in micro:bit board. To flash the DAPLink firmware, it must be
209 # in maintenance mode, for MicroPython in standard mode. 228 # in maintenance mode, for MicroPython in standard mode.
210 # The Calliope mini board must be in standard mode.
211 if self.__deviceType == "bbc_microbit": 229 if self.__deviceType == "bbc_microbit":
212 # BBC micro:bit 230 # BBC micro:bit
213 if firmware: 231 if firmware:
214 deviceDirectory = Utilities.findVolume("MAINTENANCE") 232 deviceDirectories = Utilities.findVolume("MAINTENANCE",
233 all=True)
215 else: 234 else:
216 deviceDirectory = Utilities.findVolume("MICROBIT") 235 deviceDirectories = Utilities.findVolume("MICROBIT",
236 all=True)
217 else: 237 else:
218 # Calliope mini 238 # Calliope mini
219 if firmware: 239 if firmware:
220 deviceDirectory = Utilities.findVolume("MAINTENANCE") 240 deviceDirectories = Utilities.findVolume("MAINTENANCE",
241 all=True)
221 else: 242 else:
222 deviceDirectory = Utilities.findVolume("MINI") 243 deviceDirectories = Utilities.findVolume("MINI", all=True)
223 if not deviceDirectory: 244 if len(deviceDirectories) == 0:
224 if self.__deviceType == "bbc_microbit": 245 if self.__deviceType == "bbc_microbit":
225 # BBC micro:bit is not ready or not mounted 246 # BBC micro:bit is not ready or not mounted
226 if firmware: 247 if firmware:
227 E5MessageBox.critical( 248 E5MessageBox.critical(
228 self.microPython, 249 self.microPython,
282 ' the MicroPython firmware. Please make sure,' 303 ' the MicroPython firmware. Please make sure,'
283 ' that a drive called MINI is available.' 304 ' that a drive called MINI is available.'
284 '</p>' 305 '</p>'
285 ) 306 )
286 ) 307 )
287 else: 308 elif len(deviceDirectories) == 1:
288 downloadsPath = QStandardPaths.standardLocations( 309 downloadsPath = QStandardPaths.standardLocations(
289 QStandardPaths.DownloadLocation)[0] 310 QStandardPaths.DownloadLocation)[0]
290 firmware = E5FileDialog.getOpenFileName( 311 firmware = E5FileDialog.getOpenFileName(
291 self.microPython, 312 self.microPython,
292 self.tr("Flash MicroPython/Firmware"), 313 self.tr("Flash MicroPython/Firmware"),
293 downloadsPath, 314 downloadsPath,
294 self.tr("MicroPython/Firmware Files (*.hex *.bin);;" 315 self.tr("MicroPython/Firmware Files (*.hex *.bin);;"
295 "All Files (*)")) 316 "All Files (*)"))
296 if firmware and os.path.exists(firmware): 317 if firmware and os.path.exists(firmware):
297 shutil.copy2(firmware, deviceDirectory) 318 shutil.copy2(firmware, deviceDirectories[0])
319 else:
320 E5MessageBox.warning(
321 self,
322 self.tr("Flash MicroPython/Firmware"),
323 self.tr("There are multiple devices in ready for flashing."
324 " Please make sure, that only one device is prepared.")
325 )
298 326
299 @pyqtSlot() 327 @pyqtSlot()
300 def __saveMain(self): 328 def __saveMain(self):
301 """ 329 """
302 Private slot to copy the current script as 'main.py' onto the 330 Private slot to copy the current script as 'main.py' onto the

eric ide

mercurial