src/eric7/MicroPython/MicrobitDevices.py

Wed, 08 Feb 2023 18:09:19 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 08 Feb 2023 18:09:19 +0100
branch
eric7
changeset 9749
5d409223cf3f
parent 9738
4ae976ee5339
child 9750
4958dd72c937
permissions
-rw-r--r--

MicroPython
- Added functionality to show the installed firmware version and the version
available on Github (for remaining boards).

7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
9653
e67609152c5e Updated copyright for 2023.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
3 # Copyright (c) 2019 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
7549
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
7 Module implementing the device interface class for BBC micro:bit and
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
8 Calliope mini boards.
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
11 import os
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
12 import shutil
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
13
9749
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
14 from PyQt6.QtCore import QStandardPaths, QUrl, pyqtSlot
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
15 from PyQt6.QtNetwork import QNetworkRequest
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
16 from PyQt6.QtWidgets import QInputDialog, QLineEdit
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
17
9749
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
18 from eric7 import Globals, Preferences
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
19 from eric7.EricWidgets import EricFileDialog, EricMessageBox
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
20 from eric7.EricWidgets.EricApplication import ericApp
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9576
diff changeset
21 from eric7.SystemUtilities import FileSystemUtilities
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
22
9749
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
23 from .MicroPythonDevices import FirmwareGithubUrls, MicroPythonDevice
7134
21d23ca51680 Renamed "MicroPythonReplWidget" to "MicroPythonWidget".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7126
diff changeset
24 from .MicroPythonWidget import HAS_QTCHART
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 class MicrobitDevice(MicroPythonDevice):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
7549
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
29 Class implementing the device for BBC micro:bit and Calliope mini boards.
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
31
7549
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
32 def __init__(self, microPythonWidget, deviceType, parent=None):
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
35
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 @param microPythonWidget reference to the main MicroPython widget
7134
21d23ca51680 Renamed "MicroPythonReplWidget" to "MicroPythonWidget".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7126
diff changeset
37 @type MicroPythonWidget
7549
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
38 @param deviceType type of the device
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
39 @type str
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 @param parent reference to the parent object
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 @type QObject
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
43 super().__init__(microPythonWidget, deviceType, parent)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
44
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 def setButtons(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 Public method to enable the supported action buttons.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
49 super().setButtons()
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.microPython.setActionButtons(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
51 run=True, repl=True, files=True, chart=HAS_QTCHART
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
52 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
53
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 def forceInterrupt(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 Public method to determine the need for an interrupt when opening the
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 serial connection.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
58
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 @return flag indicating an interrupt is needed
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 @rtype bool
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 return True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
63
7126
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
64 def deviceName(self):
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
65 """
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
66 Public method to get the name of the device.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
67
7126
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
68 @return name of the device
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
69 @rtype str
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
70 """
8117
aaa5e0eacd4e MicroPython: changed the logic to synchronize the time because some devices don't implement long integer and failed defining the 'set_time()' function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8096
diff changeset
71 if self.getDeviceType() == "bbc_microbit":
7551
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
72 # BBC micro:bit
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
73 return self.tr("BBC micro:bit")
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
74 else:
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
75 # Calliope mini
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
76 return self.tr("Calliope mini")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
77
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 def canStartRepl(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 Public method to determine, if a REPL can be started.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
81
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 @return tuple containing a flag indicating it is safe to start a REPL
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 and a reason why it cannot.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 @rtype tuple of (bool, str)
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 """
7100
c4d9c28ebcd8 Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
86 return True, ""
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
87
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 def canStartPlotter(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 Public method to determine, if a Plotter can be started.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
91
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 @return tuple containing a flag indicating it is safe to start a
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 Plotter and a reason why it cannot.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 @rtype tuple of (bool, str)
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 """
7100
c4d9c28ebcd8 Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
96 return True, ""
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
97
7126
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
98 def canRunScript(self):
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
99 """
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
100 Public method to determine, if a script can be executed.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
101
7126
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
102 @return tuple containing a flag indicating it is safe to start a
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
103 Plotter and a reason why it cannot.
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
104 @rtype tuple of (bool, str)
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
105 """
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
106 return True, ""
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
107
7126
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
108 def runScript(self, script):
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
109 """
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
110 Public method to run the given Python script.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
111
7126
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
112 @param script script to be executed
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
113 @type str
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
114 """
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
115 pythonScript = script.split("\n")
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
116 self.sendCommands(pythonScript)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
117
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 def canStartFileManager(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 Public method to determine, if a File Manager can be started.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
121
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 @return tuple containing a flag indicating it is safe to start a
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 File Manager and a reason why it cannot.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 @rtype tuple of (bool, str)
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 """
7126
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
126 return True, ""
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
127
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
128 def hasTimeCommands(self):
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
129 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
130 Public method to check, if the device supports time commands.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
131
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
132 The default returns True.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
133
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
134 @return flag indicating support for time commands
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
135 @rtype bool
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
136 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
137 return False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
138
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
139 def addDeviceMenuEntries(self, menu):
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
140 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
141 Public method to add device specific entries to the given menu.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
142
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
143 @param menu reference to the context menu
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
144 @type QMenu
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
145 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
146 connected = self.microPython.isConnected()
9749
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
147 linkConnected = self.microPython.isLinkConnected()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
148
9749
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
149 menu.addAction(
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
150 self.tr("Show MicroPython Versions"), self.__showFirmwareVersions
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
151 ).setEnabled(connected and self.getDeviceType() != "calliope")
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
152 menu.addAction(
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
153 self.tr("Flash MicroPython"), self.__flashMicroPython
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
154 ).setEnabled(not linkConnected)
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
155 menu.addAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
156 self.tr("Flash Firmware"), lambda: self.__flashMicroPython(firmware=True)
9749
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
157 ).setEnabled(not linkConnected)
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
158 menu.addSeparator()
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
159 act = menu.addAction(self.tr("Save Script"), self.__saveScriptToDevice)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
160 act.setToolTip(self.tr("Save the current script to the selected device"))
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
161 act.setEnabled(connected)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
162 act = menu.addAction(self.tr("Save Script as 'main.py'"), self.__saveMain)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
163 act.setToolTip(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
164 self.tr("Save the current script as 'main.py' on the connected device")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
165 )
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
166 act.setEnabled(connected)
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
167 menu.addSeparator()
9749
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
168 menu.addAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
169 self.tr("Reset {0}").format(self.deviceName()), self.__resetDevice
9749
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
170 ).setEnabled(connected)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
171
8096
5425a9072300 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8091
diff changeset
172 def hasFlashMenuEntry(self):
5425a9072300 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8091
diff changeset
173 """
5425a9072300 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8091
diff changeset
174 Public method to check, if the device has its own flash menu entry.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
175
8096
5425a9072300 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8091
diff changeset
176 @return flag indicating a specific flash menu entry
5425a9072300 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8091
diff changeset
177 @rtype bool
5425a9072300 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8091
diff changeset
178 """
5425a9072300 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8091
diff changeset
179 return True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
180
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
181 @pyqtSlot()
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
182 def __flashMicroPython(self, firmware=False):
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
183 """
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
184 Private slot to flash MicroPython or the DAPLink firmware to the
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
185 device.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
186
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
187 @param firmware flag indicating to flash the DAPLink firmware
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
188 @type bool
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
189 """
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
190 # Attempts to find the path on the file system that represents the
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
191 # plugged in micro:bit board. To flash the DAPLink firmware, it must be
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
192 # in maintenance mode, for MicroPython in standard mode.
8117
aaa5e0eacd4e MicroPython: changed the logic to synchronize the time because some devices don't implement long integer and failed defining the 'set_time()' function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8096
diff changeset
193 if self.getDeviceType() == "bbc_microbit":
7552
b62e73df71dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7551
diff changeset
194 # BBC micro:bit
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
195 if firmware:
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9576
diff changeset
196 deviceDirectories = FileSystemUtilities.findVolume(
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9576
diff changeset
197 "MAINTENANCE", findAll=True
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9576
diff changeset
198 )
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
199 else:
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9576
diff changeset
200 deviceDirectories = FileSystemUtilities.findVolume(
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9576
diff changeset
201 "MICROBIT", findAll=True
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9576
diff changeset
202 )
7552
b62e73df71dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7551
diff changeset
203 else:
b62e73df71dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7551
diff changeset
204 # Calliope mini
8051
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
205 if firmware:
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9576
diff changeset
206 deviceDirectories = FileSystemUtilities.findVolume(
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9576
diff changeset
207 "MAINTENANCE", findAll=True
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9576
diff changeset
208 )
8051
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
209 else:
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9576
diff changeset
210 deviceDirectories = FileSystemUtilities.findVolume("MINI", findAll=True)
8062
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8051
diff changeset
211 if len(deviceDirectories) == 0:
8117
aaa5e0eacd4e MicroPython: changed the logic to synchronize the time because some devices don't implement long integer and failed defining the 'set_time()' function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8096
diff changeset
212 if self.getDeviceType() == "bbc_microbit":
7551
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
213 # BBC micro:bit is not ready or not mounted
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
214 if firmware:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
215 EricMessageBox.critical(
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
216 self.microPython,
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
217 self.tr("Flash MicroPython/Firmware"),
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
218 self.tr(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
219 "<p>The BBC micro:bit is not ready for flashing"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
220 " the DAPLink firmware. Follow these"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
221 " instructions. </p>"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
222 "<ul>"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
223 "<li>unplug USB cable and any batteries</li>"
9749
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
224 "<li>keep RESET button pressed and plug USB cable"
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
225 " back in</li>"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
226 "<li>a drive called MAINTENANCE should be"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
227 " available</li>"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
228 "</ul>"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
229 "<p>See the "
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
230 '<a href="https://microbit.org/guide/firmware/">'
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
231 "micro:bit web site</a> for details.</p>"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
232 ),
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
233 )
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
234 else:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
235 EricMessageBox.critical(
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
236 self.microPython,
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
237 self.tr("Flash MicroPython/Firmware"),
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
238 self.tr(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
239 "<p>The BBC micro:bit is not ready for flashing"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
240 " the MicroPython firmware. Please make sure,"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
241 " that a drive called MICROBIT is available."
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
242 "</p>"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
243 ),
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
244 )
7551
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
245 else:
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
246 # Calliope mini is not ready or not mounted
8051
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
247 if firmware:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
248 EricMessageBox.critical(
8051
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
249 self.microPython,
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
250 self.tr("Flash MicroPython/Firmware"),
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
251 self.tr(
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
252 '<p>The "Calliope mini" is not ready for flashing'
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
253 " the DAPLink firmware. Follow these"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
254 " instructions. </p>"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
255 "<ul>"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
256 "<li>unplug USB cable and any batteries</li>"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
257 "<li>keep RESET button pressed an plug USB cable"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
258 " back in</li>"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
259 "<li>a drive called MAINTENANCE should be"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
260 " available</li>"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
261 "</ul>"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
262 ),
8051
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
263 )
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
264 else:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
265 EricMessageBox.critical(
8051
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
266 self.microPython,
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
267 self.tr("Flash MicroPython/Firmware"),
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
268 self.tr(
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
269 '<p>The "Calliope mini" is not ready for flashing'
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
270 " the MicroPython firmware. Please make sure,"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
271 " that a drive called MINI is available."
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
272 "</p>"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
273 ),
8051
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
274 )
8062
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8051
diff changeset
275 elif len(deviceDirectories) == 1:
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
276 downloadsPath = QStandardPaths.standardLocations(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
277 QStandardPaths.StandardLocation.DownloadLocation
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
278 )[0]
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
279 firmware = EricFileDialog.getOpenFileName(
7173
f611c3b7313f EspDevices, MicrobitDevices: fixed a few omissions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7161
diff changeset
280 self.microPython,
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
281 self.tr("Flash MicroPython/Firmware"),
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
282 downloadsPath,
9576
be9f8e7e42e0 Corrected some 'wrong' string quotes caused by the Black line merging.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9496
diff changeset
283 self.tr("MicroPython/Firmware Files (*.hex *.bin);;All Files (*)"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
284 )
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
285 if firmware and os.path.exists(firmware):
8062
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8051
diff changeset
286 shutil.copy2(firmware, deviceDirectories[0])
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8051
diff changeset
287 else:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
288 EricMessageBox.warning(
8062
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8051
diff changeset
289 self,
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8051
diff changeset
290 self.tr("Flash MicroPython/Firmware"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
291 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
292 "There are multiple devices ready for flashing."
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
293 " Please make sure, that only one device is prepared."
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
294 ),
8062
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8051
diff changeset
295 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
296
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
297 @pyqtSlot()
9749
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
298 def __showFirmwareVersions(self):
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
299 """
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
300 Private slot to show the firmware version of the connected device and the
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
301 available firmware version.
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
302 """
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
303 if self.microPython.isConnected():
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
304 interface = self.microPython.commandsInterface()
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
305 if interface is not None:
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
306 impInfo = interface.getImplementation()
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
307 versionInfo = interface.version()
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
308 if impInfo["name"] != "micropython":
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
309 EricMessageBox.critical(
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
310 None,
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
311 self.tr("Show MicroPython Versions"),
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
312 self.tr(
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
313 """The firmware of the connected device cannot be"""
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
314 """ determined or the board does not run MicroPython."""
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
315 """ Aborting..."""
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
316 ),
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
317 )
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
318 else:
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
319 impInfo["version"] = versionInfo["release"]
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
320 if self.getDeviceType() == "bbc_microbit":
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
321 if "nRF51822" in versionInfo["machine"]:
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
322 url = QUrl(FirmwareGithubUrls["microbit_v1"])
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
323 elif "nRF52833" in versionInfo["machine"]:
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
324 url = QUrl(FirmwareGithubUrls["microbit_v2"])
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
325 else:
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
326 EricMessageBox.critical(
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
327 None,
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
328 self.tr("Show MicroPython Versions"),
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
329 self.tr(
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
330 """<p>The BBC micro:bit generation cannot be"""
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
331 """ determined. Aborting...</p>"""
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
332 ),
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
333 )
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
334 return
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
335 else:
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
336 EricMessageBox.critical(
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
337 None,
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
338 self.tr("Show MicroPython Versions"),
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
339 self.tr(
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
340 """<p>The firmware URL for the device type <b>{0}</b>"""
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
341 """ is not known. Aborting...</p>"""
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
342 ).format(self.getDeviceType()),
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
343 )
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
344 return
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
345
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
346 ui = ericApp().getObject("UserInterface")
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
347 request = QNetworkRequest(url)
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
348 reply = ui.networkAccessManager().head(request)
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
349 reply.finished.connect(
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
350 lambda: self.__firmwareVersionResponse(reply, impInfo)
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
351 )
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
352
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
353 def __firmwareVersionResponse(self, reply, implementation):
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
354 """
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
355 Private method handling the response of the latest version request.
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
356
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
357 @param reply reference to the reply object
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
358 @type QNetworkReply
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
359 @param implementation dictionary containing the implementation data of the
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
360 connected device
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
361 @type dict
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
362 """
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
363 latestUrl = reply.url().toString()
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
364 tag = latestUrl.rsplit("/", 1)[-1]
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
365 while tag and not tag[0].isdecimal():
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
366 # get rid of leading non-decimal characters
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
367 tag = tag[1:]
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
368 latestVersion = Globals.versionToTuple(tag)
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
369
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
370 if implementation["version"] == "unknown":
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
371 currentVersionStr = self.tr("unknown")
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
372 currentVersion = (0, 0, 0)
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
373 else:
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
374 currentVersionStr = implementation["version"]
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
375 currentVersion = Globals.versionToTuple(currentVersionStr)
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
376
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
377 msg = self.tr(
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
378 "<h4>MicroPython Version Information<br/>"
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
379 "(BBC micro:bit v{2})</h4>"
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
380 "<table>"
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
381 "<tr><td>Installed:</td><td>{0}</td></tr>"
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
382 "<tr><td>Available:</td><td>{1}</td></tr>"
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
383 "</table>"
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
384 ).format(currentVersionStr, tag, currentVersionStr[0])
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
385 if currentVersion < latestVersion:
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
386 msg += self.tr("<p><b>Update available!</b></p>")
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
387
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
388 EricMessageBox.information(
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
389 None,
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
390 self.tr("MicroPython Version"),
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
391 msg,
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
392 )
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
393
5d409223cf3f MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9738
diff changeset
394 @pyqtSlot()
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
395 def __saveMain(self):
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
396 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
397 Private slot to copy the current script as 'main.py' onto the
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
398 connected device.
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
399 """
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
400 self.__saveScriptToDevice("main.py")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
401
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
402 @pyqtSlot()
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
403 def __saveScriptToDevice(self, scriptName=""):
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
404 """
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
405 Private method to save the current script onto the connected
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
406 device.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
407
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
408 @param scriptName name of the file on the device
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
409 @type str
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
410 """
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
411 aw = ericApp().getObject("ViewManager").activeWindow()
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
412 if not aw:
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
413 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
414
8259
2bbec88047dd Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
415 title = (
2bbec88047dd Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
416 self.tr("Save Script as '{0}'").format(scriptName)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
417 if scriptName
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
418 else self.tr("Save Script")
8259
2bbec88047dd Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
419 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
420
7186
ccd55666e9d2 Utilities, MicrobitDevices: added MicroPython to the known Python Variants.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7173
diff changeset
421 if not (aw.isPyFile() or aw.isMicroPythonFile()):
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
422 yes = EricMessageBox.yesNo(
7173
f611c3b7313f EspDevices, MicrobitDevices: fixed a few omissions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7161
diff changeset
423 self.microPython,
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
424 title,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
425 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
426 """The current editor does not contain a Python"""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
427 """ script. Write it anyway?"""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
428 ),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
429 )
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
430 if not yes:
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
431 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
432
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
433 script = aw.text().strip()
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
434 if not script:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
435 EricMessageBox.warning(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
436 self.microPython, title, self.tr("""The script is empty. Aborting.""")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
437 )
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
438 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
439
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
440 if not scriptName:
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
441 scriptName = os.path.basename(aw.getFileName())
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
442 scriptName, ok = QInputDialog.getText(
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
443 self.microPython,
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
444 title,
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
445 self.tr("Enter a file name on the device:"),
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8117
diff changeset
446 QLineEdit.EchoMode.Normal,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
447 scriptName,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
448 )
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
449 if not ok or not bool(scriptName):
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
450 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
451
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
452 title = self.tr("Save Script as '{0}'").format(scriptName)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
453
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
454 commands = [
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
455 "fd = open('{0}', 'wb')".format(scriptName),
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
456 "f = fd.write",
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
457 ]
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
458 for line in script.splitlines():
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
459 commands.append("f(" + repr(line + "\n") + ")")
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
460 commands.append("fd.close()")
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
461 out, err = self.microPython.commandsInterface().execute(commands)
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
462 if err:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
463 EricMessageBox.critical(
7173
f611c3b7313f EspDevices, MicrobitDevices: fixed a few omissions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7161
diff changeset
464 self.microPython,
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
465 title,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
466 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
467 """<p>The script could not be saved to the"""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
468 """ device.</p><p>Reason: {0}</p>"""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
469 ).format(err.decode("utf-8")),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
470 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
471
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
472 # reset the device
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
473 self.__resetDevice()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
474
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
475 @pyqtSlot()
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
476 def __resetDevice(self):
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
477 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
478 Private slot to reset the connected device.
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
479 """
8117
aaa5e0eacd4e MicroPython: changed the logic to synchronize the time because some devices don't implement long integer and failed defining the 'set_time()' function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8096
diff changeset
480 if self.getDeviceType() == "bbc_microbit":
7551
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
481 # BBC micro:bit
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
482 self.microPython.commandsInterface().execute(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
483 [
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
484 "import microbit",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
485 "microbit.reset()",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
486 ]
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
487 )
7551
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
488 else:
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
489 # Calliope mini
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
490 self.microPython.commandsInterface().execute(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
491 [
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
492 "import calliope_mini",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
493 "calliope_mini.reset()",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
494 ]
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
495 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
496
7161
728018c32b09 MicroPythonWidget: added actions to show the device documentation and to open the configuration page to the hamburger menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7134
diff changeset
497 def getDocumentationUrl(self):
728018c32b09 MicroPythonWidget: added actions to show the device documentation and to open the configuration page to the hamburger menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7134
diff changeset
498 """
728018c32b09 MicroPythonWidget: added actions to show the device documentation and to open the configuration page to the hamburger menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7134
diff changeset
499 Public method to get the device documentation URL.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
500
7161
728018c32b09 MicroPythonWidget: added actions to show the device documentation and to open the configuration page to the hamburger menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7134
diff changeset
501 @return documentation URL of the device
728018c32b09 MicroPythonWidget: added actions to show the device documentation and to open the configuration page to the hamburger menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7134
diff changeset
502 @rtype str
728018c32b09 MicroPythonWidget: added actions to show the device documentation and to open the configuration page to the hamburger menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7134
diff changeset
503 """
8117
aaa5e0eacd4e MicroPython: changed the logic to synchronize the time because some devices don't implement long integer and failed defining the 'set_time()' function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8096
diff changeset
504 if self.getDeviceType() == "bbc_microbit":
7549
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
505 # BBC micro:bit
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
506 return Preferences.getMicroPython("MicrobitDocuUrl")
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
507 else:
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
508 # Calliope mini
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
509 return Preferences.getMicroPython("CalliopeDocuUrl")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
510
8051
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
511 def getDownloadMenuEntries(self):
7328
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
512 """
8051
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
513 Public method to retrieve the entries for the downloads menu.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
514
8051
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
515 @return list of tuples with menu text and URL to be opened for each
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
516 entry
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
517 @rtype list of tuple of (str, str)
7328
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
518 """
8117
aaa5e0eacd4e MicroPython: changed the logic to synchronize the time because some devices don't implement long integer and failed defining the 'set_time()' function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8096
diff changeset
519 if self.getDeviceType() == "bbc_microbit":
8051
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
520 return [
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
521 (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
522 self.tr("MicroPython Firmware for BBC micro:bit V1"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
523 Preferences.getMicroPython("MicrobitMicroPythonUrl"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
524 ),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
525 (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
526 self.tr("MicroPython Firmware for BBC micro:bit V2"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
527 Preferences.getMicroPython("MicrobitV2MicroPythonUrl"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
528 ),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
529 (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
530 self.tr("DAPLink Firmware"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
531 Preferences.getMicroPython("MicrobitFirmwareUrl"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
532 ),
8051
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
533 ]
7549
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
534 else:
8051
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
535 return [
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
536 (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
537 self.tr("MicroPython Firmware"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
538 Preferences.getMicroPython("CalliopeMicroPythonUrl"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
539 ),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
540 (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
541 self.tr("DAPLink Firmware"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
542 Preferences.getMicroPython("CalliopeDAPLinkUrl"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
543 ),
8051
b78279548993 MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8038
diff changeset
544 ]
9496
05017f795c24 Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
545
05017f795c24 Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
546
9738
4ae976ee5339 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
547 def createDevice(microPythonWidget, deviceType, vid, pid, boardName):
9496
05017f795c24 Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
548 """
05017f795c24 Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
549 Function to instantiate a MicroPython device object.
05017f795c24 Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
550
05017f795c24 Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
551 @param microPythonWidget reference to the main MicroPython widget
05017f795c24 Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
552 @type MicroPythonWidget
05017f795c24 Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
553 @param deviceType device type assigned to this device interface
05017f795c24 Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
554 @type str
05017f795c24 Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
555 @param vid vendor ID
05017f795c24 Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
556 @type int
05017f795c24 Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
557 @param pid product ID
05017f795c24 Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
558 @type int
9738
4ae976ee5339 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
559 @param boardName name of the board
4ae976ee5339 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
560 @type str
9496
05017f795c24 Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
561 @return reference to the instantiated device object
05017f795c24 Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
562 @rtype MicrobitDevice
05017f795c24 Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
563 """
05017f795c24 Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
564 return MicrobitDevice(microPythonWidget, deviceType)

eric ide

mercurial