eric6/MicroPython/CircuitPythonDevices.py

Wed, 07 Aug 2019 16:08:46 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 07 Aug 2019 16:08:46 +0200
branch
micropython
changeset 7125
2028553ee58c
parent 7122
8e67ef7975de
child 7129
3cc19aec959a
permissions
-rw-r--r--

CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.

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
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2019 Detlev Offenbach <detlev@die-offenbachs.de>
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
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from __future__ import unicode_literals
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
7116
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
12 import shutil
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
13
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
14 from PyQt5.QtCore import pyqtSlot
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
15 from PyQt5.QtWidgets import QDialog
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
16
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from E5Gui import E5MessageBox
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from .MicroPythonDevices import MicroPythonDevice
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 from .MicroPythonReplWidget import HAS_QTCHART
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
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
22 import Utilities
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 class CircuitPythonDevice(MicroPythonDevice):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Class implementing the device for CircuitPython boards.
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 def __init__(self, microPythonWidget, parent=None):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 Constructor
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @param microPythonWidget reference to the main MicroPython widget
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @type MicroPythonReplWidget
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 @param parent reference to the parent object
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 @type QObject
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 super(CircuitPythonDevice, self).__init__(microPythonWidget, parent)
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 def setButtons(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 Public method to enable the supported action buttons.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 super(CircuitPythonDevice, self).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
45 self.microPython.setActionButtons(
c4d9c28ebcd8 Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7092
diff changeset
46 run=True, repl=True, files=True, chart=HAS_QTCHART)
7092
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
47
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
48 workspace = self.getWorkspace()
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
49 if workspace.endswith("CIRCUITPY"):
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
50 self.microPython.setActionButtons(open=True, save=True)
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 def forceInterrupt(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 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
55 serial connection.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 @return flag indicating an interrupt is needed
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @rtype bool
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 return False
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
7125
2028553ee58c CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7122
diff changeset
62 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
63 """
2028553ee58c CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7122
diff changeset
64 Public method to get the 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
65
2028553ee58c CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7122
diff changeset
66 @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
67 @rtype str
2028553ee58c CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7122
diff changeset
68 """
2028553ee58c CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7122
diff changeset
69 return self.tr("CircuitPython")
2028553ee58c CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7122
diff changeset
70
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 def canStartRepl(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 Public method to determine, if a REPL can be started.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 @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
76 and a reason why it cannot.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 @rtype tuple of (bool, str)
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 return True, ""
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 def canStartPlotter(self):
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 Public method to determine, if a Plotter can be started.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 @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
86 Plotter and a reason why it cannot.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 @rtype tuple of (bool, str)
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 return True, ""
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90
7092
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
91 def canRunScript(self):
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
92 """
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
93 Public method to determine, if a script can be executed.
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
94
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
95 @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
96 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
97 @rtype tuple of (bool, str)
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
98 """
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
99 return True, ""
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
100
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
101 def runScript(self, script):
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
102 """
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
103 Public method to run the given Python script.
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
104
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
105 @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
106 @type str
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
107 """
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
108 pythonScript = script.split("\n")
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
109 self.sendCommands(pythonScript)
7414b3b012b1 CircuitPythonDevices: started the adaption for 'CircuitPython' based devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
110
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
111 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
112 """
c4d9c28ebcd8 Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7092
diff changeset
113 Public method to determine, if a File Manager can be started.
c4d9c28ebcd8 Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7092
diff changeset
114
c4d9c28ebcd8 Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7092
diff changeset
115 @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
116 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
117 @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
118 """
c4d9c28ebcd8 Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7092
diff changeset
119 return True, ""
c4d9c28ebcd8 Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7092
diff changeset
120
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 def getWorkspace(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 Public method to get the workspace directory.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 @return workspace directory used for saving files
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 @rtype str
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 # Attempts to find the path on the filesystem that represents the
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 # plugged in CIRCUITPY board.
7100
c4d9c28ebcd8 Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7092
diff changeset
130 deviceDirectory = Utilities.findVolume("CIRCUITPY")
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 if deviceDirectory:
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 return deviceDirectory
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 else:
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 # return the default workspace and give the user a warning
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 E5MessageBox.warning(
7116
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
137 self.microPython,
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 self.tr("Workspace Directory"),
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 self.tr("Python files for CircuitPython devices are stored on"
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 " the device. Therefore, to edit these files you need"
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 " to have the device plugged in. Until you plug in a"
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 " device, the standard directory will be used."))
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 return super(CircuitPythonDevice, self).getWorkspace()
7116
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
145
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
146 def addDeviceMenuEntries(self, menu):
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
147 """
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
148 Public method to add device specific entries to the given menu.
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
149
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
150 @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
151 @type QMenu
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
152 """
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
153 connected = self.microPython.isConnected()
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
154
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
155 act = menu.addAction(self.tr("Flash CircuitPython Firmware"),
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
156 self.__flashCircuitPython)
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
157 act.setEnabled(not connected)
7122
8e67ef7975de CircuitPythonDevices: added some TODO markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7116
diff changeset
158 # TODO: add menu entry to copy a .mpy or .py file to the
8e67ef7975de CircuitPythonDevices: added some TODO markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7116
diff changeset
159 # device library (creating the /lib folder if it doesn't
8e67ef7975de CircuitPythonDevices: added some TODO markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7116
diff changeset
160 # exist already)
8e67ef7975de CircuitPythonDevices: added some TODO markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7116
diff changeset
161 # TODO: add menu entry to cross-compile a .py file (using mpy-cross)
7116
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
162
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
163 @pyqtSlot()
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
164 def __flashCircuitPython(self):
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
165 """
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
166 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
167 """
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
168 ok = E5MessageBox.information(
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
169 self.microPython,
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
170 self.tr("Flash CircuitPython Firmware"),
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
171 self.tr("Please reset the device to bootloader mode and confirm"
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
172 " when ready."),
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
173 E5MessageBox.StandardButtons(
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
174 E5MessageBox.Abort |
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
175 E5MessageBox.Ok))
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
176 if ok:
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
177 from .CircuitPythonFirmwareSelectionDialog import (
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
178 CircuitPythonFirmwareSelectionDialog)
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
179 dlg = CircuitPythonFirmwareSelectionDialog()
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
180 if dlg.exec_() == QDialog.Accepted:
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
181 cpyPath, devicePath = dlg.getData()
233b6e62ca2b CircuitPython: added code to flash a new CircuitPython firmware.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7100
diff changeset
182 shutil.copy2(cpyPath, devicePath)

eric ide

mercurial