42 class MicroPythonFileManagerWidget(QWidget, Ui_MicroPythonFileManagerWidget): |
42 class MicroPythonFileManagerWidget(QWidget, Ui_MicroPythonFileManagerWidget): |
43 """ |
43 """ |
44 Class implementing a file manager for MicroPython devices. |
44 Class implementing a file manager for MicroPython devices. |
45 """ |
45 """ |
46 |
46 |
47 def __init__(self, commandsInterface, deviceWithLocalAccess, parent=None): |
47 def __init__(self, device, parent=None): |
48 """ |
48 """ |
49 Constructor |
49 Constructor |
50 |
50 |
51 @param commandsInterface reference to the commands interface object |
51 @param device MicroPython device object |
52 @type MicroPythonCommandsInterface |
52 @type BaseDevice |
53 @param deviceWithLocalAccess flag indicating the device supports file |
|
54 access via a local directory |
|
55 @type bool |
|
56 @param parent reference to the parent widget |
53 @param parent reference to the parent widget |
57 @type QWidget |
54 @type QWidget |
58 """ |
55 """ |
59 super().__init__(parent) |
56 super().__init__(parent) |
60 self.setupUi(self) |
57 self.setupUi(self) |
61 |
58 |
62 self.__repl = parent |
59 self.__repl = parent |
63 self.__deviceWithLocalAccess = deviceWithLocalAccess |
60 self.__deviceWithLocalAccess = device.supportsLocalFileAccess() |
64 |
61 |
65 self.syncButton.setIcon(EricPixmapCache.getIcon("2rightarrow")) |
62 self.syncButton.setIcon(EricPixmapCache.getIcon("2rightarrow")) |
66 self.putButton.setIcon(EricPixmapCache.getIcon("1rightarrow")) |
63 self.putButton.setIcon(EricPixmapCache.getIcon("1rightarrow")) |
67 self.putAsButton.setIcon(EricPixmapCache.getIcon("putAs")) |
64 self.putAsButton.setIcon(EricPixmapCache.getIcon("putAs")) |
68 self.getButton.setIcon(EricPixmapCache.getIcon("1leftarrow")) |
65 self.getButton.setIcon(EricPixmapCache.getIcon("1leftarrow")) |
94 self.deviceFileTreeWidget.header().setSortIndicator( |
91 self.deviceFileTreeWidget.header().setSortIndicator( |
95 0, Qt.SortOrder.AscendingOrder |
92 0, Qt.SortOrder.AscendingOrder |
96 ) |
93 ) |
97 |
94 |
98 self.__progressInfoDialog = None |
95 self.__progressInfoDialog = None |
99 self.__fileManager = MicroPythonFileManager(commandsInterface, self) |
96 self.__fileManager = MicroPythonFileManager(device, self) |
100 |
97 |
101 self.__fileManager.longListFiles.connect(self.__handleLongListFiles) |
98 self.__fileManager.longListFiles.connect(self.__handleLongListFiles) |
102 self.__fileManager.currentDir.connect(self.__handleCurrentDir) |
99 self.__fileManager.currentDir.connect(self.__handleCurrentDir) |
103 self.__fileManager.currentDirChanged.connect(self.__handleCurrentDir) |
100 self.__fileManager.currentDirChanged.connect(self.__handleCurrentDir) |
104 self.__fileManager.putFileDone.connect(self.__newDeviceList) |
101 self.__fileManager.putFileDone.connect(self.__newDeviceList) |
380 cwd = self.deviceCwd.text() |
377 cwd = self.deviceCwd.text() |
381 if cwd: |
378 if cwd: |
382 name = ( |
379 name = ( |
383 cwd + item.text(0) |
380 cwd + item.text(0) |
384 if cwd.endswith("/") |
381 if cwd.endswith("/") |
385 else"{0}/{1}".format(cwd, item.text(0)) |
382 else "{0}/{1}".format(cwd, item.text(0)) |
386 ) |
383 ) |
387 else: |
384 else: |
388 name = item.text(0) |
385 name = item.text(0) |
389 if name.endswith("/"): |
386 if name.endswith("/"): |
390 # directory names end with a '/' |
387 # directory names end with a '/' |
391 self.__fileManager.cd(name[:-1]) |
388 self.__fileManager.cd(name[:-1]) |
392 else: |
389 else: |
393 data = self.__fileManager.getData(name) |
390 data = self.__fileManager.getData(name) |
394 text = data.decode(encoding = "utf-8") |
391 text = data.decode(encoding="utf-8") |
395 ericApp().getObject("ViewManager").newEditorWithText( |
392 ericApp().getObject("ViewManager").newEditorWithText( |
396 text, "Python3", "device:{0}".format(name) |
393 text, "Python3", "device:{0}".format(name) |
397 ) |
394 ) |
398 |
395 |
399 @pyqtSlot() |
396 @pyqtSlot() |
686 cwd = self.deviceCwd.text() |
683 cwd = self.deviceCwd.text() |
687 if cwd: |
684 if cwd: |
688 name = ( |
685 name = ( |
689 cwd + filename |
686 cwd + filename |
690 if cwd.endswith("/") |
687 if cwd.endswith("/") |
691 else"{0}/{1}".format(cwd, filename) |
688 else "{0}/{1}".format(cwd, filename) |
692 ) |
689 ) |
693 else: |
690 else: |
694 name = filename |
691 name = filename |
695 if not name.endswith("/"): |
692 if not name.endswith("/"): |
696 data = self.__fileManager.getData(name) |
693 data = self.__fileManager.getData(name) |
697 text = data.decode(encoding = "utf-8") |
694 text = data.decode(encoding="utf-8") |
698 ericApp().getObject("ViewManager").newEditorWithText( |
695 ericApp().getObject("ViewManager").newEditorWithText( |
699 text, "Python3", "device:{0}".format(name) |
696 text, "Python3", "device:{0}".format(name) |
700 ) |
697 ) |
701 |
698 |
702 @pyqtSlot() |
699 @pyqtSlot() |
703 def on_saveButton_clicked(self, saveAs=False): |
700 def on_saveButton_clicked(self, saveAs=False): |
704 """ |
701 """ |
705 Private slot to save the text of the current editor to a file on the device. |
702 Private slot to save the text of the current editor to a file on the device. |
|
703 |
|
704 @param saveAs flag indicating to save the file with a new name |
|
705 @type bool |
706 """ |
706 """ |
707 aw = ericApp().getObject("ViewManager").activeWindow() |
707 aw = ericApp().getObject("ViewManager").activeWindow() |
708 if not aw: |
708 if not aw: |
709 return |
709 return |
710 |
710 |
737 if saveAs and self.__isFileInList(filename, self.deviceFileTreeWidget): |
737 if saveAs and self.__isFileInList(filename, self.deviceFileTreeWidget): |
738 # ask for overwrite permission |
738 # ask for overwrite permission |
739 action, resultFilename = confirmOverwrite( |
739 action, resultFilename = confirmOverwrite( |
740 filename, |
740 filename, |
741 self.tr("Save File As"), |
741 self.tr("Save File As"), |
742 self.tr( |
742 self.tr("The given file exists already (Enter file name only)."), |
743 "The given file exists already (Enter file name only)." |
|
744 ), |
|
745 False, |
743 False, |
746 self, |
744 self, |
747 ) |
745 ) |
748 if action == "cancel": |
746 if action == "cancel": |
749 return |
747 return |