eric6/MicroPython/MicrobitDevices.py

changeset 8067
a467ab075be0
parent 8062
8dc5acb30a8b
child 8071
408756e389d0
equal deleted inserted replaced
8066:1208cdae96b6 8067:a467ab075be0
40 @type QObject 40 @type QObject
41 """ 41 """
42 super(MicrobitDevice, self).__init__(microPythonWidget, parent) 42 super(MicrobitDevice, self).__init__(microPythonWidget, parent)
43 43
44 self.__deviceType = deviceType 44 self.__deviceType = deviceType
45
46 self.__workspace = self.__findWorkspace()
47 45
48 def setButtons(self): 46 def setButtons(self):
49 """ 47 """
50 Public method to enable the supported action buttons. 48 Public method to enable the supported action buttons.
51 """ 49 """
124 @return tuple containing a flag indicating it is safe to start a 122 @return tuple containing a flag indicating it is safe to start a
125 File Manager and a reason why it cannot. 123 File Manager and a reason why it cannot.
126 @rtype tuple of (bool, str) 124 @rtype tuple of (bool, str)
127 """ 125 """
128 return True, "" 126 return True, ""
129
130 def getWorkspace(self):
131 """
132 Public method to get the workspace directory.
133
134 @return workspace directory used for saving files
135 @rtype str
136 """
137 if self.__workspace:
138 # return cached entry
139 return self.__workspace
140 else:
141 self.__workspace = self.__findWorkspace()
142 return self.__workspace
143
144 def __findWorkspace(self):
145 """
146 Public method to find the workspace directory.
147
148 @return workspace directory used for saving files
149 @rtype str
150 """
151 # Attempts to find the path on the filesystem that represents the
152 # plugged in MICROBIT or MINI board.
153 if self.__deviceType == "bbc_microbit":
154 # BBC micro:bit
155 deviceDirectories = Utilities.findVolume("MICROBIT", all=True)
156 else:
157 # Calliope mini
158 deviceDirectories = Utilities.findVolume("MINI", all=True)
159
160 if deviceDirectories:
161 if len(deviceDirectories) == 1:
162 return deviceDirectories[0]
163 else:
164 return self.selectDeviceDirectory(deviceDirectories)
165 else:
166 # return the default workspace and give the user a warning
167 E5MessageBox.warning(
168 self.microPython,
169 self.tr("Workspace Directory"),
170 self.tr("Could not find an attached {0}.\n\n"
171 "Please make sure the device is plugged "
172 "into this computer.").format(self.deviceName()))
173
174 return super(MicrobitDevice, self).getWorkspace()
175 127
176 def hasTimeCommands(self): 128 def hasTimeCommands(self):
177 """ 129 """
178 Public method to check, if the device supports time commands. 130 Public method to check, if the device supports time commands.
179 131
228 # in maintenance mode, for MicroPython in standard mode. 180 # in maintenance mode, for MicroPython in standard mode.
229 if self.__deviceType == "bbc_microbit": 181 if self.__deviceType == "bbc_microbit":
230 # BBC micro:bit 182 # BBC micro:bit
231 if firmware: 183 if firmware:
232 deviceDirectories = Utilities.findVolume("MAINTENANCE", 184 deviceDirectories = Utilities.findVolume("MAINTENANCE",
233 all=True) 185 findAll=True)
234 else: 186 else:
235 deviceDirectories = Utilities.findVolume("MICROBIT", 187 deviceDirectories = Utilities.findVolume("MICROBIT",
236 all=True) 188 findAll=True)
237 else: 189 else:
238 # Calliope mini 190 # Calliope mini
239 if firmware: 191 if firmware:
240 deviceDirectories = Utilities.findVolume("MAINTENANCE", 192 deviceDirectories = Utilities.findVolume("MAINTENANCE",
241 all=True) 193 findAll=True)
242 else: 194 else:
243 deviceDirectories = Utilities.findVolume("MINI", all=True) 195 deviceDirectories = Utilities.findVolume("MINI",
196 findAll=True)
244 if len(deviceDirectories) == 0: 197 if len(deviceDirectories) == 0:
245 if self.__deviceType == "bbc_microbit": 198 if self.__deviceType == "bbc_microbit":
246 # BBC micro:bit is not ready or not mounted 199 # BBC micro:bit is not ready or not mounted
247 if firmware: 200 if firmware:
248 E5MessageBox.critical( 201 E5MessageBox.critical(

eric ide

mercurial