Sat, 11 Feb 2023 19:52:53 +0100
Moved the MicroPython board specific functions to a separate submenu.
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 | |
9742
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
13 | from PyQt6.QtCore import QUrl, pyqtSlot |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
14 | from PyQt6.QtNetwork import QNetworkRequest |
9738 | 15 | 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
|
16 | |
9742
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
17 | from eric7 import Globals, Preferences |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
18 | from eric7.EricWidgets import EricFileDialog, EricMessageBox |
9742
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
19 | from eric7.EricWidgets.EricApplication import ericApp |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9496
diff
changeset
|
20 | from eric7.SystemUtilities import FileSystemUtilities |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | |
9740 | 22 | from .CircuitPythonUpdater.CircuitPythonUpdaterInterface import ( |
23 | CircuitPythonUpdaterInterface, | |
24 | isCircupAvailable, | |
25 | ) | |
9747 | 26 | from .MicroPythonDevices import FirmwareGithubUrls, MicroPythonDevice |
7134
21d23ca51680
Renamed "MicroPythonReplWidget" to "MicroPythonWidget".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7132
diff
changeset
|
27 | from .MicroPythonWidget import HAS_QTCHART |
7059
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 | |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | class CircuitPythonDevice(MicroPythonDevice): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | Class implementing the device for CircuitPython boards. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
34 | |
7132
c4682cfcd160
CircuitPythonDevice: only report local access if the well known volume is mounted.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7129
diff
changeset
|
35 | DeviceVolumeName = "CIRCUITPY" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
36 | |
9738 | 37 | def __init__(self, microPythonWidget, deviceType, boardName, parent=None): |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
40 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | @param microPythonWidget reference to the main MicroPython widget |
7134
21d23ca51680
Renamed "MicroPythonReplWidget" to "MicroPythonWidget".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7132
diff
changeset
|
42 | @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
|
43 | @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
|
44 | @type str |
9738 | 45 | @param boardName name of the board |
46 | @type str | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | @param parent reference to the parent object |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | @type QObject |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
50 | super().__init__(microPythonWidget, deviceType, parent) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
51 | |
9738 | 52 | 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
|
53 | self.__workspace = self.__findWorkspace() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
54 | |
9740 | 55 | self.__updater = CircuitPythonUpdaterInterface(self) |
56 | ||
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
|
57 | 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
|
58 | "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
|
59 | } |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
60 | |
9752
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
61 | self.__createCPyMenu() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
62 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | def setButtons(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | Public method to enable the supported action buttons. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | """ |
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
|
67 | 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
|
68 | self.microPython.setActionButtons( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
69 | 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
|
70 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
71 | |
7132
c4682cfcd160
CircuitPythonDevice: only report local access if the well known volume is mounted.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7129
diff
changeset
|
72 | if self.__deviceVolumeMounted(): |
7092
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
73 | 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
|
74 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | def forceInterrupt(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | 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
|
78 | serial connection. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
79 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | @return flag indicating an interrupt is needed |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | @rtype bool |
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 False |
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 | 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
|
86 | """ |
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7122
diff
changeset
|
87 | 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
|
88 | |
7125
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7122
diff
changeset
|
89 | @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
|
90 | @rtype str |
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7122
diff
changeset
|
91 | """ |
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7122
diff
changeset
|
92 | return self.tr("CircuitPython") |
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 | def canStartRepl(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | 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
|
97 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | @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
|
99 | and a reason why it cannot. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | @rtype tuple of (bool, str) |
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 | return True, "" |
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 | def canStartPlotter(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | 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
|
107 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | @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
|
109 | Plotter and a reason why it cannot. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | @rtype tuple of (bool, str) |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
111 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | return True, "" |
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 | def canRunScript(self): |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
115 | """ |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
116 | 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
|
117 | |
7092
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
118 | @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
|
119 | 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
|
120 | @rtype tuple of (bool, str) |
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 | return True, "" |
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 | def runScript(self, script): |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
125 | """ |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
126 | 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
|
127 | |
7092
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
128 | @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
|
129 | @type str |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
130 | """ |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
131 | pythonScript = script.split("\n") |
7414b3b012b1
CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
132 | self.sendCommands(pythonScript) |
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 | 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
|
135 | """ |
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 | 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
|
137 | |
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
|
138 | @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
|
139 | 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
|
140 | @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
|
141 | """ |
c4d9c28ebcd8
Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7092
diff
changeset
|
142 | return True, "" |
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 | 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
|
145 | """ |
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 | 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
|
147 | |
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
|
148 | @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
|
149 | @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
|
150 | """ |
7132
c4682cfcd160
CircuitPythonDevice: only report local access if the well known volume is mounted.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7129
diff
changeset
|
151 | return self.__deviceVolumeMounted() |
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 | 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
|
154 | """ |
c4682cfcd160
CircuitPythonDevice: only report local access if the well known volume is mounted.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7129
diff
changeset
|
155 | 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
|
156 | |
7132
c4682cfcd160
CircuitPythonDevice: only report local access if the well known volume is mounted.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7129
diff
changeset
|
157 | @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
|
158 | @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
|
159 | """ |
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
|
160 | 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
|
161 | self.__workspace = "" # reset |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
162 | |
8062
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
163 | 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
|
164 | |
9738 | 165 | def __findDeviceDirectories(self, directories): |
166 | """ | |
167 | Private method to find the device directories associated with the | |
168 | current board name. | |
169 | ||
170 | @param directories list of directories to be checked | |
171 | @type list of str | |
172 | @return list of associated directories | |
173 | @rtype list of str | |
174 | """ | |
175 | boardDirectories = [] | |
176 | for directory in directories: | |
177 | bootFile = os.path.join(directory, "boot_out.txt") | |
178 | if os.path.exists(bootFile): | |
179 | with open(bootFile, "r") as f: | |
180 | line = f.readline() | |
181 | if self.__boardName in line: | |
182 | boardDirectories.append(directory) | |
183 | ||
184 | return boardDirectories | |
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 | 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
|
187 | """ |
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
|
188 | 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
|
189 | |
8062
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
190 | @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
|
191 | @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
|
192 | @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
|
193 | @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
|
194 | """ |
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
195 | # 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
|
196 | # 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
|
197 | 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
|
198 | 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
|
199 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
200 | |
8062
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8053
diff
changeset
|
201 | 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
|
202 | 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
|
203 | 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
|
204 | else: |
9738 | 205 | boardDirectories = self.__findDeviceDirectories(deviceDirectories) |
206 | if len(boardDirectories) == 1: | |
207 | return boardDirectories[0] | |
208 | elif len(boardDirectories) > 1: | |
209 | return self.selectDeviceDirectory(boardDirectories) | |
210 | else: | |
211 | return self.selectDeviceDirectory(deviceDirectories) | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
212 | else: |
7174
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7161
diff
changeset
|
213 | # 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
|
214 | # silent mode is selected) |
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7161
diff
changeset
|
215 | 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
|
216 | EricMessageBox.warning( |
7174
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7161
diff
changeset
|
217 | self.microPython, |
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7161
diff
changeset
|
218 | self.tr("Workspace Directory"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
219 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
220 | "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
|
221 | " 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
|
222 | " 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
|
223 | " 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
|
224 | ), |
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
|
225 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
226 | |
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
|
227 | return super().getWorkspace() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
228 | |
9740 | 229 | def getWorkspace(self, silent=False): |
230 | """ | |
231 | Public method to get the workspace directory. | |
232 | ||
233 | @param silent flag indicating silent operations | |
234 | @type bool | |
235 | @return workspace directory used for saving files | |
236 | @rtype str | |
237 | """ | |
238 | if self.__workspace: | |
239 | # return cached entry | |
240 | return self.__workspace | |
241 | else: | |
242 | self.__workspace = self.__findWorkspace(silent=silent) | |
243 | return self.__workspace | |
244 | ||
9752
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
245 | def __createCPyMenu(self): |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
246 | """ |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
247 | Private method to create the CircuitPython submenu. |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
248 | """ |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
249 | self.__libraryMenu = QMenu(self.tr("Library Management")) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
250 | self.__libraryMenu.aboutToShow.connect(self.__aboutToShowLibraryMenu) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
251 | self.__libraryMenu.setTearOffEnabled(True) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
252 | |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
253 | self.__cpyMenu = QMenu(self.tr("CircuitPython Functions")) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
254 | |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
255 | self.__cpyMenu.addAction( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
256 | self.tr("Show CircuitPython Versions"), self.__showCircuitPythonVersions |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
257 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
258 | self.__cpyMenu.addSeparator() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
259 | self.__flashCpyAct = self.__cpyMenu.addAction( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
260 | self.tr("Flash CircuitPython Firmware"), self.__flashCircuitPython |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
261 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
262 | self.__cpyMenu.addSeparator() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
263 | self.__cpyMenu.addMenu(self.__libraryMenu) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
264 | |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
265 | |
7116
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
266 | def addDeviceMenuEntries(self, menu): |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
267 | """ |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
268 | 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
|
269 | |
7116
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
270 | @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
|
271 | @type QMenu |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
272 | """ |
9749 | 273 | linkConnected = self.microPython.isLinkConnected() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
274 | |
9752
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
275 | self.__flashCpyAct.setEnabled(not linkConnected) |
9738 | 276 | |
9752
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
277 | menu.addMenu(self.__cpyMenu) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
278 | |
9740 | 279 | @pyqtSlot() |
280 | def __aboutToShowLibraryMenu(self): | |
281 | """ | |
282 | Private slot to populate the 'Library Management' menu. | |
283 | """ | |
284 | self.__libraryMenu.clear() | |
285 | ||
286 | if isCircupAvailable(): | |
287 | self.__updater.populateMenu(self.__libraryMenu) | |
288 | else: | |
289 | act = self.__libraryMenu.addAction( | |
290 | self.tr("Install Library Files"), self.__installLibraryFiles | |
291 | ) | |
292 | act.setEnabled(self.__deviceVolumeMounted()) | |
293 | act = self.__libraryMenu.addAction( | |
294 | self.tr("Install Library Package"), | |
295 | lambda: self.__installLibraryFiles(packageMode=True), | |
296 | ) | |
297 | act.setEnabled(self.__deviceVolumeMounted()) | |
298 | self.__libraryMenu.addSeparator() | |
299 | self.__libraryMenu.addAction( | |
300 | self.tr("Install 'circup' Package"), | |
301 | self.__updater.installCircup, | |
302 | ) | |
303 | ||
8096 | 304 | def hasFlashMenuEntry(self): |
305 | """ | |
306 | 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
|
307 | |
8096 | 308 | @return flag indicating a specific flash menu entry |
309 | @rtype bool | |
310 | """ | |
311 | return True | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
312 | |
7116
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
313 | @pyqtSlot() |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
314 | def __flashCircuitPython(self): |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
315 | """ |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
316 | 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
|
317 | """ |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
318 | 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
|
319 | |
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
|
320 | 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
|
321 | 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
|
322 | 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
|
323 | 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
|
324 | 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
|
325 | 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
|
326 | else: |
8096 | 327 | dlg = UF2FlashDialog(boardType="circuitpython") |
328 | dlg.exec() | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
329 | |
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
|
330 | 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
|
331 | """ |
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
|
332 | 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
|
333 | 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
|
334 | """ |
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
|
335 | EricMessageBox.information( |
7116
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
336 | self.microPython, |
233b6e62ca2b
CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
337 | 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
|
338 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
339 | """<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
|
340 | """ 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
|
341 | """ 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
|
342 | """ 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
|
343 | """<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
|
344 | """ for details.</p>""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
345 | ).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
|
346 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
347 | |
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
|
348 | @pyqtSlot() |
9742
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
349 | def __showCircuitPythonVersions(self): |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
350 | """ |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
351 | Private slot to show the CircuitPython version of a connected device and |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
352 | the latest available one (from Github). |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
353 | """ |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
354 | ui = ericApp().getObject("UserInterface") |
9747 | 355 | request = QNetworkRequest(QUrl(FirmwareGithubUrls["circuitpython"])) |
9742
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
356 | reply = ui.networkAccessManager().head(request) |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
357 | reply.finished.connect(lambda: self.__cpyVersionResponse(reply)) |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
358 | |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
359 | def __cpyVersionResponse(self, reply): |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
360 | """ |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
361 | Private method handling the response of the latest version request. |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
362 | |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
363 | @param reply reference to the reply object |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
364 | @type QNetworkReply |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
365 | """ |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
366 | latestUrl = reply.url().toString() |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
367 | tag = latestUrl.rsplit("/", 1)[-1] |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
368 | latestVersion = Globals.versionToTuple(tag) |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
369 | |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
370 | cpyVersionStr = self.tr("unknown") |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
371 | cpyVersion = (0, 0, 0) |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
372 | if self.supportsLocalFileAccess(): |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
373 | bootFile = os.path.join(self.getWorkspace(), "boot_out.txt") |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
374 | if os.path.exists(bootFile): |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
375 | with open(bootFile, "r") as f: |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
376 | line = f.readline() |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
377 | cpyVersionStr = line.split(";")[0].split()[2] |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
378 | cpyVersion = Globals.versionToTuple(cpyVersionStr) |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
379 | if ( |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
380 | cpyVersion == (0, 0, 0) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
381 | and self._deviceData |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
382 | and self._deviceData["mpy_version"] != "unknown" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
383 | ): |
9745
2c706ccc2b42
Added code to the CircuitPython interface to show the installed firmware version even if the drive is not mounted but the device is connected via the serial console.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9742
diff
changeset
|
384 | # drive is not mounted or 'boot_out.txt' is missing but the device |
2c706ccc2b42
Added code to the CircuitPython interface to show the installed firmware version even if the drive is not mounted but the device is connected via the serial console.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9742
diff
changeset
|
385 | # is connected via the serial console |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
386 | cpyVersionStr = self._deviceData["mpy_version"] |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
387 | cpyVersion = Globals.versionToTuple(cpyVersionStr) |
9742
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
388 | |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
389 | msg = self.tr( |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
390 | "<h4>CircuitPython Version Information</h4>" |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
391 | "<table>" |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
392 | "<tr><td>Installed:</td><td>{0}</td></tr>" |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
393 | "<tr><td>Available:</td><td>{1}</td></tr>" |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
394 | "</table>" |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
395 | ).format(cpyVersionStr, tag) |
9746
37d460e32843
Corrected the CircuitPython interface code to show the update availability notice correctly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9745
diff
changeset
|
396 | if cpyVersion < latestVersion and cpyVersion != (0, 0, 0): |
9742
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
397 | msg += self.tr("<p><b>Update available!</b></p>") |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
398 | |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
399 | EricMessageBox.information( |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
400 | None, |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
401 | self.tr("CircuitPython Version"), |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
402 | msg, |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
403 | ) |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
404 | |
48dbfea4ac06
Added a CircuitPython menu entry to show the installed and available firmware version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9740
diff
changeset
|
405 | @pyqtSlot() |
9738 | 406 | 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
|
407 | """ |
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
|
408 | Private slot to install Python files into the onboard library. |
9738 | 409 | |
410 | @param packageMode flag indicating to install a library package | |
411 | (defaults to False) | |
412 | @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
|
413 | """ |
9738 | 414 | title = ( |
415 | self.tr("Install Library Package") | |
416 | if packageMode | |
417 | else self.tr("Install Library Files") | |
418 | ) | |
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
|
419 | 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
|
420 | 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
|
421 | self.microPython, |
9738 | 422 | title, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
423 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
424 | """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
|
425 | """ 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
|
426 | ), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
427 | ) |
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
|
428 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
429 | |
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
|
430 | 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
|
431 | # 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
|
432 | 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
|
433 | os.makedirs(target) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
434 | |
9738 | 435 | if packageMode: |
436 | libraryPackage = EricFileDialog.getExistingDirectory( | |
437 | self.microPython, | |
438 | title, | |
439 | os.path.expanduser("~"), | |
440 | EricFileDialog.Option(0), | |
441 | ) | |
442 | if libraryPackage: | |
443 | target = os.path.join(target, os.path.basename(libraryPackage)) | |
444 | shutil.rmtree(target, ignore_errors=True) | |
445 | shutil.copytree(libraryPackage, target) | |
446 | else: | |
447 | libraryFiles = EricFileDialog.getOpenFileNames( | |
448 | self.microPython, | |
449 | title, | |
450 | os.path.expanduser("~"), | |
451 | self.tr( | |
452 | "Compiled Python Files (*.mpy);;" | |
453 | "Python Files (*.py);;" | |
454 | "All Files (*)" | |
455 | ), | |
456 | ) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
457 | |
9738 | 458 | for libraryFile in libraryFiles: |
459 | if os.path.exists(libraryFile): | |
460 | shutil.copy2(libraryFile, target) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
461 | |
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
|
462 | 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
|
463 | """ |
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
|
464 | 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
|
465 | |
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
|
466 | @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
|
467 | @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
|
468 | """ |
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
|
469 | return Preferences.getMicroPython("CircuitPythonDocuUrl") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
470 | |
8053
5316e335722f
CircuitPython: added downloads menu for Firmware and Libraries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
471 | def getDownloadMenuEntries(self): |
7328 | 472 | """ |
8053
5316e335722f
CircuitPython: added downloads menu for Firmware and Libraries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
473 | 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
|
474 | |
8053
5316e335722f
CircuitPython: added downloads menu for Firmware and Libraries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
475 | @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
|
476 | entry |
5316e335722f
CircuitPython: added downloads menu for Firmware and Libraries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
477 | @rtype list of tuple of (str, str) |
7328 | 478 | """ |
8053
5316e335722f
CircuitPython: added downloads menu for Firmware and Libraries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
479 | return [ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
480 | ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
481 | self.tr("CircuitPython Firmware"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
482 | Preferences.getMicroPython("CircuitPythonFirmwareUrl"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
483 | ), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
484 | ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
485 | self.tr("CircuitPython Libraries"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
486 | Preferences.getMicroPython("CircuitPythonLibrariesUrl"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
487 | ), |
8053
5316e335722f
CircuitPython: added downloads menu for Firmware and Libraries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
488 | ] |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
489 | |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
490 | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
491 | def createDevice(microPythonWidget, deviceType, vid, pid, boardName, serialNumber): |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
492 | """ |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
493 | 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
|
494 | |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
495 | @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
|
496 | @type MicroPythonWidget |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
497 | @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
|
498 | @type str |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
499 | @param vid vendor ID |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
500 | @type int |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
501 | @param pid product ID |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
502 | @type int |
9738 | 503 | @param boardName name of the board |
504 | @type str | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
505 | @param serialNumber serial number of the board |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
506 | @type str |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
507 | @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
|
508 | @rtype CircuitPythonDevice |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
509 | """ |
9738 | 510 | return CircuitPythonDevice(microPythonWidget, deviceType, boardName) |