eric6/MicroPython/MicrobitDevices.py

Tue, 21 Apr 2020 19:52:43 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 21 Apr 2020 19:52:43 +0200
changeset 7548
e1c6a2e32a38
parent 7360
9190402e4505
child 7549
fcfbb9e94471
permissions
-rw-r--r--

MicroPython: started implementing support for the "Calliope mini".

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
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7328
diff changeset
3 # Copyright (c) 2019 - 2020 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 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the device interface class for BBC micro:bit boards.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
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
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
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 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 Class implementing the device for BBC micro:bit boards.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 def __init__(self, microPythonWidget, parent=None):
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
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 @param parent reference to the parent object
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @type QObject
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 super(MicrobitDevice, self).__init__(microPythonWidget, parent)
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 def setButtons(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 Public method to enable the supported action buttons.
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 super(MicrobitDevice, self).setButtons()
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 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
48 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
49
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 def forceInterrupt(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 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
53 serial connection.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 @return flag indicating an interrupt is needed
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 @rtype bool
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 return True
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
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
60 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
61 """
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
62 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
63
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 @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
65 @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
66 """
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 return self.tr("BBC micro:bit")
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
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 def canStartRepl(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 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
72
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 @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
74 and a reason why it cannot.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 @rtype tuple of (bool, str)
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 """
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
77 return True, ""
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 def canStartPlotter(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 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
82
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 @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
84 Plotter and a reason why it cannot.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 @rtype tuple of (bool, str)
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 """
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
87 return True, ""
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88
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
89 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
90 """
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
91 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
92
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
93 @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
94 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
95 @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
96 """
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
97 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
98
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 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
100 """
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 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
102
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 @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
104 @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
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 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
107 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
108
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 def canStartFileManager(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 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
112
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 @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
114 File Manager and a reason why it cannot.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 @rtype tuple of (bool, str)
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 """
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
117 return True, ""
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
118
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
119 def getWorkspace(self):
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
120 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
121 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
122
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
123 @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
124 @rtype str
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
125 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
126 # Attempts to find the path on the filesystem that represents the
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
127 # plugged in MICROBIT board.
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
128 deviceDirectory = Utilities.findVolume("MICROBIT")
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 if deviceDirectory:
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
131 return deviceDirectory
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
132 else:
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
133 # 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
134 E5MessageBox.warning(
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
135 self.microPython,
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
136 self.tr("Workspace Directory"),
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
137 self.tr("Could not find an attached BBC micro:bit.\n\n"
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
138 "Please make sure the device is plugged "
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
139 "into this computer."))
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 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
142
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
143 def hasTimeCommands(self):
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
144 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
145 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
146
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
147 The default returns True.
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
148
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
149 @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
150 @rtype bool
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
151 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
152 return False
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
153
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
154 def addDeviceMenuEntries(self, menu):
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
155 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
156 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
157
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
158 @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
159 @type QMenu
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 connected = self.microPython.isConnected()
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
162
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
163 act = menu.addAction(self.tr("Flash MicroPython Firmware"),
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
164 self.__flashMicroPython)
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
165 act.setEnabled(not connected)
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
166 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
167 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
168 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
169 "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
170 act.setEnabled(connected)
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
171 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
172 self.__saveMain)
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
173 act.setToolTip(self.tr(
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
174 "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
175 act.setEnabled(connected)
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
176 menu.addSeparator()
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
177 act = menu.addAction(self.tr("Reset micro:bit"), self.__resetDevice)
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
178 act.setEnabled(connected)
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
179
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
180 @pyqtSlot()
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
181 def __flashMicroPython(self):
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
182 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
183 Private slot to flash the default MicroPython firmware to the device.
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
184 """
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
185 # Attempts to find the path on the filesystem that represents the
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 # plugged in micro:bit board in maintenance mode.
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 deviceDirectory = Utilities.findVolume("MAINTENANCE")
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
188 if not deviceDirectory:
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
189 # BBC micro:bit is not ready or not mounted
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
190 E5MessageBox.critical(
7173
f611c3b7313f EspDevices, MicrobitDevices: fixed a few omissions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7161
diff changeset
191 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
192 self.tr("Flash MicroPython 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
193 self.tr(
7548
e1c6a2e32a38 MicroPython: started implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
194 '<p>The BBC micro:bit is not ready for flashing. Follow'
e1c6a2e32a38 MicroPython: started implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
195 ' these instructions.</p>'
e1c6a2e32a38 MicroPython: started implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
196 '<ul>'
e1c6a2e32a38 MicroPython: started implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
197 '<li>unplug USB cable and any batteries</li>'
e1c6a2e32a38 MicroPython: started implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
198 '<li>keep RESET pressed an plug USB cable back in</li>'
e1c6a2e32a38 MicroPython: started implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
199 '<li>a drive called MAINTENANCE should be available</li>'
e1c6a2e32a38 MicroPython: started implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
200 '</ul>'
e1c6a2e32a38 MicroPython: started implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
201 '<p>See the '
e1c6a2e32a38 MicroPython: started implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
202 '<a href="https://microbit.org/guide/firmware/">'
e1c6a2e32a38 MicroPython: started implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
203 'micro:bit web site</a> for details.</p>'
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
204 ))
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
205 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
206 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
207 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
208 firmware = E5FileDialog.getOpenFileName(
7173
f611c3b7313f EspDevices, MicrobitDevices: fixed a few omissions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7161
diff changeset
209 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
210 self.tr("Flash MicroPython 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
211 downloadsPath,
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
212 self.tr("MicroPython Firmware Files (*.hex);;All Files (*)"))
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
213 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
214 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
215
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
216 @pyqtSlot()
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
217 def __saveMain(self):
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
218 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
219 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
220 connected device.
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
221 """
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
222 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
223
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
224 @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
225 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
226 """
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
227 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
228 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
229
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
230 @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
231 @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
232 """
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
233 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
234 if not aw:
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
235 return
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
236
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
237 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
238 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
239 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
240 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
241
7186
ccd55666e9d2 Utilities, MicrobitDevices: added MicroPython to the known Python Variants.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7173
diff changeset
242 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
243 yes = E5MessageBox.yesNo(
7173
f611c3b7313f EspDevices, MicrobitDevices: fixed a few omissions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7161
diff changeset
244 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
245 title,
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
246 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
247 """ script. Write it anyway?"""))
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
248 if not yes:
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
249 return
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
250
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
251 script = aw.text().strip()
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
252 if not script:
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
253 E5MessageBox.warning(
7173
f611c3b7313f EspDevices, MicrobitDevices: fixed a few omissions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7161
diff changeset
254 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
255 title,
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
256 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
257 return
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
258
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
259 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
260 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
261 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
262 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
263 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
264 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
265 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
266 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
267 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
268 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
269
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
270 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
271
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
272 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
273 "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
274 "f = fd.write",
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
275 ]
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
276 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
277 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
278 commands.append("fd.close()")
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
279 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
280 if err:
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
281 E5MessageBox.critical(
7173
f611c3b7313f EspDevices, MicrobitDevices: fixed a few omissions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7161
diff changeset
282 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
283 title,
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
284 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
285 """ 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
286 .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
287
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
288 # 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
289 self.__resetDevice()
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
290
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
291 @pyqtSlot()
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
292 def __resetDevice(self):
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
293 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
294 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
295 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
296 self.microPython.commandsInterface().execute([
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
297 "import microbit",
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
298 "microbit.reset()",
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
299 ])
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
300
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
301 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
302 """
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
303 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
304
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
305 @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
306 @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
307 """
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
308 return Preferences.getMicroPython("MicrobitDocuUrl")
7328
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
309
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
310 def getFirmwareUrl(self):
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
311 """
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
312 Public method to get the device firmware download URL.
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
313
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
314 @return firmware download URL of the device
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
315 @rtype str
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
316 """
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
317 return Preferences.getMicroPython("MicrobitFirmwareUrl")

eric ide

mercurial