eric6/MicroPython/CircuitPythonDevices.py

changeset 8062
8dc5acb30a8b
parent 8053
5316e335722f
child 8067
a467ab075be0
equal deleted inserted replaced
8061:979562f350bf 8062:8dc5acb30a8b
36 @type MicroPythonWidget 36 @type MicroPythonWidget
37 @param parent reference to the parent object 37 @param parent reference to the parent object
38 @type QObject 38 @type QObject
39 """ 39 """
40 super(CircuitPythonDevice, self).__init__(microPythonWidget, parent) 40 super(CircuitPythonDevice, self).__init__(microPythonWidget, parent)
41
42 self.__workspace = self.__findWorkspace()
41 43
42 def setButtons(self): 44 def setButtons(self):
43 """ 45 """
44 Public method to enable the supported action buttons. 46 Public method to enable the supported action buttons.
45 """ 47 """
133 Private method to check, if the device volume is mounted. 135 Private method to check, if the device volume is mounted.
134 136
135 @return flag indicated a mounted device 137 @return flag indicated a mounted device
136 @rtype bool 138 @rtype bool
137 """ 139 """
138 return self.getWorkspace(silent=True).endswith(self.DeviceVolumeName) 140 return self.DeviceVolumeName in self.getWorkspace(silent=True)
139 141
140 def getWorkspace(self, silent=False): 142 def getWorkspace(self, silent=False):
141 """ 143 """
142 Public method to get the workspace directory. 144 Public method to get the workspace directory.
143 145
144 @param silent flag indicating silent operations 146 @param silent flag indicating silent operations
145 @type bool 147 @type bool
146 @return workspace directory used for saving files 148 @return workspace directory used for saving files
147 @rtype str 149 @rtype str
148 """ 150 """
149 # Attempts to find the path on the filesystem that represents the 151 if self.__workspace:
150 # plugged in CIRCUITPY board. 152 # return cached entry
151 deviceDirectory = Utilities.findVolume(self.DeviceVolumeName) 153 return self.__workspace
152 154 else:
153 if deviceDirectory: 155 self.__workspace = self.__findWorkspace(silent=silent)
154 return deviceDirectory 156 return self.__workspace
157
158 def __findWorkspace(self, silent=False):
159 """
160 Public method to find the workspace directory.
161
162 @param silent flag indicating silent operations
163 @type bool
164 @return workspace directory used for saving files
165 @rtype str
166 """
167 # Attempts to find the paths on the filesystem that represents the
168 # plugged in CIRCUITPY boards.
169 deviceDirectories = Utilities.findVolume(self.DeviceVolumeName,
170 all=True)
171
172 if deviceDirectories:
173 if len(deviceDirectories) == 1:
174 return deviceDirectories[0]
175 else:
176 return self.selectDeviceDirectory(deviceDirectories)
155 else: 177 else:
156 # return the default workspace and give the user a warning (unless 178 # return the default workspace and give the user a warning (unless
157 # silent mode is selected) 179 # silent mode is selected)
158 if not silent: 180 if not silent:
159 E5MessageBox.warning( 181 E5MessageBox.warning(

eric ide

mercurial