|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2020 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to show the application routes. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtCore import pyqtSlot, QProcess |
|
11 from PyQt5.QtWidgets import QDialog |
|
12 |
|
13 from E5Gui import E5MessageBox |
|
14 |
|
15 from .Ui_RoutesDialog import Ui_RoutesDialog |
|
16 |
|
17 |
|
18 class RoutesDialog(QDialog, Ui_RoutesDialog): |
|
19 """ |
|
20 Class implementing a dialog to show the application routes. |
|
21 """ |
|
22 def __init__(self, parent=None): |
|
23 """ |
|
24 Constructor |
|
25 |
|
26 @param parent reference to the parent widget |
|
27 @type QWidget |
|
28 """ |
|
29 super(RoutesDialog, self).__init__(parent) |
|
30 self.setupUi(self) |
|
31 |
|
32 self.__process = None |
|
33 |
|
34 def showRoutes(self, project): |
|
35 """ |
|
36 Public method to show the list of routes. |
|
37 |
|
38 @param project reference to the project object |
|
39 @type Project |
|
40 @return flag indicating success |
|
41 @rtype bool |
|
42 """ |
|
43 workdir, env = project.prepareRuntimeEnvironment() |
|
44 if env is not None: |
|
45 command = project.getFlaskCommand() |
|
46 |
|
47 self.__process = QProcess() |
|
48 self.__process.setProcessEnvironment(env) |
|
49 self.__process.setWorkingDirectory(workdir) |
|
50 self.__process.setProcessChannelMode(QProcess.MergedChannels) |
|
51 |
|
52 args = ["routes"] |
|
53 if self.matchButton.isChecked(): |
|
54 sortorder = "match" |
|
55 elif self.endpointButton.isChecked(): |
|
56 sortorder = "endpoint" |
|
57 elif self.methodsButton.isChecked(): |
|
58 sortorder = "methods" |
|
59 elif self.ruleButton.isChecked(): |
|
60 sortorder = "rule" |
|
61 else: |
|
62 sortorder = "" |
|
63 if sortorder: |
|
64 args += ["--sort", sortorder] |
|
65 if self.allMethodsCheckBox.isChecked(): |
|
66 args.append("--all-methods") |
|
67 |
|
68 self.__process.start(command, args) |
|
69 ok = self.__process.waitForStarted(10000) |
|
70 if ok: |
|
71 ok = self.__process.waitForFinished(10000) |
|
72 if ok: |
|
73 out = str(self.__process.readAllStandardOutput(), "utf-8") |
|
74 self.__processOutput(out) |
|
75 else: |
|
76 E5MessageBox.critical( |
|
77 None, |
|
78 self.tr("Flask Routes"), |
|
79 self.tr("""The Flask process did not finish within""" |
|
80 """ 10 seconds.""")) |
|
81 else: |
|
82 E5MessageBox.critical( |
|
83 None, |
|
84 self.tr("Run Flask Server"), |
|
85 self.tr("""The Flask process could not be started.""")) |
|
86 return ok |
|
87 else: |
|
88 return False |
|
89 |
|
90 def __processOutput(self, output): |
|
91 """ |
|
92 Private method to process the flask output and populate the routes |
|
93 list. |
|
94 |
|
95 @param output output of the flask process |
|
96 @type str |
|
97 """ |
|
98 self.routesList.clear() |
|
99 |
|
100 # split output into lines |
|
101 # determine field width based on second line |
|
102 # split each line based on widths and populate list |
|
103 print(output) |
|
104 |
|
105 @pyqtSlot(bool) |
|
106 def on_matchButton_toggled(self, checked): |
|
107 """ |
|
108 Slot documentation goes here. |
|
109 |
|
110 @param checked DESCRIPTION |
|
111 @type bool |
|
112 """ |
|
113 # TODO: not implemented yet |
|
114 pass |
|
115 |
|
116 @pyqtSlot(bool) |
|
117 def on_endpointButton_toggled(self, checked): |
|
118 """ |
|
119 Slot documentation goes here. |
|
120 |
|
121 @param checked DESCRIPTION |
|
122 @type bool |
|
123 """ |
|
124 # TODO: not implemented yet |
|
125 pass |
|
126 |
|
127 @pyqtSlot(bool) |
|
128 def on_methodsButton_toggled(self, checked): |
|
129 """ |
|
130 Slot documentation goes here. |
|
131 |
|
132 @param checked DESCRIPTION |
|
133 @type bool |
|
134 """ |
|
135 # TODO: not implemented yet |
|
136 pass |
|
137 |
|
138 @pyqtSlot(bool) |
|
139 def on_ruleButton_toggled(self, checked): |
|
140 """ |
|
141 Slot documentation goes here. |
|
142 |
|
143 @param checked DESCRIPTION |
|
144 @type bool |
|
145 """ |
|
146 # TODO: not implemented yet |
|
147 pass |
|
148 |
|
149 @pyqtSlot(bool) |
|
150 def on_allMethodsCheckBox_toggled(self, checked): |
|
151 """ |
|
152 Slot documentation goes here. |
|
153 |
|
154 @param checked DESCRIPTION |
|
155 @type bool |
|
156 """ |
|
157 # TODO: not implemented yet |
|
158 pass |