eric6/MicroPython/MicroPythonFileManagerWidget.py

branch
micropython
changeset 7083
217862c28319
parent 7082
ec199ef0cfc6
child 7084
3eddfc540614
--- a/eric6/MicroPython/MicroPythonFileManagerWidget.py	Wed Jul 24 20:12:19 2019 +0200
+++ b/eric6/MicroPython/MicroPythonFileManagerWidget.py	Thu Jul 25 19:55:40 2019 +0200
@@ -18,6 +18,7 @@
 
 from E5Gui import E5MessageBox, E5PathPickerDialog
 from E5Gui.E5PathPicker import E5PathPickerModes
+from E5Gui.E5FileSaveConfirmDialog import confirmOverwrite
 from E5Gui.E5Application import e5App
 
 from .Ui_MicroPythonFileManagerWidget import Ui_MicroPythonFileManagerWidget
@@ -62,6 +63,7 @@
         self.deviceFileTreeWidget.header().setSortIndicator(
             0, Qt.AscendingOrder)
         
+        self.__progressInfoDialog = None
         self.__fileManager = MicroPythonFileManager(port, self)
         
         self.__fileManager.longListFiles.connect(self.__handleLongListFiles)
@@ -71,6 +73,8 @@
         self.__fileManager.getFileDone.connect(self.__handleGetDone)
         self.__fileManager.rsyncDone.connect(self.__handleRsyncDone)
         self.__fileManager.rsyncMessages.connect(self.__handleRsyncMessages)
+        self.__fileManager.rsyncProgressMessage.connect(
+            self.__handleRsyncProgressMessage)
         self.__fileManager.removeDirectoryDone.connect(self.__newDeviceList)
         self.__fileManager.createDirectoryDone.connect(self.__newDeviceList)
         self.__fileManager.deleteFileDone.connect(self.__newDeviceList)
@@ -89,6 +93,8 @@
         self.__localMenu = QMenu(self)
         self.__localMenu.addAction(self.tr("Change Directory"),
                                    self.__changeLocalDirectory)
+        # TODO: add some more local entries
+        # TODO: add entry to reload
         
         self.__deviceMenu = QMenu(self)
         self.__deviceMenu.addAction(
@@ -103,6 +109,8 @@
         self.__devDelFileAct = self.__deviceMenu.addAction(
             self.tr("Delete File"), self.__deleteDeviceFile)
         self.__deviceMenu.addSeparator()
+        # TODO: add entry to reload
+        self.__deviceMenu.addSeparator()
         self.__deviceMenu.addAction(
             self.tr("Synchronize Time"), self.__synchronizeTime)
         self.__deviceMenu.addAction(
@@ -319,24 +327,18 @@
                 # it is really a file
                 if self.__isFileInList(filename, self.deviceFileTreeWidget):
                     # ask for overwrite permission
-                    ok = E5MessageBox.yesNo(
-                        self,
-                        self.tr("Copy File to Device"),
-                        self.tr("<p>The file <b>{0}</b> exists on the"
-                                " connected device. Overwrite it?</p>")
-                        .format(filename)
-                    )
-                    if ok:
+                    # TODO: test this
+                    action, resultFilename = confirmOverwrite(
+                        filename, self.tr("Copy File to Device"),
+                        self.tr("The given file exists already"
+                                " (Enter file name only)."),
+                        False, self)
+                    if action == "cancel":
+                        return
+                    elif action == "rename":
+                        deviceFilename = os.path.basename(resultFilename)
+                    else:
                         deviceFilename = filename
-                    else:
-                        deviceFilename, ok = QInputDialog.getText(
-                            self,
-                            self.tr("Copy File to Device"),
-                            self.tr("Enter a new name:"),
-                            QLineEdit.Normal,
-                            filename)
-                        if not ok or not bool(deviceFilename):
-                            return
                 else:
                     deviceFilename = filename
                 
@@ -357,30 +359,26 @@
                 # it is really a file
                 if self.__isFileInList(filename, self.localFileTreeWidget):
                     # ask for overwrite permission
-                    ok = E5MessageBox.yesNo(
-                        self,
-                        self.tr("Copy File from Device"),
-                        self.tr("<p>The file <b>{0}</b> exists locally."
-                                " Overwrite it?</p>")
-                        .format(filename)
-                    )
-                    if ok:
+                    # TODO: test this
+                    action, resultFilename = confirmOverwrite(
+                        filename, self.tr("Copy File from Device"),
+                        self.tr("The given file exists already."),
+                        True, self)
+                    if action == "cancel":
+                        return
+                    elif action == "rename":
+                        localFilename = resultFilename
+                    else:
                         localFilename = filename
-                    else:
-                        localFilename, ok = QInputDialog.getText(
-                            self,
-                            self.tr("Copy File from Device"),
-                            self.tr("Enter a new name:"),
-                            QLineEdit.Normal,
-                            filename)
-                        if not ok or not bool(localFilename):
-                            return
                 else:
                     localFilename = filename
                 
+                if not os.path.isabs(localFilename):
+                    localFilename = os.path.join(self.localCwd.text(),
+                                                 localFilename)
                 self.__fileManager.get(
                     os.path.join(self.deviceCwd.text(), filename),
-                    os.path.join(self.localCwd.text(), localFilename)
+                    localFilename
                 )
     
     @pyqtSlot(str, str)
@@ -395,6 +393,7 @@
         """
         self.__listLocalFiles(self.localCwd.text())
     
+    # TODO: test this
     @pyqtSlot()
     def on_syncButton_clicked(self):
         """
@@ -436,6 +435,16 @@
             )
         )
     
