ProjectFlask/RoutesDialog.py

changeset 8
cfbd3a2757fd
parent 7
a140b2a8ba93
child 35
65a377b7a52c
diff -r a140b2a8ba93 -r cfbd3a2757fd ProjectFlask/RoutesDialog.py
--- a/ProjectFlask/RoutesDialog.py	Thu Nov 12 19:43:14 2020 +0100
+++ b/ProjectFlask/RoutesDialog.py	Fri Nov 13 19:51:28 2020 +0100
@@ -7,8 +7,9 @@
 Module implementing a dialog to show the application routes.
 """
 
-from PyQt5.QtCore import pyqtSlot, QProcess
-from PyQt5.QtWidgets import QDialog
+from PyQt5.QtCore import pyqtSlot, Qt, QProcess
+from PyQt5.QtGui import QGuiApplication
+from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem
 
 from E5Gui import E5MessageBox
 
@@ -19,30 +20,35 @@
     """
     Class implementing a dialog to show the application routes.
     """
-    def __init__(self, parent=None):
+    def __init__(self, project, parent=None):
         """
         Constructor
         
+        @param project reference to the project object
+        @type Project
         @param parent reference to the parent widget
         @type QWidget
         """
         super(RoutesDialog, self).__init__(parent)
         self.setupUi(self)
         
+        self.__refreshButton = self.buttonBox.addButton(
+            self.tr("Refresh"), QDialogButtonBox.ActionRole)
+        self.__refreshButton.clicked.connect(self.showRoutes)
+        
+        self.__project = project
         self.__process = None
     
-    def showRoutes(self, project):
+    def showRoutes(self):
         """
         Public method to show the list of routes.
         
-        @param project reference to the project object
-        @type Project
         @return flag indicating success
         @rtype bool
         """
-        workdir, env = project.prepareRuntimeEnvironment()
+        workdir, env = self.__project.prepareRuntimeEnvironment()
         if env is not None:
-            command = project.getFlaskCommand()
+            command = self.__project.getFlaskCommand()
             
             self.__process = QProcess()
             self.__process.setProcessEnvironment(env)
@@ -65,6 +71,7 @@
             if self.allMethodsCheckBox.isChecked():
                 args.append("--all-methods")
             
+            QGuiApplication.setOverrideCursor(Qt.WaitCursor)
             self.__process.start(command, args)
             ok = self.__process.waitForStarted(10000)
             if ok:
@@ -83,6 +90,9 @@
                     None,
                     self.tr("Run Flask Server"),
                     self.tr("""The Flask process could not be started."""))
+            for column in range(self.routesList.columnCount()):
+                self.routesList.resizeColumnToContents(column)
+            QGuiApplication.restoreOverrideCursor()
             return ok
         else:
             return False
@@ -97,62 +107,66 @@
         """
         self.routesList.clear()
         
-        # split output into lines
-        # determine field width based on second line
-        # split each line based on widths and populate list
-        print(output)
+        lines = output.splitlines()
+        widths = [len(part) for part in lines[1].split()]
+        for line in lines[2:]:
+            parts = []
+            for width in widths:
+                parts.append(line[:width].strip())
+                line = line[width:].lstrip()
+                
+            QTreeWidgetItem(self.routesList, parts)
     
     @pyqtSlot(bool)
     def on_matchButton_toggled(self, checked):
         """
-        Slot documentation goes here.
+        Private slot handling the selection of the 'match' sort order.
         
-        @param checked DESCRIPTION
+        @param checked state of the button
         @type bool
         """
-        # TODO: not implemented yet
-        pass
+        if checked:
+            self.showRoutes()
     
     @pyqtSlot(bool)
     def on_endpointButton_toggled(self, checked):
         """
-        Slot documentation goes here.
+        Private slot handling the selection of the 'endpoint' sort order.
         
-        @param checked DESCRIPTION
+        @param checked state of the button
         @type bool
         """
-        # TODO: not implemented yet
-        pass
+        if checked:
+            self.showRoutes()
     
     @pyqtSlot(bool)
     def on_methodsButton_toggled(self, checked):
         """
-        Slot documentation goes here.
+        Private slot handling the selection of the 'methods' sort order.
         
-        @param checked DESCRIPTION
+        @param checked state of the button
         @type bool
         """
-        # TODO: not implemented yet
-        pass
+        if checked:
+            self.showRoutes()
     
     @pyqtSlot(bool)
     def on_ruleButton_toggled(self, checked):
         """
-        Slot documentation goes here.
+        Private slot handling the selection of the 'rule' sort order.
         
-        @param checked DESCRIPTION
+        @param checked state of the button
         @type bool
         """
-        # TODO: not implemented yet
-        pass
+        if checked:
+            self.showRoutes()
     
     @pyqtSlot(bool)
     def on_allMethodsCheckBox_toggled(self, checked):
         """
-        Slot documentation goes here.
+        Private slot handling the selection to show all methods.
         
-        @param checked DESCRIPTION
+        @param checked state of the button
         @type bool
         """
-        # TODO: not implemented yet
-        pass
+        self.showRoutes()

eric ide

mercurial