44 """ |
44 """ |
45 super().__init__(microPythonWidget, deviceType, parent) |
45 super().__init__(microPythonWidget, deviceType, parent) |
46 |
46 |
47 self._submitMode = "paste" # use 'paste' mode |
47 self._submitMode = "paste" # use 'paste' mode |
48 |
48 |
49 self.__workspace = self.__findWorkspace() |
|
50 |
|
51 self.__createSTLinkMenu() |
49 self.__createSTLinkMenu() |
52 |
50 |
53 def setButtons(self): |
51 def setButtons(self): |
54 """ |
52 """ |
55 Public method to enable the supported action buttons. |
53 Public method to enable the supported action buttons. |
126 @return tuple containing a flag indicating it is safe to start a |
124 @return tuple containing a flag indicating it is safe to start a |
127 File Manager and a reason why it cannot. |
125 File Manager and a reason why it cannot. |
128 @rtype tuple of (bool, str) |
126 @rtype tuple of (bool, str) |
129 """ |
127 """ |
130 return True, "" |
128 return True, "" |
131 |
|
132 def supportsLocalFileAccess(self): |
|
133 """ |
|
134 Public method to indicate file access via a local directory. |
|
135 |
|
136 @return flag indicating file access via local directory |
|
137 @rtype bool |
|
138 """ |
|
139 return self.__deviceVolumeMounted() |
|
140 |
|
141 def __deviceVolumeMounted(self): |
|
142 """ |
|
143 Private method to check, if the device volume is mounted. |
|
144 |
|
145 @return flag indicated a mounted device |
|
146 @rtype bool |
|
147 """ |
|
148 if self.__workspace and not os.path.exists(self.__workspace): |
|
149 self.__workspace = "" # reset |
|
150 |
|
151 return self.DeviceVolumeName in self.getWorkspace(silent=True) |
|
152 |
|
153 def getWorkspace(self, silent=False): |
|
154 """ |
|
155 Public method to get the workspace directory. |
|
156 |
|
157 @param silent flag indicating silent operations |
|
158 @type bool |
|
159 @return workspace directory used for saving files |
|
160 @rtype str |
|
161 """ |
|
162 if self.__workspace: |
|
163 # return cached entry |
|
164 return self.__workspace |
|
165 else: |
|
166 self.__workspace = self.__findWorkspace(silent=silent) |
|
167 return self.__workspace |
|
168 |
|
169 def __findWorkspace(self, silent=False): |
|
170 """ |
|
171 Private method to find the workspace directory. |
|
172 |
|
173 @param silent flag indicating silent operations |
|
174 @type bool |
|
175 @return workspace directory used for saving files |
|
176 @rtype str |
|
177 """ |
|
178 # Attempts to find the path on the filesystem that represents the |
|
179 # plugged in PyBoard board. |
|
180 deviceDirectories = FileSystemUtilities.findVolume( |
|
181 self.DeviceVolumeName, findAll=True |
|
182 ) |
|
183 |
|
184 if deviceDirectories: |
|
185 if len(deviceDirectories) == 1: |
|
186 return deviceDirectories[0] |
|
187 else: |
|
188 return self.selectDeviceDirectory(deviceDirectories) |
|
189 else: |
|
190 # return the default workspace and give the user a warning (unless |
|
191 # silent mode is selected) |
|
192 if not silent: |
|
193 EricMessageBox.warning( |
|
194 self.microPython, |
|
195 self.tr("Workspace Directory"), |
|
196 self.tr( |
|
197 "Python files for STLink boards can be edited in" |
|
198 " place, if the device volume is locally" |
|
199 " available. Such a volume was not found. In" |
|
200 " place editing will not be available." |
|
201 ), |
|
202 ) |
|
203 |
|
204 return super().getWorkspace() |
|
205 |
129 |
206 def getDocumentationUrl(self): |
130 def getDocumentationUrl(self): |
207 """ |
131 """ |
208 Public method to get the device documentation URL. |
132 Public method to get the device documentation URL. |
209 |
133 |
475 def __resetDevice(self): |
399 def __resetDevice(self): |
476 """ |
400 """ |
477 Private slot to reset the connected device. |
401 Private slot to reset the connected device. |
478 """ |
402 """ |
479 if self.microPython.isConnected(): |
403 if self.microPython.isConnected(): |
480 self.executeCommands( |
404 out, err = self.executeCommands( |
481 "import machine\nmachine.reset()\n", mode=self._submitMode |
405 "import machine\nmachine.reset()\n", mode=self._submitMode |
482 ) |
406 ) |
|
407 if not err: |
|
408 self.microPython.insertData(out + b"\r\n") |
483 |
409 |
484 |
410 |
485 def createDevice(microPythonWidget, deviceType, _vid, _pid, _boardName, _serialNumber): |
411 def createDevice(microPythonWidget, deviceType, _vid, _pid, _boardName, _serialNumber): |
486 """ |
412 """ |
487 Function to instantiate a MicroPython device object. |
413 Function to instantiate a MicroPython device object. |