+    @pyqtSlot(str)
+    def __handleRsyncProgressMessage(self, message):
+        """
+        Private slot handling progress messages sent by the file manager.
+        """
+        # TODO: not implemented yet
+        #   create and open the info dialog, if it is None
+        #   connect to the dialog finished(int) signal to set the memeber variable to None
+        #   add messages to dialog
+    
     @pyqtSlot()
     def __newDeviceList(self):
         """
@@ -462,16 +471,18 @@
         """
         Private slot to change the local directory.
         """
-        path, ok = E5PathPickerDialog.getPath(
+        dirPath, ok = E5PathPickerDialog.getPath(
             self,
             self.tr("Change Directory"),
             self.tr("Select Directory"),
             E5PathPickerModes.DirectoryShowFilesMode,
             defaultDirectory=self.localCwd.text(),
         )
-        if ok and path:
-            self.localCwd.setText(path)
-            self.__listLocalFiles(path)
+        if ok and dirPath:
+            if not os.path.isabs(dirPath):
+                dirPath = os.path.join(self.localCwd.text(), dirPath)
+            self.localCwd.setText(dirPath)
+            self.__listLocalFiles(dirPath)
     
     ##################################################################
     ## Context menu methods for the device files below
@@ -510,12 +521,15 @@
         dirPath, ok = QInputDialog.getText(
             self,
             self.tr("Change Directory"),
-            self.tr("Enter the full directory path on the device:"),
+            self.tr("Enter the directory path on the device:"),
             QLineEdit.Normal,
             self.deviceCwd.text())
         if ok and dirPath:
+            if not dirPath.startswith("/"):
+                dirPath = self.deviceCwd.text() + "/" + dirPath
             self.__fileManager.cd(dirPath)
     
+    # TODO: test this
     @pyqtSlot()
     def __createDeviceDirectory(self):
         """
@@ -529,6 +543,7 @@
         if ok and dirPath:
             self.__fileManager.mkdir(dirPath)
     
+    # TODO: test this
     @pyqtSlot()
     def __deleteDeviceDirectory(self):
         """
@@ -537,6 +552,7 @@
         if bool(len(self.deviceFileTreeWidget.selectedItems())):
             name = self.deviceFileTreeWidget.selectedItems()[0].text(0)
             dirname = self.deviceCwd.text() + "/" + name[:-1]
+            # TODO: add confirmation
             self.__fileManager.rmdir(dirname)
     
     @pyqtSlot()
@@ -548,6 +564,7 @@
         if bool(len(self.deviceFileTreeWidget.selectedItems())):
             name = self.deviceFileTreeWidget.selectedItems()[0].text(0)
             dirname = self.deviceCwd.text() + "/" + name[:-1]
+            # TODO: add confirmation
             self.__fileManager.rmdir(dirname, recursive=True)
     
     @pyqtSlot()
@@ -558,6 +575,7 @@
         if bool(len(self.deviceFileTreeWidget.selectedItems())):
             name = self.deviceFileTreeWidget.selectedItems()[0].text(0)
             filename = self.deviceCwd.text() + "/" + name
+            # TODO: add confirmation
             self.__fileManager.delete(filename)
     
     @pyqtSlot()
@@ -634,7 +652,7 @@
             msg += "<table>"
             for key, value in versionInfo.items():
                 msg += "<tr><td><b>{0}</b></td><td>{1}</td></tr>".format(
-                    key, value)
+                    key.capitalize(), value)
             msg += "</table>"
         else:
             msg = self.tr("No version information available.")

eric ide

mercurial