15 |
15 |
16 from eric7 import Preferences |
16 from eric7 import Preferences |
17 from eric7.EricWidgets import EricFileDialog, EricMessageBox |
17 from eric7.EricWidgets import EricFileDialog, EricMessageBox |
18 from eric7.SystemUtilities import FileSystemUtilities |
18 from eric7.SystemUtilities import FileSystemUtilities |
19 |
19 |
|
20 from .CircuitPythonUpdater.CircuitPythonUpdaterInterface import ( |
|
21 CircuitPythonUpdaterInterface, |
|
22 isCircupAvailable, |
|
23 ) |
20 from .MicroPythonDevices import MicroPythonDevice |
24 from .MicroPythonDevices import MicroPythonDevice |
21 from .MicroPythonWidget import HAS_QTCHART |
25 from .MicroPythonWidget import HAS_QTCHART |
22 |
26 |
23 |
27 |
24 class CircuitPythonDevice(MicroPythonDevice): |
28 class CircuitPythonDevice(MicroPythonDevice): |
44 super().__init__(microPythonWidget, deviceType, parent) |
48 super().__init__(microPythonWidget, deviceType, parent) |
45 |
49 |
46 self.__boardName = boardName |
50 self.__boardName = boardName |
47 self.__workspace = self.__findWorkspace() |
51 self.__workspace = self.__findWorkspace() |
48 |
52 |
|
53 self.__updater = CircuitPythonUpdaterInterface(self) |
|
54 |
49 self.__nonUF2devices = { |
55 self.__nonUF2devices = { |
50 "teensy": self.__flashTeensy, |
56 "teensy": self.__flashTeensy, |
51 } |
57 } |
52 |
58 |
53 def setButtons(self): |
59 def setButtons(self): |
149 """ |
155 """ |
150 if self.__workspace and not os.path.exists(self.__workspace): |
156 if self.__workspace and not os.path.exists(self.__workspace): |
151 self.__workspace = "" # reset |
157 self.__workspace = "" # reset |
152 |
158 |
153 return self.DeviceVolumeName in self.getWorkspace(silent=True) |
159 return self.DeviceVolumeName in self.getWorkspace(silent=True) |
154 |
|
155 def getWorkspace(self, silent=False): |
|
156 """ |
|
157 Public method to get the workspace directory. |
|
158 |
|
159 @param silent flag indicating silent operations |
|
160 @type bool |
|
161 @return workspace directory used for saving files |
|
162 @rtype str |
|
163 """ |
|
164 if self.__workspace: |
|
165 # return cached entry |
|
166 return self.__workspace |
|
167 else: |
|
168 self.__workspace = self.__findWorkspace(silent=silent) |
|
169 return self.__workspace |
|
170 |
160 |
171 def __findDeviceDirectories(self, directories): |
161 def __findDeviceDirectories(self, directories): |
172 """ |
162 """ |
173 Private method to find the device directories associated with the |
163 Private method to find the device directories associated with the |
174 current board name. |
164 current board name. |
230 ), |
220 ), |
231 ) |
221 ) |
232 |
222 |
233 return super().getWorkspace() |
223 return super().getWorkspace() |
234 |
224 |
|
225 def getWorkspace(self, silent=False): |
|
226 """ |
|
227 Public method to get the workspace directory. |
|
228 |
|
229 @param silent flag indicating silent operations |
|
230 @type bool |
|
231 @return workspace directory used for saving files |
|
232 @rtype str |
|
233 """ |
|
234 if self.__workspace: |
|
235 # return cached entry |
|
236 return self.__workspace |
|
237 else: |
|
238 self.__workspace = self.__findWorkspace(silent=silent) |
|
239 return self.__workspace |
|
240 |
235 def addDeviceMenuEntries(self, menu): |
241 def addDeviceMenuEntries(self, menu): |
236 """ |
242 """ |
237 Public method to add device specific entries to the given menu. |
243 Public method to add device specific entries to the given menu. |
238 |
244 |
239 @param menu reference to the context menu |
245 @param menu reference to the context menu |
240 @type QMenu |
246 @type QMenu |
241 """ |
247 """ |
242 connected = self.microPython.isConnected() |
248 connected = self.microPython.isConnected() |
243 |
249 |
244 self.__libraryMenu = QMenu(self.tr("Library Management")) |
250 self.__libraryMenu = QMenu(self.tr("Library Management")) |
245 act = self.__libraryMenu.addAction( |
251 self.__libraryMenu.aboutToShow.connect(self.__aboutToShowLibraryMenu) |
246 self.tr("Install Library Files"), self.__installLibraryFiles |
252 self.__libraryMenu.setTearOffEnabled(True) |
247 ) |
|
248 act.setEnabled(self.__deviceVolumeMounted()) |
|
249 act = self.__libraryMenu.addAction( |
|
250 self.tr("Install Library Package"), |
|
251 lambda: self.__installLibraryFiles(packageMode=True), |
|
252 ) |
|
253 act.setEnabled(self.__deviceVolumeMounted()) |
|
254 |
253 |
255 act = menu.addAction( |
254 act = menu.addAction( |
256 self.tr("Flash CircuitPython Firmware"), self.__flashCircuitPython |
255 self.tr("Flash CircuitPython Firmware"), self.__flashCircuitPython |
257 ) |
256 ) |
258 act.setEnabled(not connected) |
257 act.setEnabled(not connected) |
259 menu.addSeparator() |
258 menu.addSeparator() |
260 menu.addMenu(self.__libraryMenu) |
259 menu.addMenu(self.__libraryMenu) |
|
260 |
|
261 @pyqtSlot() |
|
262 def __aboutToShowLibraryMenu(self): |
|
263 """ |
|
264 Private slot to populate the 'Library Management' menu. |
|
265 """ |
|
266 self.__libraryMenu.clear() |
|
267 |
|
268 if isCircupAvailable(): |
|
269 self.__updater.populateMenu(self.__libraryMenu) |
|
270 else: |
|
271 act = self.__libraryMenu.addAction( |
|
272 self.tr("Install Library Files"), self.__installLibraryFiles |
|
273 ) |
|
274 act.setEnabled(self.__deviceVolumeMounted()) |
|
275 act = self.__libraryMenu.addAction( |
|
276 self.tr("Install Library Package"), |
|
277 lambda: self.__installLibraryFiles(packageMode=True), |
|
278 ) |
|
279 act.setEnabled(self.__deviceVolumeMounted()) |
|
280 self.__libraryMenu.addSeparator() |
|
281 self.__libraryMenu.addAction( |
|
282 self.tr("Install 'circup' Package"), |
|
283 self.__updater.installCircup, |
|
284 ) |
261 |
285 |
262 def hasFlashMenuEntry(self): |
286 def hasFlashMenuEntry(self): |
263 """ |
287 """ |
264 Public method to check, if the device has its own flash menu entry. |
288 Public method to check, if the device has its own flash menu entry. |
265 |
289 |