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, QProcess |
10 from PyQt5.QtCore import pyqtSlot, Qt, QProcess |
11 from PyQt5.QtWidgets import QDialog |
11 from PyQt5.QtGui import QGuiApplication |
|
12 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem |
12 |
13 |
13 from E5Gui import E5MessageBox |
14 from E5Gui import E5MessageBox |
14 |
15 |
15 from .Ui_RoutesDialog import Ui_RoutesDialog |
16 from .Ui_RoutesDialog import Ui_RoutesDialog |
16 |
17 |
17 |
18 |
18 class RoutesDialog(QDialog, Ui_RoutesDialog): |
19 class RoutesDialog(QDialog, Ui_RoutesDialog): |
19 """ |
20 """ |
20 Class implementing a dialog to show the application routes. |
21 Class implementing a dialog to show the application routes. |
21 """ |
22 """ |
22 def __init__(self, parent=None): |
23 def __init__(self, project, parent=None): |
23 """ |
24 """ |
24 Constructor |
25 Constructor |
25 |
26 |
|
27 @param project reference to the project object |
|
28 @type Project |
26 @param parent reference to the parent widget |
29 @param parent reference to the parent widget |
27 @type QWidget |
30 @type QWidget |
28 """ |
31 """ |
29 super(RoutesDialog, self).__init__(parent) |
32 super(RoutesDialog, self).__init__(parent) |
30 self.setupUi(self) |
33 self.setupUi(self) |
31 |
34 |
|
35 self.__refreshButton = self.buttonBox.addButton( |
|
36 self.tr("Refresh"), QDialogButtonBox.ActionRole) |
|
37 self.__refreshButton.clicked.connect(self.showRoutes) |
|
38 |
|
39 self.__project = project |
32 self.__process = None |
40 self.__process = None |
33 |
41 |
34 def showRoutes(self, project): |
42 def showRoutes(self): |
35 """ |
43 """ |
36 Public method to show the list of routes. |
44 Public method to show the list of routes. |
37 |
45 |
38 @param project reference to the project object |
|
39 @type Project |
|
40 @return flag indicating success |
46 @return flag indicating success |
41 @rtype bool |
47 @rtype bool |
42 """ |
48 """ |
43 workdir, env = project.prepareRuntimeEnvironment() |
49 workdir, env = self.__project.prepareRuntimeEnvironment() |
44 if env is not None: |
50 if env is not None: |
45 command = project.getFlaskCommand() |
51 command = self.__project.getFlaskCommand() |
46 |
52 |
47 self.__process = QProcess() |
53 self.__process = QProcess() |
48 self.__process.setProcessEnvironment(env) |
54 self.__process.setProcessEnvironment(env) |
49 self.__process.setWorkingDirectory(workdir) |
55 self.__process.setWorkingDirectory(workdir) |
50 self.__process.setProcessChannelMode(QProcess.MergedChannels) |
56 self.__process.setProcessChannelMode(QProcess.MergedChannels) |
63 if sortorder: |
69 if sortorder: |
64 args += ["--sort", sortorder] |
70 args += ["--sort", sortorder] |
65 if self.allMethodsCheckBox.isChecked(): |
71 if self.allMethodsCheckBox.isChecked(): |
66 args.append("--all-methods") |
72 args.append("--all-methods") |
67 |
73 |
|
74 QGuiApplication.setOverrideCursor(Qt.WaitCursor) |
68 self.__process.start(command, args) |
75 self.__process.start(command, args) |
69 ok = self.__process.waitForStarted(10000) |
76 ok = self.__process.waitForStarted(10000) |
70 if ok: |
77 if ok: |
71 ok = self.__process.waitForFinished(10000) |
78 ok = self.__process.waitForFinished(10000) |
72 if ok: |
79 if ok: |
81 else: |
88 else: |
82 E5MessageBox.critical( |
89 E5MessageBox.critical( |
83 None, |
90 None, |
84 self.tr("Run Flask Server"), |
91 self.tr("Run Flask Server"), |
85 self.tr("""The Flask process could not be started.""")) |
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() |
86 return ok |
96 return ok |
87 else: |
97 else: |
88 return False |
98 return False |
89 |
99 |
90 def __processOutput(self, output): |
100 def __processOutput(self, output): |
95 @param output output of the flask process |
105 @param output output of the flask process |
96 @type str |
106 @type str |
97 """ |
107 """ |
98 self.routesList.clear() |
108 self.routesList.clear() |
99 |
109 |
100 # split output into lines |
110 lines = output.splitlines() |
101 # determine field width based on second line |
111 widths = [len(part) for part in lines[1].split()] |
102 # split each line based on widths and populate list |
112 for line in lines[2:]: |
103 print(output) |
113 parts = [] |
|
114 for width in widths: |
|
115 parts.append(line[:width].strip()) |
|
116 line = line[width:].lstrip() |
|
117 |
|
118 QTreeWidgetItem(self.routesList, parts) |
104 |
119 |
105 @pyqtSlot(bool) |
120 @pyqtSlot(bool) |
106 def on_matchButton_toggled(self, checked): |
121 def on_matchButton_toggled(self, checked): |
107 """ |
122 """ |
108 Slot documentation goes here. |
123 Private slot handling the selection of the 'match' sort order. |
109 |
124 |
110 @param checked DESCRIPTION |
125 @param checked state of the button |
111 @type bool |
126 @type bool |
112 """ |
127 """ |
113 # TODO: not implemented yet |
128 if checked: |
114 pass |
129 self.showRoutes() |
115 |
130 |
116 @pyqtSlot(bool) |
131 @pyqtSlot(bool) |
117 def on_endpointButton_toggled(self, checked): |
132 def on_endpointButton_toggled(self, checked): |
118 """ |
133 """ |
119 Slot documentation goes here. |
134 Private slot handling the selection of the 'endpoint' sort order. |
120 |
135 |
121 @param checked DESCRIPTION |
136 @param checked state of the button |
122 @type bool |
137 @type bool |
123 """ |
138 """ |
124 # TODO: not implemented yet |
139 if checked: |
125 pass |
140 self.showRoutes() |
126 |
141 |
127 @pyqtSlot(bool) |
142 @pyqtSlot(bool) |
128 def on_methodsButton_toggled(self, checked): |
143 def on_methodsButton_toggled(self, checked): |
129 """ |
144 """ |
130 Slot documentation goes here. |
145 Private slot handling the selection of the 'methods' sort order. |
131 |
146 |
132 @param checked DESCRIPTION |
147 @param checked state of the button |
133 @type bool |
148 @type bool |
134 """ |
149 """ |
135 # TODO: not implemented yet |
150 if checked: |
136 pass |
151 self.showRoutes() |
137 |
152 |
138 @pyqtSlot(bool) |
153 @pyqtSlot(bool) |
139 def on_ruleButton_toggled(self, checked): |
154 def on_ruleButton_toggled(self, checked): |
140 """ |
155 """ |
141 Slot documentation goes here. |
156 Private slot handling the selection of the 'rule' sort order. |
142 |
157 |
143 @param checked DESCRIPTION |
158 @param checked state of the button |
144 @type bool |
159 @type bool |
145 """ |
160 """ |
146 # TODO: not implemented yet |
161 if checked: |
147 pass |
162 self.showRoutes() |
148 |
163 |
149 @pyqtSlot(bool) |
164 @pyqtSlot(bool) |
150 def on_allMethodsCheckBox_toggled(self, checked): |
165 def on_allMethodsCheckBox_toggled(self, checked): |
151 """ |
166 """ |
152 Slot documentation goes here. |
167 Private slot handling the selection to show all methods. |
153 |
168 |
154 @param checked DESCRIPTION |
169 @param checked state of the button |
155 @type bool |
170 @type bool |
156 """ |
171 """ |
157 # TODO: not implemented yet |
172 self.showRoutes() |
158 pass |
|