Finished implementing the "flask routes" function.

Fri, 13 Nov 2020 19:51:28 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 13 Nov 2020 19:51:28 +0100
changeset 8
cfbd3a2757fd
parent 7
a140b2a8ba93
child 9
79094fb72c18

Finished implementing the "flask routes" function.

ProjectFlask/Project.py file | annotate | diff | comparison | revisions
ProjectFlask/RoutesDialog.py file | annotate | diff | comparison | revisions
--- a/ProjectFlask/Project.py	Thu Nov 12 19:43:14 2020 +0100
+++ b/ProjectFlask/Project.py	Fri Nov 13 19:51:28 2020 +0100
@@ -212,8 +212,9 @@
         """
         Public method to handle the closing of a project.
         """
-        if self.__serverDialog is not None:
-            self.__serverDialog.close()
+        for dlg in (self.__serverDialog, self.__routesDialog):
+            if dlg is not None:
+                dlg.close()
 ##        if self.__serverProc is not None:
 ##            self.__serverProcFinished()
     
@@ -475,11 +476,10 @@
         """
         Private slot showing all URL dispatch routes.
         """
-        # TODO: implement this (flask routes)
         if self.__routesDialog is not None:
             self.__routesDialog.close()
         
-        dlg = RoutesDialog()
-        if dlg.showRoutes(self):
+        dlg = RoutesDialog(self)
+        if dlg.showRoutes():
             dlg.show()
             self.__routesDialog = dlg
--- 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