|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2002 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Start Program dialog. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QComboBox, QInputDialog |
|
13 |
|
14 from E5Gui.E5PathPicker import E5PathPickerModes |
|
15 from E5Gui.E5Application import e5App |
|
16 |
|
17 import Preferences |
|
18 |
|
19 |
|
20 class StartDialog(QDialog): |
|
21 """ |
|
22 Class implementing the Start Program dialog. |
|
23 |
|
24 It implements a dialog that is used to start an |
|
25 application for debugging. It asks the user to enter |
|
26 the commandline parameters, the working directory and |
|
27 whether exception reporting should be disabled. |
|
28 """ |
|
29 def __init__(self, caption, lastUsedVenvName, argvList, wdList, envList, |
|
30 exceptions, |
|
31 parent=None, dialogType=0, modfuncList=None, |
|
32 tracePython=False, autoClearShell=True, autoContinue=True, |
|
33 autoFork=False, forkChild=False): |
|
34 """ |
|
35 Constructor |
|
36 |
|
37 @param caption the caption to be displayed |
|
38 @type str |
|
39 @param lastUsedVenvName name of the most recently used virtual |
|
40 environment |
|
41 @type str |
|
42 @param argvList history list of command line arguments |
|
43 @type list of str |
|
44 @param wdList history list of working directories |
|
45 @type list of str |
|
46 @param envList history list of environment parameter settings |
|
47 @type list of str |
|
48 @param exceptions exception reporting flag |
|
49 @type bool |
|
50 @param parent parent widget of this dialog |
|
51 @type QWidget |
|
52 @param dialogType type of the start dialog |
|
53 <ul> |
|
54 <li>0 = start debug dialog</li> |
|
55 <li>1 = start run dialog</li> |
|
56 <li>2 = start coverage dialog</li> |
|
57 <li>3 = start profile dialog</li> |
|
58 </ul> |
|
59 @type int (0 to 3) |
|
60 @keyparam modfuncList history list of module functions |
|
61 @type list of str |
|
62 @keyparam tracePython flag indicating if the Python library should |
|
63 be traced as well |
|
64 @type bool |
|
65 @keyparam autoClearShell flag indicating, that the interpreter window |
|
66 should be cleared automatically |
|
67 @type bool |
|
68 @keyparam autoContinue flag indicating, that the debugger should not |
|
69 stop at the first executable line |
|
70 @type bool |
|
71 @keyparam autoFork flag indicating the automatic fork mode |
|
72 @type bool |
|
73 @keyparam forkChild flag indicating to debug the child after forking |
|
74 @type bool |
|
75 """ |
|
76 super(StartDialog, self).__init__(parent) |
|
77 self.setModal(True) |
|
78 |
|
79 self.dialogType = dialogType |
|
80 if dialogType == 0: |
|
81 from .Ui_StartDebugDialog import Ui_StartDebugDialog |
|
82 self.ui = Ui_StartDebugDialog() |
|
83 elif dialogType == 1: |
|
84 from .Ui_StartRunDialog import Ui_StartRunDialog |
|
85 self.ui = Ui_StartRunDialog() |
|
86 elif dialogType == 2: |
|
87 from .Ui_StartCoverageDialog import Ui_StartCoverageDialog |
|
88 self.ui = Ui_StartCoverageDialog() |
|
89 elif dialogType == 3: |
|
90 from .Ui_StartProfileDialog import Ui_StartProfileDialog |
|
91 self.ui = Ui_StartProfileDialog() |
|
92 self.ui.setupUi(self) |
|
93 |
|
94 self.ui.venvComboBox.addItem("") |
|
95 self.ui.venvComboBox.addItems( |
|
96 sorted(e5App().getObject("VirtualEnvManager") |
|
97 .getVirtualenvNames())) |
|
98 |
|
99 self.ui.workdirPicker.setMode(E5PathPickerModes.DirectoryMode) |
|
100 self.ui.workdirPicker.setDefaultDirectory( |
|
101 Preferences.getMultiProject("Workspace")) |
|
102 self.ui.workdirPicker.setInsertPolicy(QComboBox.InsertAtTop) |
|
103 self.ui.workdirPicker.setSizeAdjustPolicy( |
|
104 QComboBox.AdjustToMinimumContentsLength) |
|
105 |
|
106 self.clearButton = self.ui.buttonBox.addButton( |
|
107 self.tr("Clear Histories"), QDialogButtonBox.ActionRole) |
|
108 self.editButton = self.ui.buttonBox.addButton( |
|
109 self.tr("Edit History"), QDialogButtonBox.ActionRole) |
|
110 |
|
111 self.setWindowTitle(caption) |
|
112 self.ui.cmdlineCombo.clear() |
|
113 self.ui.cmdlineCombo.addItems(argvList) |
|
114 if len(argvList) > 0: |
|
115 self.ui.cmdlineCombo.setCurrentIndex(0) |
|
116 self.ui.workdirPicker.clear() |
|
117 self.ui.workdirPicker.addItems(wdList) |
|
118 if len(wdList) > 0: |
|
119 self.ui.workdirPicker.setCurrentIndex(0) |
|
120 self.ui.environmentCombo.clear() |
|
121 self.ui.environmentCombo.addItems(envList) |
|
122 self.ui.exceptionCheckBox.setChecked(exceptions) |
|
123 self.ui.clearShellCheckBox.setChecked(autoClearShell) |
|
124 self.ui.consoleCheckBox.setEnabled( |
|
125 Preferences.getDebugger("ConsoleDbgCommand") != "") |
|
126 self.ui.consoleCheckBox.setChecked(False) |
|
127 venvIndex = max(0, self.ui.venvComboBox.findText(lastUsedVenvName)) |
|
128 self.ui.venvComboBox.setCurrentIndex(venvIndex) |
|
129 |
|
130 if dialogType == 0: # start debug dialog |
|
131 self.ui.tracePythonCheckBox.setChecked(tracePython) |
|
132 self.ui.tracePythonCheckBox.show() |
|
133 self.ui.autoContinueCheckBox.setChecked(autoContinue) |
|
134 self.ui.forkModeCheckBox.setChecked(autoFork) |
|
135 self.ui.forkChildCheckBox.setChecked(forkChild) |
|
136 |
|
137 if dialogType == 1: # start run dialog |
|
138 self.ui.forkModeCheckBox.setChecked(autoFork) |
|
139 self.ui.forkChildCheckBox.setChecked(forkChild) |
|
140 |
|
141 if dialogType == 3: # start coverage or profile dialog |
|
142 self.ui.eraseCheckBox.setChecked(True) |
|
143 |
|
144 self.__clearHistoryLists = False |
|
145 self.__historiesModified = False |
|
146 |
|
147 msh = self.minimumSizeHint() |
|
148 self.resize(max(self.width(), msh.width()), msh.height()) |
|
149 |
|
150 def on_modFuncCombo_editTextChanged(self): |
|
151 """ |
|
152 Private slot to enable/disable the OK button. |
|
153 """ |
|
154 self.ui.buttonBox.button(QDialogButtonBox.Ok).setDisabled( |
|
155 self.ui.modFuncCombo.currentText() == "") |
|
156 |
|
157 def getData(self): |
|
158 """ |
|
159 Public method to retrieve the data entered into this dialog. |
|
160 |
|
161 @return a tuple of interpreter (string), argv (string), workdir |
|
162 (string), environment (string), exceptions flag (boolean), |
|
163 clear interpreter flag (boolean) and run in console flag (boolean) |
|
164 """ |
|
165 cmdLine = self.ui.cmdlineCombo.currentText() |
|
166 workdir = self.ui.workdirPicker.currentText(toNative=False) |
|
167 environment = self.ui.environmentCombo.currentText() |
|
168 venvName = self.ui.venvComboBox.currentText() |
|
169 |
|
170 return (venvName, |
|
171 cmdLine, |
|
172 workdir, |
|
173 environment, |
|
174 self.ui.exceptionCheckBox.isChecked(), |
|
175 self.ui.clearShellCheckBox.isChecked(), |
|
176 self.ui.consoleCheckBox.isChecked(), |
|
177 ) |
|
178 |
|
179 def getDebugData(self): |
|
180 """ |
|
181 Public method to retrieve the debug related data entered into this |
|
182 dialog. |
|
183 |
|
184 @return a tuple of a flag indicating, if the Python library should be |
|
185 traced as well, a flag indicating, that the debugger should not |
|
186 stop at the first executable line (boolean), a flag indicating, |
|
187 that the debugger should fork automatically (boolean) and a flag |
|
188 indicating, that the debugger should debug the child process after |
|
189 forking automatically (boolean) |
|
190 """ |
|
191 if self.dialogType == 0: |
|
192 return (self.ui.tracePythonCheckBox.isChecked(), |
|
193 self.ui.autoContinueCheckBox.isChecked(), |
|
194 self.ui.forkModeCheckBox.isChecked(), |
|
195 self.ui.forkChildCheckBox.isChecked()) |
|
196 else: |
|
197 return (False, False, False, False) |
|
198 |
|
199 def getRunData(self): |
|
200 """ |
|
201 Public method to retrieve the debug related data entered into this |
|
202 dialog. |
|
203 |
|
204 @return a tuple of a flag indicating, that the debugger should fork |
|
205 automatically (boolean) and a flag indicating, that the debugger |
|
206 should debug the child process after forking automatically |
|
207 (boolean) |
|
208 """ |
|
209 if self.dialogType == 1: |
|
210 return (self.ui.forkModeCheckBox.isChecked(), |
|
211 self.ui.forkChildCheckBox.isChecked()) |
|
212 else: |
|
213 return (False, False) |
|
214 |
|
215 def getCoverageData(self): |
|
216 """ |
|
217 Public method to retrieve the coverage related data entered into this |
|
218 dialog. |
|
219 |
|
220 @return flag indicating erasure of coverage info (boolean) |
|
221 """ |
|
222 if self.dialogType == 2: |
|
223 return self.ui.eraseCheckBox.isChecked() |
|
224 else: |
|
225 return False |
|
226 |
|
227 def getProfilingData(self): |
|
228 """ |
|
229 Public method to retrieve the profiling related data entered into this |
|
230 dialog. |
|
231 |
|
232 @return flag indicating erasure of profiling info (boolean) |
|
233 """ |
|
234 if self.dialogType == 3: |
|
235 return self.ui.eraseCheckBox.isChecked() |
|
236 else: |
|
237 return False |
|
238 |
|
239 def __clearHistories(self): |
|
240 """ |
|
241 Private slot to clear the combo boxes lists and record a flag to |
|
242 clear the lists. |
|
243 """ |
|
244 self.__clearHistoryLists = True |
|
245 self.__historiesModified = False # clear catches it all |
|
246 |
|
247 cmdLine = self.ui.cmdlineCombo.currentText() |
|
248 workdir = self.ui.workdirPicker.currentText() |
|
249 environment = self.ui.environmentCombo.currentText() |
|
250 |
|
251 self.ui.cmdlineCombo.clear() |
|
252 self.ui.workdirPicker.clear() |
|
253 self.ui.environmentCombo.clear() |
|
254 |
|
255 self.ui.cmdlineCombo.addItem(cmdLine) |
|
256 self.ui.workdirPicker.addItem(workdir) |
|
257 self.ui.environmentCombo.addItem(environment) |
|
258 |
|
259 def __editHistory(self): |
|
260 """ |
|
261 Private slot to edit a history list. |
|
262 """ |
|
263 histories = [ |
|
264 "", |
|
265 self.tr("Command Line"), |
|
266 self.tr("Working Directory"), |
|
267 self.tr("Environment"), |
|
268 ] |
|
269 historyKind, ok = QInputDialog.getItem( |
|
270 self, |
|
271 self.tr("Edit History"), |
|
272 self.tr("Select the history list to be edited:"), |
|
273 histories, |
|
274 0, False) |
|
275 if ok and historyKind: |
|
276 historiesIndex = histories.index(historyKind) |
|
277 if historiesIndex == 2: |
|
278 history = self.ui.workdirPicker.getPathItems() |
|
279 else: |
|
280 history = [] |
|
281 if historiesIndex == 1: |
|
282 combo = self.ui.cmdlineCombo |
|
283 else: |
|
284 combo = self.ui.environmentCombo |
|
285 for index in range(combo.count()): |
|
286 history.append(combo.itemText(index)) |
|
287 |
|
288 from .StartHistoryEditDialog import StartHistoryEditDialog |
|
289 dlg = StartHistoryEditDialog(history, self) |
|
290 if dlg.exec_() == QDialog.Accepted: |
|
291 history = dlg.getHistory() |
|
292 if historiesIndex == 1: |
|
293 combo = self.ui.cmdlineCombo |
|
294 elif historiesIndex == 2: |
|
295 combo = self.ui.workdirPicker |
|
296 else: |
|
297 combo = self.ui.environmentCombo |
|
298 combo.clear() |
|
299 combo.addItems(history) |
|
300 |
|
301 self.__historiesModified = True |
|
302 |
|
303 def historiesModified(self): |
|
304 """ |
|
305 Public method to test for modified histories. |
|
306 |
|
307 @return flag indicating modified histories |
|
308 @rtype bool |
|
309 """ |
|
310 return self.__historiesModified |
|
311 |
|
312 def clearHistories(self): |
|
313 """ |
|
314 Public method to test, if histories shall be cleared. |
|
315 |
|
316 @return flag indicating histories shall be cleared |
|
317 @rtype bool |
|
318 """ |
|
319 return self.__clearHistoryLists |
|
320 |
|
321 def getHistories(self): |
|
322 """ |
|
323 Public method to get the lists of histories. |
|
324 |
|
325 @return tuple containing the histories of command line arguments, |
|
326 working directories, environment settings and interpreters |
|
327 @rtype tuple of four list of str |
|
328 """ |
|
329 return ( |
|
330 [self.ui.cmdlineCombo.itemText(index) for index in range( |
|
331 self.ui.cmdlineCombo.count())], |
|
332 self.ui.workdirPicker.getPathItems(), |
|
333 [self.ui.environmentCombo.itemText(index) for index in range( |
|
334 self.ui.environmentCombo.count())], |
|
335 ) |
|
336 |
|
337 def on_buttonBox_clicked(self, button): |
|
338 """ |
|
339 Private slot called by a button of the button box clicked. |
|
340 |
|
341 @param button button that was clicked (QAbstractButton) |
|
342 """ |
|
343 if button == self.clearButton: |
|
344 self.__clearHistories() |
|
345 elif button == self.editButton: |
|
346 self.__editHistory() |