eric6/MicroPython/CircuitPythonDevices.py

branch
micropython
changeset 7138
a2a53535d855
parent 7134
21d23ca51680
child 7145
ceb3e8b242c1
equal deleted inserted replaced
7137:4ed2573947ff 7138:a2a53535d855
8 """ 8 """
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 import shutil 12 import shutil
13 import os
13 14
14 from PyQt5.QtCore import pyqtSlot 15 from PyQt5.QtCore import pyqtSlot
15 from PyQt5.QtWidgets import QDialog 16 from PyQt5.QtWidgets import QDialog
16 17
17 from E5Gui import E5MessageBox 18 from E5Gui import E5MessageBox, E5FileDialog
18 19
19 from .MicroPythonDevices import MicroPythonDevice 20 from .MicroPythonDevices import MicroPythonDevice
20 from .MicroPythonWidget import HAS_QTCHART 21 from .MicroPythonWidget import HAS_QTCHART
21 22
22 import Utilities 23 import Utilities
172 connected = self.microPython.isConnected() 173 connected = self.microPython.isConnected()
173 174
174 act = menu.addAction(self.tr("Flash CircuitPython Firmware"), 175 act = menu.addAction(self.tr("Flash CircuitPython Firmware"),
175 self.__flashCircuitPython) 176 self.__flashCircuitPython)
176 act.setEnabled(not connected) 177 act.setEnabled(not connected)
177 # TODO: add menu entry to copy a .mpy or .py file to the 178 menu.addSeparator()
178 # device library (creating the /lib folder if it doesn't 179 act = menu.addAction(self.tr("Install Library Files"),
179 # exist already) 180 self.__installLibraryFiles)
181 act.setEnabled(self.__deviceVolumeMounted())
180 182
181 @pyqtSlot() 183 @pyqtSlot()
182 def __flashCircuitPython(self): 184 def __flashCircuitPython(self):
183 """ 185 """
184 Private slot to flash a CircuitPython firmware to the device. 186 Private slot to flash a CircuitPython firmware to the device.
196 CircuitPythonFirmwareSelectionDialog) 198 CircuitPythonFirmwareSelectionDialog)
197 dlg = CircuitPythonFirmwareSelectionDialog() 199 dlg = CircuitPythonFirmwareSelectionDialog()
198 if dlg.exec_() == QDialog.Accepted: 200 if dlg.exec_() == QDialog.Accepted:
199 cpyPath, devicePath = dlg.getData() 201 cpyPath, devicePath = dlg.getData()
200 shutil.copy2(cpyPath, devicePath) 202 shutil.copy2(cpyPath, devicePath)
203
204 @pyqtSlot()
205 def __installLibraryFiles(self):
206 """
207 Private slot to install Python files into the onboard library.
208 """
209 if not self.__deviceVolumeMounted():
210 E5MessageBox.critical(
211 self.microPython,
212 self.tr("Install Library Files"),
213 self.tr("""The device volume "<b>{0}</b>" is not available."""
214 """ Ensure it is mounted properly and try again."""))
215 return
216
217 target = os.path.join(self.getWorkspace(), "lib")
218 # ensure that the library directory exists on the device
219 if not os.path.isdir(target):
220 os.makedirs(target)
221
222 libraryFiles = E5FileDialog.getOpenFileNames(
223 self.microPython,
224 self.tr("Install Library Files"),
225 os.path.expanduser("~"),
226 self.tr("Compiled Python Files (*.mpy);;"
227 "Python Files (*.py);;"
228 "All Files (*)"))
229
230 for libraryFile in libraryFiles:
231 if os.path.exists(libraryFile):
232 shutil.copy2(libraryFile, target)

eric ide

mercurial