12 import os |
12 import os |
13 import shutil |
13 import shutil |
14 |
14 |
15 from PyQt6.QtCore import QStandardPaths, QUrl, pyqtSlot |
15 from PyQt6.QtCore import QStandardPaths, QUrl, pyqtSlot |
16 from PyQt6.QtNetwork import QNetworkRequest |
16 from PyQt6.QtNetwork import QNetworkRequest |
17 from PyQt6.QtWidgets import QInputDialog, QLineEdit |
17 from PyQt6.QtWidgets import QInputDialog, QLineEdit, QMenu |
18 |
18 |
19 from eric7 import Globals, Preferences |
19 from eric7 import Globals, Preferences |
20 from eric7.EricWidgets import EricFileDialog, EricMessageBox |
20 from eric7.EricWidgets import EricFileDialog, EricMessageBox |
21 from eric7.EricWidgets.EricApplication import ericApp |
21 from eric7.EricWidgets.EricApplication import ericApp |
22 from eric7.SystemUtilities import FileSystemUtilities |
22 from eric7.SystemUtilities import FileSystemUtilities |
176 @return flag indicating a Calliope mini |
178 @return flag indicating a Calliope mini |
177 @rtype bool |
179 @rtype bool |
178 """ |
180 """ |
179 return self.__boardId in (0x12A0,) |
181 return self.__boardId in (0x12A0,) |
180 |
182 |
|
183 def __createMicrobitMenu(self): |
|
184 """ |
|
185 Private method to create the microbit submenu. |
|
186 """ |
|
187 self.__microbitMenu = QMenu(self.tr("BBC micro:bit/Calliope Functions")) |
|
188 |
|
189 self.__showMpyAct = self.__microbitMenu.addAction( |
|
190 self.tr("Show MicroPython Versions"), self.__showFirmwareVersions |
|
191 ) |
|
192 self.__microbitMenu.addSeparator() |
|
193 self.__flashMpyAct = self.__microbitMenu.addAction( |
|
194 self.tr("Flash MicroPython"), self.__flashMicroPython |
|
195 ) |
|
196 self.__flashDAPLinkAct = self.__microbitMenu.addAction( |
|
197 self.tr("Flash Firmware"), lambda: self.__flashMicroPython(firmware=True) |
|
198 ) |
|
199 self.__microbitMenu.addSeparator() |
|
200 self.__saveScripAct = self.__microbitMenu.addAction( |
|
201 self.tr("Save Script"), self.__saveScriptToDevice |
|
202 ) |
|
203 self.__saveScripAct.setToolTip( |
|
204 self.tr("Save the current script to the selected device") |
|
205 ) |
|
206 self.__saveMainScriptAct = self.__microbitMenu.addAction( |
|
207 self.tr("Save Script as 'main.py'"), self.__saveMain |
|
208 ) |
|
209 self.__saveMainScriptAct.setToolTip( |
|
210 self.tr("Save the current script as 'main.py' on the connected device") |
|
211 ) |
|
212 self.__microbitMenu.addSeparator() |
|
213 self.__resetAct = self.__microbitMenu.addAction( |
|
214 self.tr("Reset {0}").format(self.deviceName()), self.__resetDevice |
|
215 ) |
|
216 |
181 def addDeviceMenuEntries(self, menu): |
217 def addDeviceMenuEntries(self, menu): |
182 """ |
218 """ |
183 Public method to add device specific entries to the given menu. |
219 Public method to add device specific entries to the given menu. |
184 |
220 |
185 @param menu reference to the context menu |
221 @param menu reference to the context menu |
186 @type QMenu |
222 @type QMenu |
187 """ |
223 """ |
188 connected = self.microPython.isConnected() |
224 connected = self.microPython.isConnected() |
189 linkConnected = self.microPython.isLinkConnected() |
225 linkConnected = self.microPython.isLinkConnected() |
190 |
226 |
191 menu.addAction( |
227 self.__showMpyAct.setEnabled(connected and self.getDeviceType() != "calliope") |
192 self.tr("Show MicroPython Versions"), self.__showFirmwareVersions |
228 self.__flashMpyAct.setEnabled(not linkConnected) |
193 ).setEnabled(connected and self.getDeviceType() != "calliope") |
229 self.__flashDAPLinkAct.setEnabled(not linkConnected) |
194 menu.addAction( |
230 self.__saveScripAct.setEnabled(connected) |
195 self.tr("Flash MicroPython"), self.__flashMicroPython |
231 self.__saveMainScriptAct.setEnabled(connected) |
196 ).setEnabled(not linkConnected) |
232 self.__resetAct.setEnabled(connected) |
197 menu.addAction( |
233 |
198 self.tr("Flash Firmware"), lambda: self.__flashMicroPython(firmware=True) |
234 menu.addMenu(self.__microbitMenu) |
199 ).setEnabled(not linkConnected) |
|
200 menu.addSeparator() |
|
201 act = menu.addAction(self.tr("Save Script"), self.__saveScriptToDevice) |
|
202 act.setToolTip(self.tr("Save the current script to the selected device")) |
|
203 act.setEnabled(connected) |
|
204 act = menu.addAction(self.tr("Save Script as 'main.py'"), self.__saveMain) |
|
205 act.setToolTip( |
|
206 self.tr("Save the current script as 'main.py' on the connected device") |
|
207 ) |
|
208 act.setEnabled(connected) |
|
209 menu.addSeparator() |
|
210 menu.addAction( |
|
211 self.tr("Reset {0}").format(self.deviceName()), self.__resetDevice |
|
212 ).setEnabled(connected) |
|
213 |
235 |
214 def hasFlashMenuEntry(self): |
236 def hasFlashMenuEntry(self): |
215 """ |
237 """ |
216 Public method to check, if the device has its own flash menu entry. |
238 Public method to check, if the device has its own flash menu entry. |
217 |
239 |