Mon, 01 Feb 2021 20:01:18 +0100
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
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 | |
7923
91e843545d9a
Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7780
diff
changeset
|
3 | # Copyright (c) 2019 - 2021 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 | |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
14 | from PyQt5.QtCore import pyqtSlot, QStandardPaths |
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
|
15 | from PyQt5.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
|
16 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | from .MicroPythonDevices import MicroPythonDevice |
7134
21d23ca51680
Renamed "MicroPythonReplWidget" to "MicroPythonWidget".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
18 | from .MicroPythonWidget import HAS_QTCHART |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
20 | from E5Gui import E5MessageBox, E5FileDialog |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
21 | from E5Gui.E5Application import e5App |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
22 | |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
23 | import Utilities |
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
|
24 | import Preferences |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
25 | |
7059
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 | """ |
7549
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
31 | def __init__(self, microPythonWidget, deviceType, parent=None): |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | Constructor |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | @param microPythonWidget reference to the main MicroPython widget |
7134
21d23ca51680
Renamed "MicroPythonReplWidget" to "MicroPythonWidget".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
36 | @type MicroPythonWidget |
7549
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
37 | @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
|
38 | @type str |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | @param parent reference to the parent object |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | @type QObject |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | super(MicrobitDevice, self).__init__(microPythonWidget, parent) |
7549
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
43 | |
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
44 | self.__deviceType = deviceType |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | def setButtons(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | Public method to enable the supported action buttons. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | super(MicrobitDevice, self).setButtons() |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | self.microPython.setActionButtons( |
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
|
52 | run=True, repl=True, files=True, chart=HAS_QTCHART) |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | |
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. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | |
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 |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
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. |
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
|
67 | |
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 | """ |
7551
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
71 | if self.__deviceType == "bbc_microbit": |
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") |
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
|
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. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | |
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, "" |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | |
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. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | |
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, "" |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
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. |
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
|
101 | |
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, "" |
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
|
107 | |
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. |
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
|
111 | |
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) |
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
|
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. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | |
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, "" |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
127 | |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
128 | def getWorkspace(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 get the workspace directory. |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
131 | |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
132 | @return workspace directory used for saving files |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
133 | @rtype str |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
134 | """ |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
135 | # Attempts to find the path on the filesystem that represents the |
7551
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
136 | # plugged in MICROBIT or MINI board. |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
137 | if self.__deviceType == "bbc_microbit": |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
138 | # BBC micro:bit |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
139 | deviceDirectory = Utilities.findVolume("MICROBIT") |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
140 | else: |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
141 | # Calliope mini |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
142 | deviceDirectory = Utilities.findVolume("MINI") |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
143 | |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
144 | if deviceDirectory: |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
145 | return deviceDirectory |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
146 | else: |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
147 | # return the default workspace and give the user a warning |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
148 | E5MessageBox.warning( |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
149 | self.microPython, |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
150 | self.tr("Workspace Directory"), |
7551
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
151 | self.tr("Could not find an attached {0}.\n\n" |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
152 | "Please make sure the device is plugged " |
7551
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
153 | "into this computer.").format(self.deviceName())) |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
154 | |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
155 | return super(MicrobitDevice, self).getWorkspace() |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
156 | |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
157 | def hasTimeCommands(self): |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
158 | """ |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
159 | Public method to check, if the device supports time commands. |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
160 | |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
161 | The default returns True. |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
162 | |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
163 | @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
|
164 | @rtype bool |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
165 | """ |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
166 | return False |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
167 | |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
168 | def addDeviceMenuEntries(self, menu): |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
169 | """ |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
170 | Public method to add device specific entries to the given menu. |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
171 | |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
172 | @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
|
173 | @type QMenu |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
174 | """ |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
175 | connected = self.microPython.isConnected() |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
176 | |
8032
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
177 | act = menu.addAction(self.tr("Flash MicroPython"), |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
178 | self.__flashMicroPython) |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
179 | act.setEnabled(not connected) |
8032
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
180 | act = menu.addAction(self.tr("Flash Firmware"), |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
181 | lambda: self.__flashMicroPython(firmware=True)) |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
182 | act.setEnabled(not connected) |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
183 | 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
|
184 | act = menu.addAction(self.tr("Save Script"), self.__saveScriptToDevice) |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
185 | act.setToolTip(self.tr( |
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
|
186 | "Save the current script to the selected 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
|
187 | act.setEnabled(connected) |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
188 | act = menu.addAction(self.tr("Save Script as 'main.py'"), |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
189 | self.__saveMain) |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
190 | act.setToolTip(self.tr( |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
191 | "Save the current script as 'main.py' on the connected device")) |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
192 | act.setEnabled(connected) |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
193 | menu.addSeparator() |
7552
b62e73df71dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7551
diff
changeset
|
194 | act = menu.addAction(self.tr("Reset {0}").format(self.deviceName()), |
b62e73df71dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7551
diff
changeset
|
195 | self.__resetDevice) |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
196 | act.setEnabled(connected) |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
197 | |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
198 | @pyqtSlot() |
8032
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
199 | 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
|
200 | """ |
8032
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
201 | 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
|
202 | device. |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
203 | |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
204 | @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
|
205 | @type bool |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
206 | """ |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
207 | # 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
|
208 | # 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
|
209 | # in maintenance mode, for MicroPython in standard mode. |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
210 | # The Calliope mini board must be in standard mode. |
7552
b62e73df71dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7551
diff
changeset
|
211 | if self.__deviceType == "bbc_microbit": |
b62e73df71dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7551
diff
changeset
|
212 | # 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
|
213 | if firmware: |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
214 | deviceDirectory = Utilities.findVolume("MAINTENANCE") |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
215 | else: |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
216 | deviceDirectory = Utilities.findVolume("MICROBIT") |
7552
b62e73df71dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7551
diff
changeset
|
217 | else: |
b62e73df71dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7551
diff
changeset
|
218 | # 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
|
219 | if 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
|
220 | deviceDirectory = Utilities.findVolume("MAINTENANCE") |
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
|
221 | else: |
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
|
222 | deviceDirectory = Utilities.findVolume("MINI") |
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
|
223 | if not deviceDirectory: |
7551
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
224 | if self.__deviceType == "bbc_microbit": |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
225 | # 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
|
226 | if firmware: |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
227 | E5MessageBox.critical( |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
228 | self.microPython, |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
229 | 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
|
230 | self.tr( |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
231 | '<p>The BBC micro:bit is not ready for flashing' |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
232 | ' the DAPLink firmware. Follow these' |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
233 | ' instructions. </p>' |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
234 | '<ul>' |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
235 | '<li>unplug USB cable and any batteries</li>' |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
236 | '<li>keep RESET button pressed an plug USB cable' |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
237 | ' back in</li>' |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
238 | '<li>a drive called MAINTENANCE should be' |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
239 | ' available</li>' |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
240 | '</ul>' |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
241 | '<p>See the ' |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
242 | '<a href="https://microbit.org/guide/firmware/">' |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
243 | 'micro:bit web site</a> for details.</p>' |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
244 | ) |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
245 | ) |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
246 | else: |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
247 | E5MessageBox.critical( |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
248 | self.microPython, |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
249 | 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
|
250 | self.tr( |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
251 | '<p>The BBC micro:bit is not ready for flashing' |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
252 | ' the MicroPython firmware. Please make sure,' |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
253 | ' that a drive called MICROBIT is available.' |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
254 | '</p>' |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
255 | ) |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
256 | ) |
7551
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
257 | else: |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
258 | # 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
|
259 | if 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
|
260 | E5MessageBox.critical( |
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
|
261 | 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
|
262 | 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
|
263 | 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
|
264 | '<p>The "Calliope mini" is not ready for flashing' |
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
|
265 | ' the DAPLink firmware. Follow these' |
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 | ' instructions. </p>' |
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 | '<ul>' |
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 | '<li>unplug USB cable and any batteries</li>' |
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 | '<li>keep RESET button pressed an plug USB cable' |
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
|
270 | ' back in</li>' |
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
|
271 | '<li>a drive called MAINTENANCE should be' |
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
|
272 | ' available</li>' |
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
|
273 | '</ul>' |
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 | ) |
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
|
275 | ) |
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
|
276 | else: |
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
|
277 | E5MessageBox.critical( |
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
|
278 | 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
|
279 | 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
|
280 | 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
|
281 | '<p>The "Calliope mini" is not ready for flashing' |
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
|
282 | ' the MicroPython firmware. Please make sure,' |
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
|
283 | ' that a drive called MINI is available.' |
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
|
284 | '</p>' |
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
|
285 | ) |
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
|
286 | ) |
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
|
287 | else: |
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
|
288 | downloadsPath = QStandardPaths.standardLocations( |
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
|
289 | QStandardPaths.DownloadLocation)[0] |
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
|
290 | firmware = E5FileDialog.getOpenFileName( |
7173
f611c3b7313f
EspDevices, MicrobitDevices: fixed a few omissions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7161
diff
changeset
|
291 | 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
|
292 | 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
|
293 | downloadsPath, |
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
|
294 | self.tr("MicroPython/Firmware Files (*.hex *.bin);;" |
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
|
295 | "All Files (*)")) |
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
|
296 | if firmware and os.path.exists(firmware): |
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
|
297 | shutil.copy2(firmware, deviceDirectory) |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
298 | |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
299 | @pyqtSlot() |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
300 | def __saveMain(self): |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
301 | """ |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
302 | 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
|
303 | connected device. |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
304 | """ |
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
|
305 | self.__saveScriptToDevice("main.py") |
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
|
306 | |
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
|
307 | @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
|
308 | 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
|
309 | """ |
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
|
310 | 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
|
311 | 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
|
312 | |
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
|
313 | @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
|
314 | @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
|
315 | """ |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
316 | aw = e5App().getObject("ViewManager").activeWindow() |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
317 | if not aw: |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
318 | return |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
319 | |
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
|
320 | if 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
|
321 | title = self.tr("Save Script as '{0}'").format(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
|
322 | else: |
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
|
323 | title = self.tr("Save Script") |
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
|
324 | |
7186
ccd55666e9d2
Utilities, MicrobitDevices: added MicroPython to the known Python Variants.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7173
diff
changeset
|
325 | if not (aw.isPyFile() or aw.isMicroPythonFile()): |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
326 | yes = E5MessageBox.yesNo( |
7173
f611c3b7313f
EspDevices, MicrobitDevices: fixed a few omissions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7161
diff
changeset
|
327 | 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
|
328 | title, |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
329 | self.tr("""The current editor does not contain a Python""" |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
330 | """ script. Write it anyway?""")) |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
331 | if not yes: |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
332 | return |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
333 | |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
334 | script = aw.text().strip() |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
335 | if not script: |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
336 | E5MessageBox.warning( |
7173
f611c3b7313f
EspDevices, MicrobitDevices: fixed a few omissions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7161
diff
changeset
|
337 | 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
|
338 | title, |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
339 | self.tr("""The script is empty. Aborting.""")) |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
340 | return |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
341 | |
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
|
342 | 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
|
343 | 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
|
344 | 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
|
345 | 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
|
346 | 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
|
347 | self.tr("Enter a file name 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
|
348 | QLineEdit.Normal, |
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
|
349 | 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
|
350 | 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
|
351 | return |
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
|
352 | |
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
|
353 | title = self.tr("Save Script as '{0}'").format(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
|
354 | |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
355 | 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
|
356 | "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
|
357 | "f = fd.write", |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
358 | ] |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
359 | 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
|
360 | 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
|
361 | commands.append("fd.close()") |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
362 | 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
|
363 | if err: |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
364 | E5MessageBox.critical( |
7173
f611c3b7313f
EspDevices, MicrobitDevices: fixed a few omissions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7161
diff
changeset
|
365 | 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
|
366 | title, |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
367 | self.tr("""<p>The script could not be saved to the""" |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
368 | """ device.</p><p>Reason: {0}</p>""") |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
369 | .format(err.decode("utf-8"))) |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
370 | |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
371 | # 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
|
372 | self.__resetDevice() |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
373 | |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
374 | @pyqtSlot() |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
375 | def __resetDevice(self): |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
376 | """ |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
377 | 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
|
378 | """ |
7551
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
379 | if self.__deviceType == "bbc_microbit": |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
380 | # BBC micro:bit |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
381 | self.microPython.commandsInterface().execute([ |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
382 | "import microbit", |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
383 | "microbit.reset()", |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
384 | ]) |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
385 | else: |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
386 | # Calliope mini |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
387 | self.microPython.commandsInterface().execute([ |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
388 | "import calliope_mini", |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
389 | "calliope_mini.reset()", |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
390 | ]) |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
391 | |
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
|
392 | 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
|
393 | """ |
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
|
394 | Public method to get the device documentation URL. |
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
|
395 | |
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
|
396 | @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
|
397 | @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
|
398 | """ |
7549
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
399 | if self.__deviceType == "bbc_microbit": |
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
400 | # BBC micro:bit |
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
401 | return Preferences.getMicroPython("MicrobitDocuUrl") |
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
402 | else: |
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
403 | # Calliope mini |
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
404 | return Preferences.getMicroPython("CalliopeDocuUrl") |
7328 | 405 | |
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
|
406 | def getDownloadMenuEntries(self): |
7328 | 407 | """ |
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
|
408 | Public method to retrieve the entries for the downloads menu. |
7328 | 409 | |
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
|
410 | @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
|
411 | 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
|
412 | @rtype list of tuple of (str, str) |
7328 | 413 | """ |
7549
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
414 | if self.__deviceType == "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
|
415 | return [ |
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
|
416 | (self.tr("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
|
417 | Preferences.getMicroPython("MicrobitMicroPythonUrl")), |
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
|
418 | (self.tr("DAPLink 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
|
419 | Preferences.getMicroPython("MicrobitFirmwareUrl")) |
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
|
420 | ] |
7549
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
421 | 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
|
422 | return [ |
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
|
423 | (self.tr("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
|
424 | Preferences.getMicroPython("CalliopeMicroPythonUrl")), |
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
|
425 | (self.tr("DAPLink 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
|
426 | Preferences.getMicroPython("CalliopeDAPLinkUrl")) |
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
|
427 | ] |