ProjectFlask/RoutesDialog.py

branch
eric7
changeset 64
0ee58185b8df
parent 61
fe1e8783a95f
child 66
0d3168d0e310
--- a/ProjectFlask/RoutesDialog.py	Sat May 29 15:04:41 2021 +0200
+++ b/ProjectFlask/RoutesDialog.py	Sun May 30 17:33:37 2021 +0200
@@ -7,11 +7,11 @@
 Module implementing a dialog to show the application routes.
 """
 
-from PyQt5.QtCore import pyqtSlot, Qt, QProcess
-from PyQt5.QtGui import QGuiApplication
-from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem
+from PyQt6.QtCore import pyqtSlot, QProcess
+from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem
 
-from E5Gui import E5MessageBox
+from EricGui.EricOverrideCursor import EricOverrideCursor, EricOverridenCursor
+from EricWidgets import EricMessageBox
 
 from .Ui_RoutesDialog import Ui_RoutesDialog
 
@@ -33,7 +33,7 @@
         self.setupUi(self)
         
         self.__refreshButton = self.buttonBox.addButton(
-            self.tr("Refresh"), QDialogButtonBox.ActionRole)
+            self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole)
         self.__refreshButton.clicked.connect(self.showRoutes)
         
         self.__project = project
@@ -53,7 +53,8 @@
             self.__process = QProcess()
             self.__process.setProcessEnvironment(env)
             self.__process.setWorkingDirectory(workdir)
-            self.__process.setProcessChannelMode(QProcess.MergedChannels)
+            self.__process.setProcessChannelMode(
+                QProcess.ProcessChannelMode.MergedChannels)
             
             args = ["routes"]
             if self.matchButton.isChecked():
@@ -71,28 +72,31 @@
             if self.allMethodsCheckBox.isChecked():
                 args.append("--all-methods")
             
-            QGuiApplication.setOverrideCursor(Qt.WaitCursor)
-            self.__process.start(command, args)
-            ok = self.__process.waitForStarted(10000)
-            if ok:
-                ok = self.__process.waitForFinished(10000)
+            with EricOverrideCursor():
+                self.__process.start(command, args)
+                ok = self.__process.waitForStarted(10000)
                 if ok:
-                    out = str(self.__process.readAllStandardOutput(), "utf-8")
-                    self.__processOutput(out)
+                    ok = self.__process.waitForFinished(10000)
+                    if ok:
+                        out = str(self.__process.readAllStandardOutput(),
+                                  "utf-8")
+                        self.__processOutput(out)
+                    else:
+                        with EricOverridenCursor():
+                            EricMessageBox.critical(
+                                None,
+                                self.tr("Flask Routes"),
+                                self.tr("""The Flask process did not finish"""
+                                        """ within 10 seconds."""))
                 else:
-                    E5MessageBox.critical(
-                        None,
-                        self.tr("Flask Routes"),
-                        self.tr("""The Flask process did not finish within"""
-                                """ 10 seconds."""))
-            else:
-                E5MessageBox.critical(
-                    None,
-                    self.tr("Flask Routes"),
-                    self.tr("""The Flask process could not be started."""))
-            for column in range(self.routesList.columnCount()):
-                self.routesList.resizeColumnToContents(column)
-            QGuiApplication.restoreOverrideCursor()
+                    with EricOverridenCursor():
+                        EricMessageBox.critical(
+                            None,
+                            self.tr("Flask Routes"),
+                            self.tr("""The Flask process could not be"""
+                                    """ started."""))
+                for column in range(self.routesList.columnCount()):
+                    self.routesList.resizeColumnToContents(column)
             return ok
         else:
             return False
@@ -108,14 +112,20 @@
         self.routesList.clear()
         
         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)
+        widths = []
+        for line in lines:
+            if not widths:
+                continue
+            elif line.lstrip().startswith("--"):
+                widths = [len(part) for part in line.split()]
+                continue
+            else:
+                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):

eric ide

mercurial