eric6/MicroPython/PyBoardDevices.py

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

eric ide

mercurial