6 """ |
6 """ |
7 Module implementing the device interface class for CircuitPython boards. |
7 Module implementing the device interface class for CircuitPython boards. |
8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
|
11 |
|
12 import shutil |
|
13 |
|
14 from PyQt5.QtCore import pyqtSlot |
|
15 from PyQt5.QtWidgets import QDialog |
11 |
16 |
12 from E5Gui import E5MessageBox |
17 from E5Gui import E5MessageBox |
13 |
18 |
14 from .MicroPythonDevices import MicroPythonDevice |
19 from .MicroPythonDevices import MicroPythonDevice |
15 from .MicroPythonReplWidget import HAS_QTCHART |
20 from .MicroPythonReplWidget import HAS_QTCHART |
35 def setButtons(self): |
40 def setButtons(self): |
36 """ |
41 """ |
37 Public method to enable the supported action buttons. |
42 Public method to enable the supported action buttons. |
38 """ |
43 """ |
39 super(CircuitPythonDevice, self).setButtons() |
44 super(CircuitPythonDevice, self).setButtons() |
40 ## self.microPython.setActionButtons( |
|
41 ## run=True, repl=True, chart=HAS_QTCHART) |
|
42 # TODO: check, if this really works |
|
43 self.microPython.setActionButtons( |
45 self.microPython.setActionButtons( |
44 run=True, repl=True, files=True, chart=HAS_QTCHART) |
46 run=True, repl=True, files=True, chart=HAS_QTCHART) |
45 |
47 |
46 workspace = self.getWorkspace() |
48 workspace = self.getWorkspace() |
47 if workspace.endswith("CIRCUITPY"): |
49 if workspace.endswith("CIRCUITPY"): |
95 @type str |
97 @type str |
96 """ |
98 """ |
97 pythonScript = script.split("\n") |
99 pythonScript = script.split("\n") |
98 self.sendCommands(pythonScript) |
100 self.sendCommands(pythonScript) |
99 |
101 |
100 # TODO: check, if this really works |
|
101 def canStartFileManager(self): |
102 def canStartFileManager(self): |
102 """ |
103 """ |
103 Public method to determine, if a File Manager can be started. |
104 Public method to determine, if a File Manager can be started. |
104 |
105 |
105 @return tuple containing a flag indicating it is safe to start a |
106 @return tuple containing a flag indicating it is safe to start a |
122 if deviceDirectory: |
123 if deviceDirectory: |
123 return deviceDirectory |
124 return deviceDirectory |
124 else: |
125 else: |
125 # return the default workspace and give the user a warning |
126 # return the default workspace and give the user a warning |
126 E5MessageBox.warning( |
127 E5MessageBox.warning( |
127 self.microPythonWidget, |
128 self.microPython, |
128 self.tr("Workspace Directory"), |
129 self.tr("Workspace Directory"), |
129 self.tr("Python files for CircuitPython devices are stored on" |
130 self.tr("Python files for CircuitPython devices are stored on" |
130 " the device. Therefore, to edit these files you need" |
131 " the device. Therefore, to edit these files you need" |
131 " to have the device plugged in. Until you plug in a" |
132 " to have the device plugged in. Until you plug in a" |
132 " device, the standard directory will be used.")) |
133 " device, the standard directory will be used.")) |
133 |
134 |
134 return super(CircuitPythonDevice, self).getWorkspace() |
135 return super(CircuitPythonDevice, self).getWorkspace() |
|
136 |
|
137 def addDeviceMenuEntries(self, menu): |
|
138 """ |
|
139 Public method to add device specific entries to the given menu. |
|
140 |
|
141 @param menu reference to the context menu |
|
142 @type QMenu |
|
143 """ |
|
144 connected = self.microPython.isConnected() |
|
145 |
|
146 act = menu.addAction(self.tr("Flash CircuitPython Firmware"), |
|
147 self.__flashCircuitPython) |
|
148 act.setEnabled(not connected) |
|
149 |
|
150 @pyqtSlot() |
|
151 def __flashCircuitPython(self): |
|
152 """ |
|
153 Private slot to flash a CircuitPython firmware to the device. |
|
154 """ |
|
155 ok = E5MessageBox.information( |
|
156 self.microPython, |
|
157 self.tr("Flash CircuitPython Firmware"), |
|
158 self.tr("Please reset the device to bootloader mode and confirm" |
|
159 " when ready."), |
|
160 E5MessageBox.StandardButtons( |
|
161 E5MessageBox.Abort | |
|
162 E5MessageBox.Ok)) |
|
163 if ok: |
|
164 from .CircuitPythonFirmwareSelectionDialog import ( |
|
165 CircuitPythonFirmwareSelectionDialog) |
|
166 dlg = CircuitPythonFirmwareSelectionDialog() |
|
167 if dlg.exec_() == QDialog.Accepted: |
|
168 cpyPath, devicePath = dlg.getData() |
|
169 shutil.copy2(cpyPath, devicePath) |