eric6/MicroPython/MicroPythonFileManagerWidget.py

branch
micropython
changeset 7088
e29b0ee86b29
parent 7084
3eddfc540614
child 7089
9f9816b19aa4
--- a/eric6/MicroPython/MicroPythonFileManagerWidget.py	Sat Jul 27 15:43:21 2019 +0200
+++ b/eric6/MicroPython/MicroPythonFileManagerWidget.py	Sat Jul 27 17:02:01 2019 +0200
@@ -36,6 +36,7 @@
 import UI.PixmapCache
 import Preferences
 import Utilities
+import Globals
 
 
 class MicroPythonFileManagerWidget(QWidget, Ui_MicroPythonFileManagerWidget):
@@ -84,10 +85,13 @@
         self.__fileManager.removeDirectoryDone.connect(self.__newDeviceList)
         self.__fileManager.createDirectoryDone.connect(self.__newDeviceList)
         self.__fileManager.deleteFileDone.connect(self.__newDeviceList)
+        self.__fileManager.fsinfoDone.connect(self.__shownFsInfoResult)
         self.__fileManager.synchTimeDone.connect(self.__timeSynchronized)
         self.__fileManager.showTimeDone.connect(self.__deviceTimeReceived)
         self.__fileManager.showVersionDone.connect(
             self.__deviceVersionReceived)
+        self.__fileManager.showImplementationDone.connect(
+            self.__deviceImplementationReceived)
         
         self.__fileManager.error.connect(self.__handleError)
         
@@ -124,21 +128,31 @@
             self.tr("Delete File"), self.__deleteDeviceFile)
         self.__deviceMenu.addSeparator()
         self.__deviceMenu.addAction(
+            self.tr("Show Filesystem Info"), self.__showFileSystemInfo)
+        self.__deviceMenu.addSeparator()
+        self.__deviceMenu.addAction(
             self.tr("Synchronize Time"), self.__synchronizeTime)
         self.__deviceMenu.addAction(
             self.tr("Show Time"), self.__showDeviceTime)
         self.__deviceMenu.addSeparator()
         self.__deviceMenu.addAction(
             self.tr("Show Version"), self.__showDeviceVersion)
+        self.__deviceMenu.addAction(
+            self.tr("Show Implementation"), self.__showImplementation)
     
     def start(self):
         """
         Public method to start the widget.
         """
-        self.__fileManager.connect()
+        ui = e5App().getObject("UserInterface")
+        vm = e5App().getObject("ViewManager")
+        
+        ui.preferencesChanged.connect(
+            self.__fileManager.handlePreferencesChanged)
+        
+        self.__fileManager.connectToDevice()
         
         dirname = ""
-        vm = e5App().getObject("ViewManager")
         aw = vm.activeWindow()
         if aw:
             dirname = os.path.dirname(aw.getFileName())
@@ -153,7 +167,11 @@
         """
         Public method to stop the widget.
         """
-        self.__fileManager.disconnect()
+        ui = e5App().getObject("UserInterface")
+        ui.preferencesChanged.disconnect(
+            self.__fileManager.handlePreferencesChanged)
+        
+        self.__fileManager.disconnectFromDevice()
     
     @pyqtSlot(str, str)
     def __handleError(self, method, error):
@@ -522,7 +540,6 @@
             self.localCwd.setText(dirPath)
             self.__listLocalFiles(dirPath)
     
-    # TODO: test this
     @pyqtSlot()
     def __createLocalDirectory(self):
         """
@@ -537,6 +554,7 @@
             dirPath = os.path.join(self.localCwd.text(), dirPath)
             try:
                 os.mkdir(dirPath)
+                self.__listLocalFiles(self.localCwd.text())
             except (OSError, IOError) as exc:
                 E5MessageBox.critical(
                     self,
@@ -546,7 +564,6 @@
                         dirPath, str(exc))
                 )
     
-    # TODO: test this
     @pyqtSlot()
     def __deleteLocalDirectoryTree(self):
         """
@@ -564,6 +581,7 @@
             if dlg.exec_() == QDialog.Accepted:
                 try:
                     shutil.rmtree(dirname)
+                    self.__listLocalFiles(self.localCwd.text())
                 except Exception as exc:
                     E5MessageBox.critical(
                         self,
@@ -573,7 +591,6 @@
                             dirname, str(exc))
                     )
     
-    # TODO: test this
     @pyqtSlot()
     def __deleteLocalFile(self):
         """
@@ -591,6 +608,7 @@
             if dlg.exec_() == QDialog.Accepted:
                 try:
                     os.remove(filename)
+                    self.__listLocalFiles(self.localCwd.text())
                 except (OSError, IOError) as exc:
                     E5MessageBox.critical(
                         self,
@@ -600,7 +618,6 @@
                             filename, str(exc))
                     )
    
-    # TODO: test this
     @pyqtSlot()
     def __showLocalTime(self):
         """
@@ -665,7 +682,6 @@
                 dirPath = self.deviceCwd.text() + "/" + dirPath
             self.__fileManager.cd(dirPath)
     
-    # TODO: test this
     @pyqtSlot()
     def __createDeviceDirectory(self):
         """
@@ -679,7 +695,6 @@
         if ok and dirPath:
             self.__fileManager.mkdir(dirPath)
     
-    # TODO: test this
     @pyqtSlot()
     def __deleteDeviceDirectory(self):
         """
@@ -733,6 +748,41 @@
                 self.__fileManager.delete(filename)
     
     @pyqtSlot()
+    def __showFileSystemInfo(self):
+        """
+        Private slot to show some file system information.
+        """
+        self.__fileManager.fileSystemInfo()
+    
+    @pyqtSlot(tuple)
+    def __shownFsInfoResult(self, fsinfo):
+        """
+        Private slot to show the file systom information of the device.
+        
+        @param fsinfo tuple of tuples containing the file system name, the
+            total size, the used size and the free size
+        @type tuple of tuples of (str, int, int, int)
+        """
+        msg = self.tr("<h3>Filesystem Information</h3>")
+        for name, totalSize, usedSize, freeSize in fsinfo:
+            msg += self.tr(
+                "<h4>{0}</h4"
+                "<table>"
+                "<tr><td>Total Size: </td><td align='right'>{1}</td></tr>"
+                "<tr><td>Used Size: </td><td align='right'>{2}</td></tr>"
+                "<tr><td>Free Size: </td><td align='right'>{3}</td></tr>"
+                "</table>"
+            ).format(name,
+                     Globals.dataString(totalSize),
+                     Globals.dataString(usedSize),
+                     Globals.dataString(freeSize),
+            )
+        E5MessageBox.information(
+            self,
+            self.tr("Filesystem Information"),
+            msg)
+    
+    @pyqtSlot()
     def __synchronizeTime(self):
         """
         Private slot to synchronize the local time to the device.
@@ -814,3 +864,29 @@
             self,
             self.tr("Device Version Information"),
             msg)
+    
+    @pyqtSlot()
+    def __showImplementation(self):
+        """
+        Private slot to show some implementation related information.
+        """
+        self.__fileManager.showImplementation()
+    
+    @pyqtSlot(str, str)
+    def __deviceImplementationReceived(self, name, version):
+        """
+        Privat slot handling the receipt of implementation info.
+        
+        @param name name of the implementation
+        @type str
+        @param version version string of the implementation
+        @type str
+        """
+        E5MessageBox.information(
+            self,
+            self.tr("Device Implementation Information"),
+            self.tr(
+                "<h3>Device Implementation Information</h3>"
+                "<p>This device contains <b>{0} {1}</b>.</p>"
+            ).format(name, version)
+        )

eric ide

mercurial