ProjectFlask/RoutesDialog.py

branch
eric7
changeset 70
22e1d0f69668
parent 66
0d3168d0e310
child 72
4557829a4acf
equal deleted inserted replaced
69:c31a4f756a04 70:22e1d0f69668
18 18
19 class RoutesDialog(QDialog, Ui_RoutesDialog): 19 class RoutesDialog(QDialog, Ui_RoutesDialog):
20 """ 20 """
21 Class implementing a dialog to show the application routes. 21 Class implementing a dialog to show the application routes.
22 """ 22 """
23
23 def __init__(self, project, parent=None): 24 def __init__(self, project, parent=None):
24 """ 25 """
25 Constructor 26 Constructor
26 27
27 @param project reference to the project object 28 @param project reference to the project object
28 @type Project 29 @type Project
29 @param parent reference to the parent widget 30 @param parent reference to the parent widget
30 @type QWidget 31 @type QWidget
31 """ 32 """
32 super().__init__(parent) 33 super().__init__(parent)
33 self.setupUi(self) 34 self.setupUi(self)
34 35
35 self.__refreshButton = self.buttonBox.addButton( 36 self.__refreshButton = self.buttonBox.addButton(
36 self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole) 37 self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole
38 )
37 self.__refreshButton.clicked.connect(self.showRoutes) 39 self.__refreshButton.clicked.connect(self.showRoutes)
38 40
39 self.__project = project 41 self.__project = project
40 self.__process = None 42 self.__process = None
41 43
42 def showRoutes(self): 44 def showRoutes(self):
43 """ 45 """
44 Public method to show the list of routes. 46 Public method to show the list of routes.
45 47
46 @return flag indicating success 48 @return flag indicating success
47 @rtype bool 49 @rtype bool
48 """ 50 """
49 workdir, env = self.__project.prepareRuntimeEnvironment() 51 workdir, env = self.__project.prepareRuntimeEnvironment()
50 if env is not None: 52 if env is not None:
51 command = self.__project.getFlaskCommand() 53 command = self.__project.getFlaskCommand()
52 54
53 self.__process = QProcess() 55 self.__process = QProcess()
54 self.__process.setProcessEnvironment(env) 56 self.__process.setProcessEnvironment(env)
55 self.__process.setWorkingDirectory(workdir) 57 self.__process.setWorkingDirectory(workdir)
56 self.__process.setProcessChannelMode( 58 self.__process.setProcessChannelMode(
57 QProcess.ProcessChannelMode.MergedChannels) 59 QProcess.ProcessChannelMode.MergedChannels
58 60 )
61
59 args = ["routes"] 62 args = ["routes"]
60 if self.matchButton.isChecked(): 63 if self.matchButton.isChecked():
61 sortorder = "match" 64 sortorder = "match"
62 elif self.endpointButton.isChecked(): 65 elif self.endpointButton.isChecked():
63 sortorder = "endpoint" 66 sortorder = "endpoint"
69 sortorder = "" 72 sortorder = ""
70 if sortorder: 73 if sortorder:
71 args += ["--sort", sortorder] 74 args += ["--sort", sortorder]
72 if self.allMethodsCheckBox.isChecked(): 75 if self.allMethodsCheckBox.isChecked():
73 args.append("--all-methods") 76 args.append("--all-methods")
74 77
75 with EricOverrideCursor(): 78 with EricOverrideCursor():
76 self.__process.start(command, args) 79 self.__process.start(command, args)
77 ok = self.__process.waitForStarted(10000) 80 ok = self.__process.waitForStarted(10000)
78 if ok: 81 if ok:
79 ok = self.__process.waitForFinished(10000) 82 ok = self.__process.waitForFinished(10000)
80 if ok: 83 if ok:
81 out = str(self.__process.readAllStandardOutput(), 84 out = str(self.__process.readAllStandardOutput(), "utf-8")
82 "utf-8")
83 self.__processOutput(out) 85 self.__processOutput(out)
84 else: 86 else:
85 with EricOverridenCursor(): 87 with EricOverridenCursor():
86 EricMessageBox.critical( 88 EricMessageBox.critical(
87 None, 89 None,
88 self.tr("Flask Routes"), 90 self.tr("Flask Routes"),
89 self.tr("""The Flask process did not finish""" 91 self.tr(
90 """ within 10 seconds.""")) 92 """The Flask process did not finish"""
93 """ within 10 seconds."""
94 ),
95 )
91 else: 96 else:
92 with EricOverridenCursor(): 97 with EricOverridenCursor():
93 EricMessageBox.critical( 98 EricMessageBox.critical(
94 None, 99 None,
95 self.tr("Flask Routes"), 100 self.tr("Flask Routes"),
96 self.tr("""The Flask process could not be""" 101 self.tr(
97 """ started.""")) 102 """The Flask process could not be""" """ started."""
103 ),
104 )
98 for column in range(self.routesList.columnCount()): 105 for column in range(self.routesList.columnCount()):
99 self.routesList.resizeColumnToContents(column) 106 self.routesList.resizeColumnToContents(column)
100 return ok 107 return ok
101 else: 108 else:
102 return False 109 return False
103 110
104 def __processOutput(self, output): 111 def __processOutput(self, output):
105 """ 112 """
106 Private method to process the flask output and populate the routes 113 Private method to process the flask output and populate the routes
107 list. 114 list.
108 115
109 @param output output of the flask process 116 @param output output of the flask process
110 @type str 117 @type str
111 """ 118 """
112 self.routesList.clear() 119 self.routesList.clear()
113 120
114 lines = output.splitlines() 121 lines = output.splitlines()
115 widths = [] 122 widths = []
116 for line in lines: 123 for line in lines:
117 if not widths: 124 if not widths:
118 continue 125 continue
122 else: 129 else:
123 parts = [] 130 parts = []
124 for width in widths: 131 for width in widths:
125 parts.append(line[:width].strip()) 132 parts.append(line[:width].strip())
126 line = line[width:].lstrip() 133 line = line[width:].lstrip()
127 134
128 QTreeWidgetItem(self.routesList, parts) 135 QTreeWidgetItem(self.routesList, parts)
129 136
130 @pyqtSlot(bool) 137 @pyqtSlot(bool)
131 def on_matchButton_toggled(self, checked): 138 def on_matchButton_toggled(self, checked):
132 """ 139 """
133 Private slot handling the selection of the 'match' sort order. 140 Private slot handling the selection of the 'match' sort order.
134 141
135 @param checked state of the button 142 @param checked state of the button
136 @type bool 143 @type bool
137 """ 144 """
138 if checked: 145 if checked:
139 self.showRoutes() 146 self.showRoutes()
140 147
141 @pyqtSlot(bool) 148 @pyqtSlot(bool)
142 def on_endpointButton_toggled(self, checked): 149 def on_endpointButton_toggled(self, checked):
143 """ 150 """
144 Private slot handling the selection of the 'endpoint' sort order. 151 Private slot handling the selection of the 'endpoint' sort order.
145 152
146 @param checked state of the button 153 @param checked state of the button
147 @type bool 154 @type bool
148 """ 155 """
149 if checked: 156 if checked:
150 self.showRoutes() 157 self.showRoutes()
151 158
152 @pyqtSlot(bool) 159 @pyqtSlot(bool)
153 def on_methodsButton_toggled(self, checked): 160 def on_methodsButton_toggled(self, checked):
154 """ 161 """
155 Private slot handling the selection of the 'methods' sort order. 162 Private slot handling the selection of the 'methods' sort order.
156 163
157 @param checked state of the button 164 @param checked state of the button
158 @type bool 165 @type bool
159 """ 166 """
160 if checked: 167 if checked:
161 self.showRoutes() 168 self.showRoutes()
162 169
163 @pyqtSlot(bool) 170 @pyqtSlot(bool)
164 def on_ruleButton_toggled(self, checked): 171 def on_ruleButton_toggled(self, checked):
165 """ 172 """
166 Private slot handling the selection of the 'rule' sort order. 173 Private slot handling the selection of the 'rule' sort order.
167 174
168 @param checked state of the button 175 @param checked state of the button
169 @type bool 176 @type bool
170 """ 177 """
171 if checked: 178 if checked:
172 self.showRoutes() 179 self.showRoutes()
173 180
174 @pyqtSlot(bool) 181 @pyqtSlot(bool)
175 def on_allMethodsCheckBox_toggled(self, checked): 182 def on_allMethodsCheckBox_toggled(self, checked):
176 """ 183 """
177 Private slot handling the selection to show all methods. 184 Private slot handling the selection to show all methods.
178 185
179 @param checked state of the button 186 @param checked state of the button
180 @type bool 187 @type bool
181 """ 188 """
182 self.showRoutes() 189 self.showRoutes()

eric ide

mercurial