36 @param pid product ID |
37 @param pid product ID |
37 @type int |
38 @type int |
38 @param parent reference to the parent object |
39 @param parent reference to the parent object |
39 @type QObject |
40 @type QObject |
40 """ |
41 """ |
41 super().__init__( |
42 super().__init__(microPythonWidget, deviceType, parent) |
42 microPythonWidget, deviceType, parent) |
43 |
43 |
|
44 self.__directAccess = False |
44 self.__directAccess = False |
45 self.__deviceVolumeName = "" |
45 self.__deviceVolumeName = "" |
46 self.__workspace = "" |
46 self.__workspace = "" |
47 self.__deviceName = "" |
47 self.__deviceName = "" |
48 |
48 |
49 for deviceData in Preferences.getMicroPython("ManualDevices"): |
49 for deviceData in Preferences.getMicroPython("ManualDevices"): |
50 if ( |
50 if deviceData["vid"] == vid and deviceData["pid"] == pid: |
51 deviceData["vid"] == vid and |
|
52 deviceData["pid"] == pid |
|
53 ): |
|
54 self.__deviceVolumeName = deviceData["data_volume"] |
51 self.__deviceVolumeName = deviceData["data_volume"] |
55 self.__directAccess = bool(deviceData["data_volume"]) |
52 self.__directAccess = bool(deviceData["data_volume"]) |
56 self.__deviceName = deviceData["description"] |
53 self.__deviceName = deviceData["description"] |
57 |
54 |
58 if self.__directAccess: |
55 if self.__directAccess: |
59 self.__workspace = self.__findWorkspace() |
56 self.__workspace = self.__findWorkspace() |
60 |
57 |
61 def setButtons(self): |
58 def setButtons(self): |
62 """ |
59 """ |
63 Public method to enable the supported action buttons. |
60 Public method to enable the supported action buttons. |
64 """ |
61 """ |
65 super().setButtons() |
62 super().setButtons() |
66 self.microPython.setActionButtons( |
63 self.microPython.setActionButtons( |
67 run=True, repl=True, files=True, chart=HAS_QTCHART) |
64 run=True, repl=True, files=True, chart=HAS_QTCHART |
68 |
65 ) |
|
66 |
69 if self.__directAccess and self.__deviceVolumeMounted(): |
67 if self.__directAccess and self.__deviceVolumeMounted(): |
70 self.microPython.setActionButtons(open=True, save=True) |
68 self.microPython.setActionButtons(open=True, save=True) |
71 |
69 |
72 def deviceName(self): |
70 def deviceName(self): |
73 """ |
71 """ |
74 Public method to get the name of the device. |
72 Public method to get the name of the device. |
75 |
73 |
76 @return name of the device |
74 @return name of the device |
77 @rtype str |
75 @rtype str |
78 """ |
76 """ |
79 return self.__deviceName |
77 return self.__deviceName |
80 |
78 |
81 def canStartRepl(self): |
79 def canStartRepl(self): |
82 """ |
80 """ |
83 Public method to determine, if a REPL can be started. |
81 Public method to determine, if a REPL can be started. |
84 |
82 |
85 @return tuple containing a flag indicating it is safe to start a REPL |
83 @return tuple containing a flag indicating it is safe to start a REPL |
86 and a reason why it cannot. |
84 and a reason why it cannot. |
87 @rtype tuple of (bool, str) |
85 @rtype tuple of (bool, str) |
88 """ |
86 """ |
89 return True, "" |
87 return True, "" |
90 |
88 |
91 def canStartPlotter(self): |
89 def canStartPlotter(self): |
92 """ |
90 """ |
93 Public method to determine, if a Plotter can be started. |
91 Public method to determine, if a Plotter can be started. |
94 |
92 |
95 @return tuple containing a flag indicating it is safe to start a |
93 @return tuple containing a flag indicating it is safe to start a |
96 Plotter and a reason why it cannot. |
94 Plotter and a reason why it cannot. |
97 @rtype tuple of (bool, str) |
95 @rtype tuple of (bool, str) |
98 """ |
96 """ |
99 return True, "" |
97 return True, "" |
100 |
98 |
101 def canRunScript(self): |
99 def canRunScript(self): |
102 """ |
100 """ |
103 Public method to determine, if a script can be executed. |
101 Public method to determine, if a script can be executed. |
104 |
102 |
105 @return tuple containing a flag indicating it is safe to start a |
103 @return tuple containing a flag indicating it is safe to start a |
106 Plotter and a reason why it cannot. |
104 Plotter and a reason why it cannot. |
107 @rtype tuple of (bool, str) |
105 @rtype tuple of (bool, str) |
108 """ |
106 """ |
109 return True, "" |
107 return True, "" |
110 |
108 |
111 def runScript(self, script): |
109 def runScript(self, script): |
112 """ |
110 """ |
113 Public method to run the given Python script. |
111 Public method to run the given Python script. |
114 |
112 |
115 @param script script to be executed |
113 @param script script to be executed |
116 @type str |
114 @type str |
117 """ |
115 """ |
118 pythonScript = script.split("\n") |
116 pythonScript = script.split("\n") |
119 self.sendCommands(pythonScript) |
117 self.sendCommands(pythonScript) |
120 |
118 |
121 def canStartFileManager(self): |
119 def canStartFileManager(self): |
122 """ |
120 """ |
123 Public method to determine, if a File Manager can be started. |
121 Public method to determine, if a File Manager can be started. |
124 |
122 |
125 @return tuple containing a flag indicating it is safe to start a |
123 @return tuple containing a flag indicating it is safe to start a |
126 File Manager and a reason why it cannot. |
124 File Manager and a reason why it cannot. |
127 @rtype tuple of (bool, str) |
125 @rtype tuple of (bool, str) |
128 """ |
126 """ |
129 return True, "" |
127 return True, "" |
130 |
128 |
131 def supportsLocalFileAccess(self): |
129 def supportsLocalFileAccess(self): |
132 """ |
130 """ |
133 Public method to indicate file access via a local directory. |
131 Public method to indicate file access via a local directory. |
134 |
132 |
135 @return flag indicating file access via local directory |
133 @return flag indicating file access via local directory |
136 @rtype bool |
134 @rtype bool |
137 """ |
135 """ |
138 return self.__deviceVolumeMounted() |
136 return self.__deviceVolumeMounted() |
139 |
137 |
140 def __deviceVolumeMounted(self): |
138 def __deviceVolumeMounted(self): |
141 """ |
139 """ |
142 Private method to check, if the device volume is mounted. |
140 Private method to check, if the device volume is mounted. |
143 |
141 |
144 @return flag indicated a mounted device |
142 @return flag indicated a mounted device |
145 @rtype bool |
143 @rtype bool |
146 """ |
144 """ |
147 if self.__workspace and not os.path.exists(self.__workspace): |
145 if self.__workspace and not os.path.exists(self.__workspace): |
148 self.__workspace = "" # reset |
146 self.__workspace = "" # reset |
149 |
147 |
150 return ( |
148 return self.__directAccess and self.__deviceVolumeName in self.getWorkspace( |
151 self.__directAccess and |
149 silent=True |
152 self.__deviceVolumeName in self.getWorkspace(silent=True) |
|
153 ) |
150 ) |
154 |
151 |
155 def getWorkspace(self, silent=False): |
152 def getWorkspace(self, silent=False): |
156 """ |
153 """ |
157 Public method to get the workspace directory. |
154 Public method to get the workspace directory. |
158 |
155 |
159 @param silent flag indicating silent operations |
156 @param silent flag indicating silent operations |
160 @type bool |
157 @type bool |
161 @return workspace directory used for saving files |
158 @return workspace directory used for saving files |
162 @rtype str |
159 @rtype str |
163 """ |
160 """ |
168 else: |
165 else: |
169 self.__workspace = self.__findWorkspace(silent=silent) |
166 self.__workspace = self.__findWorkspace(silent=silent) |
170 return self.__workspace |
167 return self.__workspace |
171 else: |
168 else: |
172 return super().getWorkspace() |
169 return super().getWorkspace() |
173 |
170 |
174 def __findWorkspace(self, silent=False): |
171 def __findWorkspace(self, silent=False): |
175 """ |
172 """ |
176 Private method to find the workspace directory. |
173 Private method to find the workspace directory. |
177 |
174 |
178 @param silent flag indicating silent operations |
175 @param silent flag indicating silent operations |
179 @type bool |
176 @type bool |
180 @return workspace directory used for saving files |
177 @return workspace directory used for saving files |
181 @rtype str |
178 @rtype str |
182 """ |
179 """ |
183 # Attempts to find the path on the filesystem that represents the |
180 # Attempts to find the path on the filesystem that represents the |
184 # plugged in board. |
181 # plugged in board. |
185 deviceDirectories = Utilities.findVolume(self.__deviceVolumeName, |
182 deviceDirectories = Utilities.findVolume(self.__deviceVolumeName, findAll=True) |
186 findAll=True) |
183 |
187 |
|
188 if deviceDirectories: |
184 if deviceDirectories: |
189 if len(deviceDirectories) == 1: |
185 if len(deviceDirectories) == 1: |
190 return deviceDirectories[0] |
186 return deviceDirectories[0] |
191 else: |
187 else: |
192 return self.selectDeviceDirectory(deviceDirectories) |
188 return self.selectDeviceDirectory(deviceDirectories) |