Sun, 30 Jun 2024 17:58:31 +0200
Moved some functions to the EricUtilities package for consistency and adapted the code base accordingly.
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
10439
21c28b0f9e41
Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10069
diff
changeset
|
3 | # Copyright (c) 2021 - 2024 Detlev Offenbach <detlev@die-offenbachs.de> |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing the device interface class for generic MicroPython devices |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | (i.e. those devices not specifically supported yet). |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
10 | |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | import os |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | |
9906
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
13 | from PyQt6.QtCore import QUrl, pyqtSlot |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
14 | from PyQt6.QtNetwork import QNetworkReply, QNetworkRequest |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
15 | from PyQt6.QtWidgets import QMenu |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
16 | |
10806
2f6df822e3b9
Moved some functions to the EricUtilities package for consistency and adapted the code base accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10683
diff
changeset
|
17 | from eric7 import EricUtilities, Preferences |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
18 | from eric7.EricWidgets import EricMessageBox |
9906
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
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 |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | |
9906
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
22 | from ..MicroPythonWidget import HAS_QTCHART |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
23 | from . import FirmwareGithubUrls |
9756
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
24 | from .DeviceBase import BaseDevice |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | |
9756
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
27 | class GenericMicroPythonDevice(BaseDevice): |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | Class implementing the device interface for generic MicroPython boards. |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
31 | |
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:
8110
diff
changeset
|
32 | def __init__(self, microPythonWidget, deviceType, vid, pid, parent=None): |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
35 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | @param microPythonWidget reference to the main MicroPython widget |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | @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:
8110
diff
changeset
|
38 | @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:
8110
diff
changeset
|
39 | @type str |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | @param vid vendor ID |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | @type int |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | @param pid product ID |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | @type int |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | @param parent reference to the parent object |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | @type QObject |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
47 | super().__init__(microPythonWidget, deviceType, parent) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
48 | |
9906
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
49 | self.__createGenericMenu() |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
50 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | self.__directAccess = False |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | self.__deviceVolumeName = "" |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | self.__workspace = "" |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | self.__deviceName = "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
55 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | for deviceData in Preferences.getMicroPython("ManualDevices"): |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
57 | if deviceData["vid"] == vid and deviceData["pid"] == pid: |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | self.__deviceVolumeName = deviceData["data_volume"] |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | self.__directAccess = bool(deviceData["data_volume"]) |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | self.__deviceName = deviceData["description"] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
61 | |
8110
c5af1d1d2a78
MicroPython: fixed some small bugs and typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8099
diff
changeset
|
62 | if self.__directAccess: |
c5af1d1d2a78
MicroPython: fixed some small bugs and typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8099
diff
changeset
|
63 | self.__workspace = self.__findWorkspace() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
64 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | def setButtons(self): |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | Public method to enable the supported action buttons. |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | """ |
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
|
69 | super().setButtons() |
9763
52f982c08301
Removed the 'Open' and 'Save' buttons from the MicroPython widget and made the repl and file manager start automatically upon connecting to the selected device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9756
diff
changeset
|
70 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | self.microPython.setActionButtons( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
72 | 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
|
73 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
74 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | def deviceName(self): |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | 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
|
78 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | @return name of the device |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | @rtype str |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
82 | return self.__deviceName |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
83 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | def canStartRepl(self): |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
86 | 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
|
87 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | @return tuple containing a flag indicating it is safe to start a REPL |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | and a reason why it cannot. |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | @rtype tuple of (bool, str) |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
92 | return True, "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
93 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | def canStartPlotter(self): |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | 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
|
97 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | @return tuple containing a flag indicating it is safe to start a |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | Plotter and a reason why it cannot. |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | @rtype tuple of (bool, str) |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
101 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
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 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | def canRunScript(self): |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | 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
|
107 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | @return tuple containing a flag indicating it is safe to start a |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | Plotter and a reason why it cannot. |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | @rtype tuple of (bool, str) |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
111 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
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 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | def runScript(self, script): |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
115 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
116 | 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
|
117 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
118 | @param script script to be executed |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | @type str |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
120 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | pythonScript = script.split("\n") |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
122 | self.sendCommands(pythonScript) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
123 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | def canStartFileManager(self): |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | 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
|
127 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | @return tuple containing a flag indicating it is safe to start a |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | File Manager and a reason why it cannot. |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | @rtype tuple of (bool, str) |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
132 | return True, "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
133 | |
9906
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
134 | def __createGenericMenu(self): |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
135 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
136 | Private method to create the Generic submenu. |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
137 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
138 | self.__genericMenu = QMenu(self.tr("Generic Device Functions")) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
139 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
140 | self.__showMpyAct = self.__genericMenu.addAction( |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
141 | self.tr("Show MicroPython Versions"), self.__showFirmwareVersions |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
142 | ) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
143 | self.__genericMenu.addSeparator() |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
144 | self.__bootloaderAct = self.__genericMenu.addAction( |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
145 | self.tr("Activate Bootloader"), self.__activateBootloader |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
146 | ) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
147 | self.__genericMenu.addSeparator() |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
148 | self.__resetAct = self.__genericMenu.addAction( |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
149 | self.tr("Reset Device"), self.__resetDevice |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
150 | ) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
151 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
152 | def addDeviceMenuEntries(self, menu): |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
153 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
154 | Public method to add device specific entries to the given menu. |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
155 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
156 | @param menu reference to the context menu |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
157 | @type QMenu |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
158 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
159 | connected = self.microPython.isConnected() |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
160 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
161 | self.__showMpyAct.setEnabled(connected) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
162 | self.__bootloaderAct.setEnabled(connected) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
163 | self.__resetAct.setEnabled(connected) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
164 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
165 | menu.addMenu(self.__genericMenu) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
166 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
167 | def supportsLocalFileAccess(self): |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
168 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
169 | 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
|
170 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
171 | @return flag indicating file access via local directory |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
172 | @rtype bool |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
173 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
174 | return self.__deviceVolumeMounted() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
175 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | def __deviceVolumeMounted(self): |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
177 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
178 | 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
|
179 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
180 | @return flag indicated a mounted device |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
181 | @rtype bool |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
182 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
183 | 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
|
184 | self.__workspace = "" # reset |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
185 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
186 | return self.__directAccess and self.__deviceVolumeName in self.getWorkspace( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
187 | silent=True |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
188 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
189 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
190 | def getWorkspace(self, silent=False): |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
191 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
192 | Public method to get the workspace directory. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
193 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
194 | @param silent flag indicating silent operations |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
195 | @type bool |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
196 | @return workspace directory used for saving files |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
197 | @rtype str |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
198 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
199 | if self.__directAccess: |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
200 | if self.__workspace: |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
201 | # return cached entry |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
202 | return self.__workspace |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
203 | else: |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
204 | self.__workspace = self.__findWorkspace(silent=silent) |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
205 | return self.__workspace |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
206 | else: |
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
|
207 | return super().getWorkspace() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
208 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
209 | def __findWorkspace(self, silent=False): |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
210 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
211 | 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
|
212 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
213 | @param silent flag indicating silent operations |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
214 | @type bool |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
215 | @return workspace directory used for saving files |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
216 | @rtype str |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
217 | """ |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
218 | # Attempts to find the path on the filesystem that represents the |
8110
c5af1d1d2a78
MicroPython: fixed some small bugs and typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8099
diff
changeset
|
219 | # plugged in board. |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9496
diff
changeset
|
220 | 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
|
221 | 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
|
222 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
223 | |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
224 | if deviceDirectories: |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
225 | if len(deviceDirectories) == 1: |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
226 | return deviceDirectories[0] |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
227 | else: |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
228 | return self.selectDeviceDirectory(deviceDirectories) |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
229 | else: |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
230 | # return the default workspace and give the user a warning (unless |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
231 | # silent mode is selected) |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
232 | 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:
8312
diff
changeset
|
233 | EricMessageBox.warning( |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
234 | self.microPython, |
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
235 | self.tr("Workspace Directory"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
236 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
237 | "Python files for this generic board can be" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
238 | " edited in 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
|
239 | " available. A volume named '{0}' was not found." |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
240 | " In 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
|
241 | ).format(self.__deviceVolumeName), |
8082
2242a6a1d786
MicroPython: added support for a generic MicroPython device where the user can configure the relevant paramaters through the 'Unknown Devices' dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
242 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
243 | |
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
|
244 | return super().getWorkspace() |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
245 | |
9906
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
246 | @pyqtSlot() |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
247 | def __activateBootloader(self): |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
248 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
249 | Private slot to switch the board into 'bootloader' mode. |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
250 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
251 | if self.microPython.isConnected(): |
9989 | 252 | self.executeCommands( |
9906
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
253 | "import machine\nmachine.bootloader()\n", mode=self._submitMode |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
254 | ) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
255 | # simulate pressing the disconnect button |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
256 | self.microPython.on_connectButton_clicked() |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
257 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
258 | @pyqtSlot() |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
259 | def __showFirmwareVersions(self): |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
260 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
261 | Private slot to show the firmware version of the connected device and the |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
262 | available firmware version. |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
263 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
264 | if self.microPython.isConnected(): |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
265 | if self._deviceData["mpy_name"] != "micropython": |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
266 | EricMessageBox.critical( |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
267 | None, |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
268 | self.tr("Show MicroPython Versions"), |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
269 | self.tr( |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
270 | """The firmware of the connected device cannot be""" |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
271 | """ determined or the board does not run MicroPython.""" |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
272 | """ Aborting...""" |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
273 | ), |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
274 | ) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
275 | else: |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
276 | ui = ericApp().getObject("UserInterface") |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
277 | request = QNetworkRequest(QUrl(FirmwareGithubUrls["micropython"])) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
278 | reply = ui.networkAccessManager().head(request) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
279 | reply.finished.connect(lambda: self.__firmwareVersionResponse(reply)) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
280 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
281 | @pyqtSlot(QNetworkReply) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
282 | def __firmwareVersionResponse(self, reply): |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
283 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
284 | Private slot handling the response of the latest version request. |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
285 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
286 | @param reply reference to the reply object |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
287 | @type QNetworkReply |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
288 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
289 | latestUrl = reply.url().toString() |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
290 | tag = latestUrl.rsplit("/", 1)[-1] |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
291 | while tag and not tag[0].isdecimal(): |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
292 | # get rid of leading non-decimal characters |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
293 | tag = tag[1:] |
10806
2f6df822e3b9
Moved some functions to the EricUtilities package for consistency and adapted the code base accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10683
diff
changeset
|
294 | latestVersion = EricUtilities.versionToTuple(tag) |
9906
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
295 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
296 | if self._deviceData["mpy_version"] == "unknown": |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
297 | currentVersionStr = self.tr("unknown") |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
298 | currentVersion = (0, 0, 0) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
299 | else: |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
300 | currentVersionStr = ( |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
301 | self._deviceData["mpy_variant_version"] |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
302 | if bool(self._deviceData["mpy_variant_version"]) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
303 | else self._deviceData["mpy_version"] |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
304 | ) |
10806
2f6df822e3b9
Moved some functions to the EricUtilities package for consistency and adapted the code base accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10683
diff
changeset
|
305 | currentVersion = EricUtilities.versionToTuple(currentVersionStr) |
9906
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
306 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
307 | msg = self.tr( |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
308 | "<h4>MicroPython Version Information</h4>" |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
309 | "<table>" |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
310 | "<tr><td>Installed:</td><td>{0}</td></tr>" |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
311 | "<tr><td>Available:</td><td>{1}</td></tr>" |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
312 | "{2}" |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
313 | "</table>" |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
314 | ).format( |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
315 | currentVersionStr, |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
316 | tag, |
10621
f5631f40c4d9
Corrected some code formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
317 | ( |
f5631f40c4d9
Corrected some code formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
318 | self.tr("<tr><td>Variant:</td><td>{0}</td></tr>").format( |
f5631f40c4d9
Corrected some code formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
319 | self._deviceData["mpy_variant"] |
f5631f40c4d9
Corrected some code formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
320 | ) |
f5631f40c4d9
Corrected some code formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
321 | if self._deviceData["mpy_variant"] |
f5631f40c4d9
Corrected some code formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
322 | else "" |
f5631f40c4d9
Corrected some code formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
323 | ), |
9906
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
324 | ) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
325 | if currentVersion < latestVersion: |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
326 | msg += self.tr("<p><b>Update available!</b></p>") |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
327 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
328 | EricMessageBox.information( |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
329 | None, |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
330 | self.tr("MicroPython Version"), |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
331 | msg, |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
332 | ) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
333 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
334 | @pyqtSlot() |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
335 | def __resetDevice(self): |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
336 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
337 | Private slot to reset the connected device. |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
338 | """ |
9989 | 339 | if self.microPython.isConnected(): |
340 | self.executeCommands( | |
341 | "import machine\nmachine.reset()\n", mode=self._submitMode | |
342 | ) | |
343 | # simulate pressing the disconnect button | |
344 | self.microPython.on_connectButton_clicked() | |
9906
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
345 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
346 | def getDocumentationUrl(self): |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
347 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
348 | Public method to get the device documentation URL. |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
349 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
350 | @return documentation URL of the device |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
351 | @rtype str |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
352 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
353 | return Preferences.getMicroPython("MicroPythonDocuUrl") |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
354 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
355 | def getFirmwareUrl(self): |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
356 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
357 | Public method to get the device firmware download URL. |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
358 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
359 | @return firmware download URL of the device |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
360 | @rtype str |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
361 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
362 | return Preferences.getMicroPython("MicroPythonFirmwareUrl") |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
363 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
364 | ################################################################## |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
365 | ## time related methods below |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
366 | ################################################################## |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
367 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
368 | def _getSetTimeCode(self): |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
369 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
370 | Protected method to get the device code to set the time. |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
371 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
372 | Note: This method must be implemented in the various device specific |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
373 | subclasses. |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
374 | |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
375 | @return code to be executed on the connected device to set the time |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
376 | @rtype str |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
377 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
378 | # rtc_time[0] - year 4 digit |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
379 | # rtc_time[1] - month 1..12 |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
380 | # rtc_time[2] - day 1..31 |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
381 | # rtc_time[3] - weekday 1..7 1=Monday |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
382 | # rtc_time[4] - hour 0..23 |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
383 | # rtc_time[5] - minute 0..59 |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
384 | # rtc_time[6] - second 0..59 |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
385 | # rtc_time[7] - yearday 1..366 |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
386 | # rtc_time[8] - isdst 0, 1, or -1 |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
387 | # |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
388 | # https://docs.micropython.org/en/latest/library/machine.RTC.html#machine-rtc |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
389 | return """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
390 | def set_time(rtc_time): |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
391 | try: |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
392 | import machine |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
393 | rtc = machine.RTC() |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
394 | rtc.datetime(rtc_time[:7] + (0,)) |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
395 | except Exception: |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
396 | pass |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
397 | """ |
39daf45010c8
Enhanced the support for Generic MicroPython devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
398 | |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
399 | |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10621
diff
changeset
|
400 | 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:
9473
diff
changeset
|
401 | """ |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
402 | Function to instantiate a MicroPython device object. |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
403 | |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
404 | @param microPythonWidget reference to the main MicroPython widget |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
405 | @type MicroPythonWidget |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
406 | @param deviceType device type assigned to this device interface |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
407 | @type str |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
408 | @param vid vendor ID |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
409 | @type int |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
410 | @param pid product ID |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
411 | @type int |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10621
diff
changeset
|
412 | @param _boardName name of the board (unused) |
9738 | 413 | @type str |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10621
diff
changeset
|
414 | @param _serialNumber serial number of the board (unused) |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9738
diff
changeset
|
415 | @type str |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
416 | @return reference to the instantiated device object |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
417 | @rtype GenericMicroPythonDevice |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
418 | """ |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
419 | return GenericMicroPythonDevice(microPythonWidget, deviceType, vid, pid) |