Mon, 06 Feb 2023 10:09:18 +0100
MicroPython
- Added functionality to update modules of CircuitPython devices with `circup`
(adapted for use within eric-ide).
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
9653
e67609152c5e
Updated copyright for 2023.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9624
diff
changeset
|
3 | # Copyright (c) 2019 - 2023 Detlev Offenbach <detlev@die-offenbachs.de> |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing the device interface class for CircuitPython 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 | |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
10 | import os |
7116
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
11 | import shutil |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
12 | |
8318
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
13 | from PyQt6.QtCore import pyqtSlot |
9738 | 14 | from PyQt6.QtWidgets import QMenu |
7116
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
15 | |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9496
diff
changeset
|
16 | from eric7 import Preferences |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
17 | from eric7.EricWidgets import EricFileDialog, EricMessageBox |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9496
diff
changeset
|
18 | from eric7.SystemUtilities import FileSystemUtilities |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | |
9740 | 20 | from .CircuitPythonUpdater.CircuitPythonUpdaterInterface import ( |
21 | CircuitPythonUpdaterInterface, | |
22 | isCircupAvailable, | |
23 | ) | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | from .MicroPythonDevices import MicroPythonDevice |
7134
21d23ca51680
Renamed "MicroPythonReplWidget" to "MicroPythonWidget".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7132
diff
changeset
|
25 | from .MicroPythonWidget import HAS_QTCHART |
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 | |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | class CircuitPythonDevice(MicroPythonDevice): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | Class implementing the device for CircuitPython boards. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
32 | |
7132
c4682cfcd160
CircuitPythonDevice: only report local access if the well known volume is mounted.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7129
diff
changeset
|
33 | DeviceVolumeName = "CIRCUITPY" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
34 | |
9738 | 35 | def __init__(self, microPythonWidget, deviceType, boardName, parent=None): |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
38 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | @param microPythonWidget reference to the main MicroPython widget |
7134
21d23ca51680
Renamed "MicroPythonReplWidget" to "MicroPythonWidget".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7132
diff
changeset
|
40 | @type MicroPythonWidget |
8117
aaa5e0eacd4e
MicroPython: changed the logic to synchronize the time because some devices don't implement long integer and failed defining the 'set_time()' function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8096
diff
changeset
|
41 | @param deviceType device type assigned to this device interface |
aaa5e0eacd4e
MicroPython: changed the logic to synchronize the time because some devices don't implement long integer and failed defining the 'set_time()' function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8096
diff
changeset
|
42 | @type str |
9738 | 43 | @param boardName name of the board |
44 | @type str | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | @param parent reference to the parent object |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | @type QObject |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
48 | super().__init__(microPythonWidget, deviceType, parent) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
49 | |
9738 | 50 | self.__boardName = boardName |
8062
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
51 | self.__workspace = self.__findWorkspace() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
52 | |
9740 | 53 | self.__updater = CircuitPythonUpdaterInterface(self) |
54 | ||
8072
58491f4c99d6
MicroPython: added code to give a hint for CircuitPython devices, that do not support the UF2 bootloader for flashing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
55 | self.__nonUF2devices = { |
58491f4c99d6
MicroPython: added code to give a hint for CircuitPython devices, that do not support the UF2 bootloader for flashing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
56 | "teensy": self.__flashTeensy, |
58491f4c99d6
MicroPython: added code to give a hint for CircuitPython devices, that do not support the UF2 bootloader for flashing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
57 | } |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
58 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | def setButtons(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | Public method to enable the supported action buttons. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | """ |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8117
diff
changeset
|
63 | super().setButtons() |
7100
c4d9c28ebcd8
Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7092
diff
changeset
|
64 | self.microPython.setActionButtons( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
65 | run=True, repl=True, files=True, chart=HAS_QTCHART |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
66 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
67 | |
7132
c4682cfcd160
CircuitPythonDevice: only report local access if the well known volume is mounted.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7129
diff
changeset
|
68 | if self.__deviceVolumeMounted(): |
7092
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
69 | self.microPython.setActionButtons(open=True, save=True) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
70 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | def forceInterrupt(self): |
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 | 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
|
74 | serial connection. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
75 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | @return flag indicating an interrupt is needed |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | @rtype bool |
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 | return False |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
80 | |
7125
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7122
diff
changeset
|
81 | def deviceName(self): |
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7122
diff
changeset
|
82 | """ |
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7122
diff
changeset
|
83 | Public method to get the name of the device. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
84 | |
7125
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7122
diff
changeset
|
85 | @return name of the device |
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7122
diff
changeset
|
86 | @rtype str |
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7122
diff
changeset
|
87 | """ |
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7122
diff
changeset
|
88 | return self.tr("CircuitPython") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
89 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | def canStartRepl(self): |
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 | Public method to determine, if a REPL can be started. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
93 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | @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
|
95 | and a reason why it cannot. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | @rtype tuple of (bool, str) |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | return True, "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
99 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | def canStartPlotter(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
101 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | Public method to determine, if a Plotter can be started. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
103 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | @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
|
105 | Plotter and a reason why it cannot. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | @rtype tuple of (bool, str) |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | return True, "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
109 | |
7092
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
110 | def canRunScript(self): |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
111 | """ |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
112 | Public method to determine, if a script can be executed. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
113 | |
7092
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
114 | @return tuple containing a flag indicating it is safe to start a |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
115 | Plotter and a reason why it cannot. |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
116 | @rtype tuple of (bool, str) |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
117 | """ |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
118 | return True, "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
119 | |
7092
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
120 | def runScript(self, script): |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
121 | """ |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
122 | Public method to run the given Python script. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
123 | |
7092
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
124 | @param script script to be executed |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
125 | @type str |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
126 | """ |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
127 | pythonScript = script.split("\n") |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
128 | self.sendCommands(pythonScript) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
129 | |
7100
c4d9c28ebcd8
Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7092
diff
changeset
|
130 | def canStartFileManager(self): |
c4d9c28ebcd8
Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7092
diff
changeset
|
131 | """ |
c4d9c28ebcd8
Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7092
diff
changeset
|
132 | Public method to determine, if a File Manager can be started. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
133 | |
7100
c4d9c28ebcd8
Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7092
diff
changeset
|
134 | @return tuple containing a flag indicating it is safe to start a |
c4d9c28ebcd8
Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7092
diff
changeset
|
135 | File Manager and a reason why it cannot. |
c4d9c28ebcd8
Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7092
diff
changeset
|
136 | @rtype tuple of (bool, str) |
c4d9c28ebcd8
Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7092
diff
changeset
|
137 | """ |
c4d9c28ebcd8
Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7092
diff
changeset
|
138 | return True, "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
139 | |
7129
3cc19aec959a
MicroPythonDevicces: added a method to indicate that a device allows access to its file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7125
diff
changeset
|
140 | def supportsLocalFileAccess(self): |
3cc19aec959a
MicroPythonDevicces: added a method to indicate that a device allows access to its file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7125
diff
changeset
|
141 | """ |
3cc19aec959a
MicroPythonDevicces: added a method to indicate that a device allows access to its file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7125
diff
changeset
|
142 | Public method to indicate file access via a local directory. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
143 | |
7129
3cc19aec959a
MicroPythonDevicces: added a method to indicate that a device allows access to its file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7125
diff
changeset
|
144 | @return flag indicating file access via local directory |
7145
ceb3e8b242c1
Regenerated source docu after merge with 'micropython' branch.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7138
diff
changeset
|
145 | @rtype bool |
7129
3cc19aec959a
MicroPythonDevicces: added a method to indicate that a device allows access to its file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7125
diff
changeset
|
146 | """ |
7132
c4682cfcd160
CircuitPythonDevice: only report local access if the well known volume is mounted.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7129
diff
changeset
|
147 | return self.__deviceVolumeMounted() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
148 | |
7132
c4682cfcd160
CircuitPythonDevice: only report local access if the well known volume is mounted.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7129
diff
changeset
|
149 | def __deviceVolumeMounted(self): |
c4682cfcd160
CircuitPythonDevice: only report local access if the well known volume is mounted.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7129
diff
changeset
|
150 | """ |
c4682cfcd160
CircuitPythonDevice: only report local access if the well known volume is mounted.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7129
diff
changeset
|
151 | Private method to check, if the device volume is mounted. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
152 | |
7132
c4682cfcd160
CircuitPythonDevice: only report local access if the well known volume is mounted.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7129
diff
changeset
|
153 | @return flag indicated a mounted device |
c4682cfcd160
CircuitPythonDevice: only report local access if the well known volume is mounted.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7129
diff
changeset
|
154 | @rtype bool |
c4682cfcd160
CircuitPythonDevice: only report local access if the well known volume is mounted.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7129
diff
changeset
|
155 | """ |
8072
58491f4c99d6
MicroPython: added code to give a hint for CircuitPython devices, that do not support the UF2 bootloader for flashing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
156 | if self.__workspace and not os.path.exists(self.__workspace): |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
157 | self.__workspace = "" # reset |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
158 | |
8062
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
159 | return self.DeviceVolumeName in self.getWorkspace(silent=True) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
160 | |
9738 | 161 | def __findDeviceDirectories(self, directories): |
162 | """ | |
163 | Private method to find the device directories associated with the | |
164 | current board name. | |
165 | ||
166 | @param directories list of directories to be checked | |
167 | @type list of str | |
168 | @return list of associated directories | |
169 | @rtype list of str | |
170 | """ | |
171 | boardDirectories = [] | |
172 | for directory in directories: | |
173 | bootFile = os.path.join(directory, "boot_out.txt") | |
174 | if os.path.exists(bootFile): | |
175 | with open(bootFile, "r") as f: | |
176 | line = f.readline() | |
177 | if self.__boardName in line: | |
178 | boardDirectories.append(directory) | |
179 | ||
180 | return boardDirectories | |
181 | ||
8062
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
182 | def __findWorkspace(self, silent=False): |
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
183 | """ |
8067
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8062
diff
changeset
|
184 | Private method to find the workspace directory. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
185 | |
8062
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
186 | @param silent flag indicating silent operations |
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
187 | @type bool |
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
188 | @return workspace directory used for saving files |
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
189 | @rtype str |
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
190 | """ |
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
191 | # Attempts to find the paths on the filesystem that represents the |
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
192 | # plugged in CIRCUITPY boards. |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9496
diff
changeset
|
193 | deviceDirectories = FileSystemUtilities.findVolume( |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9496
diff
changeset
|
194 | self.DeviceVolumeName, findAll=True |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9496
diff
changeset
|
195 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
196 | |
8062
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
197 | if deviceDirectories: |
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
198 | if len(deviceDirectories) == 1: |
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
199 | return deviceDirectories[0] |
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
200 | else: |
9738 | 201 | boardDirectories = self.__findDeviceDirectories(deviceDirectories) |
202 | if len(boardDirectories) == 1: | |
203 | return boardDirectories[0] | |
204 | elif len(boardDirectories) > 1: | |
205 | return self.selectDeviceDirectory(boardDirectories) | |
206 | else: | |
207 | return self.selectDeviceDirectory(deviceDirectories) | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
208 | else: |
7174
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7161
diff
changeset
|
209 | # return the default workspace and give the user a warning (unless |
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7161
diff
changeset
|
210 | # silent mode is selected) |
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7161
diff
changeset
|
211 | if not silent: |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
212 | EricMessageBox.warning( |
7174
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7161
diff
changeset
|
213 | self.microPython, |
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7161
diff
changeset
|
214 | self.tr("Workspace Directory"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
215 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
216 | "Python files for CircuitPython can be edited in" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
217 | " place, if the device volume is locally" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
218 | " available. Such a volume was not found. In" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
219 | " place editing will not be available." |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
220 | ), |
8067
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8062
diff
changeset
|
221 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
222 | |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8117
diff
changeset
|
223 | return super().getWorkspace() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
224 | |
9740 | 225 | def getWorkspace(self, silent=False): |
226 | """ | |
227 | Public method to get the workspace directory. | |
228 | ||
229 | @param silent flag indicating silent operations | |
230 | @type bool | |
231 | @return workspace directory used for saving files | |
232 | @rtype str | |
233 | """ | |
234 | if self.__workspace: | |
235 | # return cached entry | |
236 | return self.__workspace | |
237 | else: | |
238 | self.__workspace = self.__findWorkspace(silent=silent) | |
239 | return self.__workspace | |
240 | ||
7116
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
241 | def addDeviceMenuEntries(self, menu): |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
242 | """ |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
243 | Public method to add device specific entries to the given menu. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
244 | |
7116
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
245 | @param menu reference to the context menu |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
246 | @type QMenu |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
247 | """ |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
248 | connected = self.microPython.isConnected() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
249 | |
9738 | 250 | self.__libraryMenu = QMenu(self.tr("Library Management")) |
9740 | 251 | self.__libraryMenu.aboutToShow.connect(self.__aboutToShowLibraryMenu) |
252 | self.__libraryMenu.setTearOffEnabled(True) | |
9738 | 253 | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
254 | act = menu.addAction( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
255 | self.tr("Flash CircuitPython Firmware"), self.__flashCircuitPython |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
256 | ) |
7116
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
257 | act.setEnabled(not connected) |
7138
a2a53535d855
CircuitPythonDevices: added capability to install library files onto the device to the device menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
258 | menu.addSeparator() |
9738 | 259 | menu.addMenu(self.__libraryMenu) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
260 | |
9740 | 261 | @pyqtSlot() |
262 | def __aboutToShowLibraryMenu(self): | |
263 | """ | |
264 | Private slot to populate the 'Library Management' menu. | |
265 | """ | |
266 | self.__libraryMenu.clear() | |
267 | ||
268 | if isCircupAvailable(): | |
269 | self.__updater.populateMenu(self.__libraryMenu) | |
270 | else: | |
271 | act = self.__libraryMenu.addAction( | |
272 | self.tr("Install Library Files"), self.__installLibraryFiles | |
273 | ) | |
274 | act.setEnabled(self.__deviceVolumeMounted()) | |
275 | act = self.__libraryMenu.addAction( | |
276 | self.tr("Install Library Package"), | |
277 | lambda: self.__installLibraryFiles(packageMode=True), | |
278 | ) | |
279 | act.setEnabled(self.__deviceVolumeMounted()) | |
280 | self.__libraryMenu.addSeparator() | |
281 | self.__libraryMenu.addAction( | |
282 | self.tr("Install 'circup' Package"), | |
283 | self.__updater.installCircup, | |
284 | ) | |
285 | ||
8096 | 286 | def hasFlashMenuEntry(self): |
287 | """ | |
288 | Public method to check, if the device has its own flash menu entry. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
289 | |
8096 | 290 | @return flag indicating a specific flash menu entry |
291 | @rtype bool | |
292 | """ | |
293 | return True | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
294 | |
7116
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
295 | @pyqtSlot() |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
296 | def __flashCircuitPython(self): |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
297 | """ |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
298 | Private slot to flash a CircuitPython firmware to the device. |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
299 | """ |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
300 | from .UF2FlashDialog import UF2FlashDialog |
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
301 | |
8072
58491f4c99d6
MicroPython: added code to give a hint for CircuitPython devices, that do not support the UF2 bootloader for flashing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
302 | lBoardName = self.microPython.getCurrentBoard().lower() |
58491f4c99d6
MicroPython: added code to give a hint for CircuitPython devices, that do not support the UF2 bootloader for flashing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
303 | if lBoardName: |
58491f4c99d6
MicroPython: added code to give a hint for CircuitPython devices, that do not support the UF2 bootloader for flashing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
304 | for name in self.__nonUF2devices: |
58491f4c99d6
MicroPython: added code to give a hint for CircuitPython devices, that do not support the UF2 bootloader for flashing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
305 | if name in lBoardName: |
58491f4c99d6
MicroPython: added code to give a hint for CircuitPython devices, that do not support the UF2 bootloader for flashing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
306 | self.__nonUF2devices[name]() |
58491f4c99d6
MicroPython: added code to give a hint for CircuitPython devices, that do not support the UF2 bootloader for flashing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
307 | break |
58491f4c99d6
MicroPython: added code to give a hint for CircuitPython devices, that do not support the UF2 bootloader for flashing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
308 | else: |
8096 | 309 | dlg = UF2FlashDialog(boardType="circuitpython") |
310 | dlg.exec() | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
311 | |
8072
58491f4c99d6
MicroPython: added code to give a hint for CircuitPython devices, that do not support the UF2 bootloader for flashing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
312 | def __flashTeensy(self): |
58491f4c99d6
MicroPython: added code to give a hint for CircuitPython devices, that do not support the UF2 bootloader for flashing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
313 | """ |
58491f4c99d6
MicroPython: added code to give a hint for CircuitPython devices, that do not support the UF2 bootloader for flashing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
314 | Private method to show a message box because Teens does not support |
58491f4c99d6
MicroPython: added code to give a hint for CircuitPython devices, that do not support the UF2 bootloader for flashing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
315 | the UF2 bootloader yet. |
58491f4c99d6
MicroPython: added code to give a hint for CircuitPython devices, that do not support the UF2 bootloader for flashing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
316 | """ |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
317 | EricMessageBox.information( |
7116
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
318 | self.microPython, |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
319 | self.tr("Flash CircuitPython Firmware"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
320 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
321 | """<p>Teensy 4.0 and Teensy 4.1 do not support the UF2""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
322 | """ bootloader. Please use the 'Teensy Loader'""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
323 | """ application to flash CircuitPython. Make sure you""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
324 | """ downloaded the CircuitPython .hex file.</p>""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
325 | """<p>See <a href="{0}">the PJRC Teensy web site</a>""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
326 | """ for details.</p>""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
327 | ).format("https://www.pjrc.com/teensy/loader.html"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
328 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
329 | |
7138
a2a53535d855
CircuitPythonDevices: added capability to install library files onto the device to the device menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
330 | @pyqtSlot() |
9738 | 331 | def __installLibraryFiles(self, packageMode=False): |
7138
a2a53535d855
CircuitPythonDevices: added capability to install library files onto the device to the device menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
332 | """ |
a2a53535d855
CircuitPythonDevices: added capability to install library files onto the device to the device menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
333 | Private slot to install Python files into the onboard library. |
9738 | 334 | |
335 | @param packageMode flag indicating to install a library package | |
336 | (defaults to False) | |
337 | @type bool (optional) | |
7138
a2a53535d855
CircuitPythonDevices: added capability to install library files onto the device to the device menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
338 | """ |
9738 | 339 | title = ( |
340 | self.tr("Install Library Package") | |
341 | if packageMode | |
342 | else self.tr("Install Library Files") | |
343 | ) | |
7138
a2a53535d855
CircuitPythonDevices: added capability to install library files onto the device to the device menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
344 | if not self.__deviceVolumeMounted(): |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
345 | EricMessageBox.critical( |
7138
a2a53535d855
CircuitPythonDevices: added capability to install library files onto the device to the device menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
346 | self.microPython, |
9738 | 347 | title, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
348 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
349 | """The device volume "<b>{0}</b>" is not available.""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
350 | """ Ensure it is mounted properly and try again.""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
351 | ), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
352 | ) |
7138
a2a53535d855
CircuitPythonDevices: added capability to install library files onto the device to the device menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
353 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
354 | |
7138
a2a53535d855
CircuitPythonDevices: added capability to install library files onto the device to the device menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
355 | target = os.path.join(self.getWorkspace(), "lib") |
a2a53535d855
CircuitPythonDevices: added capability to install library files onto the device to the device menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
356 | # ensure that the library directory exists on the device |
a2a53535d855
CircuitPythonDevices: added capability to install library files onto the device to the device menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
357 | if not os.path.isdir(target): |
a2a53535d855
CircuitPythonDevices: added capability to install library files onto the device to the device menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
358 | os.makedirs(target) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
359 | |
9738 | 360 | if packageMode: |
361 | libraryPackage = EricFileDialog.getExistingDirectory( | |
362 | self.microPython, | |
363 | title, | |
364 | os.path.expanduser("~"), | |
365 | EricFileDialog.Option(0), | |
366 | ) | |
367 | if libraryPackage: | |
368 | target = os.path.join(target, os.path.basename(libraryPackage)) | |
369 | shutil.rmtree(target, ignore_errors=True) | |
370 | shutil.copytree(libraryPackage, target) | |
371 | else: | |
372 | libraryFiles = EricFileDialog.getOpenFileNames( | |
373 | self.microPython, | |
374 | title, | |
375 | os.path.expanduser("~"), | |
376 | self.tr( | |
377 | "Compiled Python Files (*.mpy);;" | |
378 | "Python Files (*.py);;" | |
379 | "All Files (*)" | |
380 | ), | |
381 | ) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
382 | |
9738 | 383 | for libraryFile in libraryFiles: |
384 | if os.path.exists(libraryFile): | |
385 | shutil.copy2(libraryFile, target) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
386 | |
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:
7145
diff
changeset
|
387 | 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:
7145
diff
changeset
|
388 | """ |
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:
7145
diff
changeset
|
389 | Public method to get the device documentation URL. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
390 | |
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:
7145
diff
changeset
|
391 | @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:
7145
diff
changeset
|
392 | @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:
7145
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:
7145
diff
changeset
|
394 | return Preferences.getMicroPython("CircuitPythonDocuUrl") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
395 | |
8053
5316e335722f
CircuitPython: added downloads menu for Firmware and Libraries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
396 | def getDownloadMenuEntries(self): |
7328 | 397 | """ |
8053
5316e335722f
CircuitPython: added downloads menu for Firmware and Libraries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
398 | Public method to retrieve the entries for the downloads menu. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
399 | |
8053
5316e335722f
CircuitPython: added downloads menu for Firmware and Libraries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
400 | @return list of tuples with menu text and URL to be opened for each |
5316e335722f
CircuitPython: added downloads menu for Firmware and Libraries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
401 | entry |
5316e335722f
CircuitPython: added downloads menu for Firmware and Libraries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
402 | @rtype list of tuple of (str, str) |
7328 | 403 | """ |
8053
5316e335722f
CircuitPython: added downloads menu for Firmware and Libraries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
404 | return [ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
405 | ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
406 | self.tr("CircuitPython Firmware"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
407 | Preferences.getMicroPython("CircuitPythonFirmwareUrl"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
408 | ), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
409 | ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
410 | self.tr("CircuitPython Libraries"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
411 | Preferences.getMicroPython("CircuitPythonLibrariesUrl"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
412 | ), |
8053
5316e335722f
CircuitPython: added downloads menu for Firmware and Libraries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
413 | ] |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
414 | |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
415 | |
9738 | 416 | def createDevice(microPythonWidget, deviceType, vid, pid, boardName): |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
417 | """ |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
418 | Function to instantiate a MicroPython device object. |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
419 | |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
420 | @param microPythonWidget reference to the main MicroPython widget |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
421 | @type MicroPythonWidget |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
422 | @param deviceType device type assigned to this device interface |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
423 | @type str |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
424 | @param vid vendor ID |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
425 | @type int |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
426 | @param pid product ID |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
427 | @type int |
9738 | 428 | @param boardName name of the board |
429 | @type str | |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
430 | @return reference to the instantiated device object |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
431 | @rtype CircuitPythonDevice |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
432 | """ |
9738 | 433 | return CircuitPythonDevice(microPythonWidget, deviceType, boardName) |