5 |
5 |
6 """ |
6 """ |
7 Module implementing a dialog to show the application routes. |
7 Module implementing a dialog to show the application routes. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt5.QtCore import pyqtSlot, Qt, QProcess |
10 from PyQt6.QtCore import pyqtSlot, QProcess |
11 from PyQt5.QtGui import QGuiApplication |
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem |
12 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem |
|
13 |
12 |
14 from E5Gui import E5MessageBox |
13 from EricGui.EricOverrideCursor import EricOverrideCursor, EricOverridenCursor |
|
14 from EricWidgets import EricMessageBox |
15 |
15 |
16 from .Ui_RoutesDialog import Ui_RoutesDialog |
16 from .Ui_RoutesDialog import Ui_RoutesDialog |
17 |
17 |
18 |
18 |
19 class RoutesDialog(QDialog, Ui_RoutesDialog): |
19 class RoutesDialog(QDialog, Ui_RoutesDialog): |
31 """ |
31 """ |
32 super().__init__(parent) |
32 super().__init__(parent) |
33 self.setupUi(self) |
33 self.setupUi(self) |
34 |
34 |
35 self.__refreshButton = self.buttonBox.addButton( |
35 self.__refreshButton = self.buttonBox.addButton( |
36 self.tr("Refresh"), QDialogButtonBox.ActionRole) |
36 self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole) |
37 self.__refreshButton.clicked.connect(self.showRoutes) |
37 self.__refreshButton.clicked.connect(self.showRoutes) |
38 |
38 |
39 self.__project = project |
39 self.__project = project |
40 self.__process = None |
40 self.__process = None |
41 |
41 |
51 command = self.__project.getFlaskCommand() |
51 command = self.__project.getFlaskCommand() |
52 |
52 |
53 self.__process = QProcess() |
53 self.__process = QProcess() |
54 self.__process.setProcessEnvironment(env) |
54 self.__process.setProcessEnvironment(env) |
55 self.__process.setWorkingDirectory(workdir) |
55 self.__process.setWorkingDirectory(workdir) |
56 self.__process.setProcessChannelMode(QProcess.MergedChannels) |
56 self.__process.setProcessChannelMode( |
|
57 QProcess.ProcessChannelMode.MergedChannels) |
57 |
58 |
58 args = ["routes"] |
59 args = ["routes"] |
59 if self.matchButton.isChecked(): |
60 if self.matchButton.isChecked(): |
60 sortorder = "match" |
61 sortorder = "match" |
61 elif self.endpointButton.isChecked(): |
62 elif self.endpointButton.isChecked(): |
69 if sortorder: |
70 if sortorder: |
70 args += ["--sort", sortorder] |
71 args += ["--sort", sortorder] |
71 if self.allMethodsCheckBox.isChecked(): |
72 if self.allMethodsCheckBox.isChecked(): |
72 args.append("--all-methods") |
73 args.append("--all-methods") |
73 |
74 |
74 QGuiApplication.setOverrideCursor(Qt.WaitCursor) |
75 with EricOverrideCursor(): |
75 self.__process.start(command, args) |
76 self.__process.start(command, args) |
76 ok = self.__process.waitForStarted(10000) |
77 ok = self.__process.waitForStarted(10000) |
77 if ok: |
|
78 ok = self.__process.waitForFinished(10000) |
|
79 if ok: |
78 if ok: |
80 out = str(self.__process.readAllStandardOutput(), "utf-8") |
79 ok = self.__process.waitForFinished(10000) |
81 self.__processOutput(out) |
80 if ok: |
|
81 out = str(self.__process.readAllStandardOutput(), |
|
82 "utf-8") |
|
83 self.__processOutput(out) |
|
84 else: |
|
85 with EricOverridenCursor(): |
|
86 EricMessageBox.critical( |
|
87 None, |
|
88 self.tr("Flask Routes"), |
|
89 self.tr("""The Flask process did not finish""" |
|
90 """ within 10 seconds.""")) |
82 else: |
91 else: |
83 E5MessageBox.critical( |
92 with EricOverridenCursor(): |
84 None, |
93 EricMessageBox.critical( |
85 self.tr("Flask Routes"), |
94 None, |
86 self.tr("""The Flask process did not finish within""" |
95 self.tr("Flask Routes"), |
87 """ 10 seconds.""")) |
96 self.tr("""The Flask process could not be""" |
88 else: |
97 """ started.""")) |
89 E5MessageBox.critical( |
98 for column in range(self.routesList.columnCount()): |
90 None, |
99 self.routesList.resizeColumnToContents(column) |
91 self.tr("Flask Routes"), |
|
92 self.tr("""The Flask process could not be started.""")) |
|
93 for column in range(self.routesList.columnCount()): |
|
94 self.routesList.resizeColumnToContents(column) |
|
95 QGuiApplication.restoreOverrideCursor() |
|
96 return ok |
100 return ok |
97 else: |
101 else: |
98 return False |
102 return False |
99 |
103 |
100 def __processOutput(self, output): |
104 def __processOutput(self, output): |
106 @type str |
110 @type str |
107 """ |
111 """ |
108 self.routesList.clear() |
112 self.routesList.clear() |
109 |
113 |
110 lines = output.splitlines() |
114 lines = output.splitlines() |
111 widths = [len(part) for part in lines[1].split()] |
115 widths = [] |
112 for line in lines[2:]: |
116 for line in lines: |
113 parts = [] |
117 if not widths: |
114 for width in widths: |
118 continue |
115 parts.append(line[:width].strip()) |
119 elif line.lstrip().startswith("--"): |
116 line = line[width:].lstrip() |
120 widths = [len(part) for part in line.split()] |
117 |
121 continue |
118 QTreeWidgetItem(self.routesList, parts) |
122 else: |
|
123 parts = [] |
|
124 for width in widths: |
|
125 parts.append(line[:width].strip()) |
|
126 line = line[width:].lstrip() |
|
127 |
|
128 QTreeWidgetItem(self.routesList, parts) |
119 |
129 |
120 @pyqtSlot(bool) |
130 @pyqtSlot(bool) |
121 def on_matchButton_toggled(self, checked): |
131 def on_matchButton_toggled(self, checked): |
122 """ |
132 """ |
123 Private slot handling the selection of the 'match' sort order. |
133 Private slot handling the selection of the 'match' sort order. |