eric6/MicroPython/MicroPythonFileManagerWidget.py

changeset 8067
a467ab075be0
parent 8058
9769eb548f0d
child 8143
2c730d5fd177
equal deleted inserted replaced
8066:1208cdae96b6 8067:a467ab075be0
62 self.putButton.setIcon(UI.PixmapCache.getIcon("1rightarrow")) 62 self.putButton.setIcon(UI.PixmapCache.getIcon("1rightarrow"))
63 self.putAsButton.setIcon(UI.PixmapCache.getIcon("putAs")) 63 self.putAsButton.setIcon(UI.PixmapCache.getIcon("putAs"))
64 self.getButton.setIcon(UI.PixmapCache.getIcon("1leftarrow")) 64 self.getButton.setIcon(UI.PixmapCache.getIcon("1leftarrow"))
65 self.getAsButton.setIcon(UI.PixmapCache.getIcon("getAs")) 65 self.getAsButton.setIcon(UI.PixmapCache.getIcon("getAs"))
66 self.localUpButton.setIcon(UI.PixmapCache.getIcon("1uparrow")) 66 self.localUpButton.setIcon(UI.PixmapCache.getIcon("1uparrow"))
67 self.localHomeButton.setIcon(UI.PixmapCache.getIcon("home"))
67 self.localReloadButton.setIcon(UI.PixmapCache.getIcon("reload")) 68 self.localReloadButton.setIcon(UI.PixmapCache.getIcon("reload"))
68 self.deviceUpButton.setIcon(UI.PixmapCache.getIcon("1uparrow")) 69 self.deviceUpButton.setIcon(UI.PixmapCache.getIcon("1uparrow"))
70 self.deviceHomeButton.setIcon(UI.PixmapCache.getIcon("home"))
69 self.deviceReloadButton.setIcon(UI.PixmapCache.getIcon("reload")) 71 self.deviceReloadButton.setIcon(UI.PixmapCache.getIcon("reload"))
70 72
71 self.deviceUpButton.setEnabled(not self.__repl.isMicrobit()) 73 self.deviceUpButton.setEnabled(not self.__repl.isMicrobit())
74 self.deviceHomeButton.setEnabled(not self.__repl.isMicrobit())
72 75
73 self.putButton.setEnabled(False) 76 self.putButton.setEnabled(False)
74 self.putAsButton.setEnabled(False) 77 self.putAsButton.setEnabled(False)
75 self.getButton.setEnabled(False) 78 self.getButton.setEnabled(False)
76 self.getAsButton.setEnabled(False) 79 self.getAsButton.setEnabled(False)
152 vm = e5App().getObject("ViewManager") 155 vm = e5App().getObject("ViewManager")
153 aw = vm.activeWindow() 156 aw = vm.activeWindow()
154 if aw: 157 if aw:
155 dirname = os.path.dirname(aw.getFileName()) 158 dirname = os.path.dirname(aw.getFileName())
156 if not dirname: 159 if not dirname:
157 dirname = (Preferences.getMultiProject("Workspace") or 160 dirname = (
158 os.path.expanduser("~")) 161 Preferences.getMicroPython("MpyWorkspace") or
162 Preferences.getMultiProject("Workspace") or
163 os.path.expanduser("~")
164 )
159 self.__listLocalFiles(dirname) 165 self.__listLocalFiles(dirname)
160 166
161 if self.__deviceWithLocalAccess: 167 if self.__deviceWithLocalAccess:
162 dirname = self.__repl.getDeviceWorkspace() 168 dirname = self.__repl.getDeviceWorkspace()
163 if dirname: 169 if dirname:
164 self.__listLocalFiles(dirname, True) 170 self.__listLocalFiles(dirname, True)
165 else: 171 return
166 self.__fileManager.pwd() 172
173 # list files via device script
174 self.__fileManager.pwd()
167 175
168 def stop(self): 176 def stop(self):
169 """ 177 """
170 Public method to stop the widget. 178 Public method to stop the widget.
171 """ 179 """
296 cwd = self.localCwd.text() 304 cwd = self.localCwd.text()
297 dirname = os.path.dirname(cwd) 305 dirname = os.path.dirname(cwd)
298 self.__listLocalFiles(dirname) 306 self.__listLocalFiles(dirname)
299 307
300 @pyqtSlot() 308 @pyqtSlot()
309 def on_localHomeButton_clicked(self):
310 """
311 Private slot to change directory to the configured workspace.
312 """
313 dirname = (
314 Preferences.getMicroPython("MpyWorkspace") or
315 Preferences.getMultiProject("Workspace") or
316 os.path.expanduser("~")
317 )
318 self.__listLocalFiles(dirname)
319
320 @pyqtSlot()
301 def on_localReloadButton_clicked(self): 321 def on_localReloadButton_clicked(self):
302 """ 322 """
303 Private slot to reload the local list. 323 Private slot to reload the local list.
304 """ 324 """
305 dirname = self.localCwd.text() 325 dirname = self.localCwd.text()
316 @param item reference to the activated item 336 @param item reference to the activated item
317 @type QTreeWidgetItem 337 @type QTreeWidgetItem
318 @param column column of the activation 338 @param column column of the activation
319 @type int 339 @type int
320 """ 340 """
321 name = os.path.join(self.deviceCwd.text(), item.text(0))
322 if self.__deviceWithLocalAccess: 341 if self.__deviceWithLocalAccess:
342 name = os.path.join(self.deviceCwd.text(), item.text(0))
323 if name.endswith("/"): 343 if name.endswith("/"):
324 # directory names end with a '/' 344 # directory names end with a '/'
325 self.__listLocalFiles(name[:-1], True) 345 self.__listLocalFiles(name[:-1], True)
326 elif Utilities.MimeTypes.isTextFile(name): 346 elif Utilities.MimeTypes.isTextFile(name):
327 e5App().getObject("ViewManager").getEditor(name) 347 e5App().getObject("ViewManager").getEditor(name)
328 else: 348 else:
349 cwd = self.deviceCwd.text()
350 if cwd.endswith("/"):
351 name = cwd + item.text(0)
352 else:
353 name = "{0}/{1}".format(cwd, item.text(0))
329 if name.endswith("/"): 354 if name.endswith("/"):
330 # directory names end with a '/' 355 # directory names end with a '/'
331 self.__fileManager.cd(name[:-1]) 356 self.__fileManager.cd(name[:-1])
332 357
333 @pyqtSlot() 358 @pyqtSlot()
352 dirname = os.path.dirname(cwd) 377 dirname = os.path.dirname(cwd)
353 if self.__deviceWithLocalAccess: 378 if self.__deviceWithLocalAccess:
354 self.__listLocalFiles(dirname, True) 379 self.__listLocalFiles(dirname, True)
355 else: 380 else:
356 self.__fileManager.cd(dirname) 381 self.__fileManager.cd(dirname)
382
383 @pyqtSlot()
384 def on_deviceHomeButton_clicked(self):
385 """
386 Private slot to move to the device home directory.
387 """
388 if self.__deviceWithLocalAccess:
389 dirname = self.__repl.getDeviceWorkspace()
390 if dirname:
391 self.__listLocalFiles(dirname, True)
392 return
393
394 # list files via device script
395 self.__fileManager.cd("/")
357 396
358 @pyqtSlot() 397 @pyqtSlot()
359 def on_deviceReloadButton_clicked(self): 398 def on_deviceReloadButton_clicked(self):
360 """ 399 """
361 Private slot to reload the device list. 400 Private slot to reload the device list.

eric ide

mercurial