|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2005 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog for entering project specific debugger settings. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 import os |
|
13 |
|
14 from PyQt5.QtCore import pyqtSlot |
|
15 from PyQt5.QtWidgets import QDialog, QComboBox |
|
16 |
|
17 from E5Gui.E5Completers import E5DirCompleter |
|
18 from E5Gui.E5PathPicker import E5PathPickerModes |
|
19 from E5Gui.E5Application import e5App |
|
20 |
|
21 from .Ui_DebuggerPropertiesDialog import Ui_DebuggerPropertiesDialog |
|
22 |
|
23 |
|
24 from eric6config import getConfig |
|
25 |
|
26 import Preferences |
|
27 import UI.PixmapCache |
|
28 |
|
29 |
|
30 class DebuggerPropertiesDialog(QDialog, Ui_DebuggerPropertiesDialog): |
|
31 """ |
|
32 Class implementing a dialog for entering project specific debugger |
|
33 settings. |
|
34 """ |
|
35 def __init__(self, project, parent=None, name=None): |
|
36 """ |
|
37 Constructor |
|
38 |
|
39 @param project reference to the project object |
|
40 @param parent parent widget of this dialog (QWidget) |
|
41 @param name name of this dialog (string) |
|
42 """ |
|
43 super(DebuggerPropertiesDialog, self).__init__(parent) |
|
44 if name: |
|
45 self.setObjectName(name) |
|
46 self.setupUi(self) |
|
47 |
|
48 debugClientsHistory = Preferences.getProject( |
|
49 "DebugClientsHistory") |
|
50 self.debugClientPicker.setMode(E5PathPickerModes.OpenFileMode) |
|
51 self.debugClientPicker.setInsertPolicy(QComboBox.InsertAtTop) |
|
52 self.debugClientPicker.setSizeAdjustPolicy( |
|
53 QComboBox.AdjustToMinimumContentsLength) |
|
54 self.debugClientPicker.setPathsList(debugClientsHistory) |
|
55 self.debugClientClearHistoryButton.setIcon( |
|
56 UI.PixmapCache.getIcon("editDelete.png")) |
|
57 |
|
58 venvManager = e5App().getObject("VirtualEnvManager") |
|
59 |
|
60 self.venvComboBox.addItem("") |
|
61 self.venvComboBox.addItems(sorted(venvManager.getVirtualenvNames())) |
|
62 |
|
63 self.translationLocalCompleter = E5DirCompleter( |
|
64 self.translationLocalEdit) |
|
65 |
|
66 self.project = project |
|
67 |
|
68 if self.project.debugProperties["VIRTUALENV"]: |
|
69 venvIndex = max(0, self.venvComboBox.findText( |
|
70 self.project.debugProperties["VIRTUALENV"])) |
|
71 else: |
|
72 if self.project.pdata["PROGLANGUAGE"] in ["Python", "Python2"]: |
|
73 venvName = Preferences.getDebugger("Python2VirtualEnv") |
|
74 elif self.project.pdata["PROGLANGUAGE"] == "Python3": |
|
75 venvName = Preferences.getDebugger("Python3VirtualEnv") |
|
76 else: |
|
77 venvName = "" |
|
78 if not venvName: |
|
79 venvName, _ = venvManager.getDefaultEnvironment() |
|
80 if venvName: |
|
81 venvIndex = max(0, self.venvComboBox.findText(venvName)) |
|
82 else: |
|
83 venvIndex = 0 |
|
84 self.venvComboBox.setCurrentIndex(venvIndex) |
|
85 if self.project.debugProperties["DEBUGCLIENT"]: |
|
86 self.debugClientPicker.setText( |
|
87 self.project.debugProperties["DEBUGCLIENT"], |
|
88 toNative=False) |
|
89 else: |
|
90 if self.project.pdata["PROGLANGUAGE"] in ["Python", "Python2", |
|
91 "Python3"]: |
|
92 debugClient = os.path.join( |
|
93 getConfig('ericDir'), |
|
94 "DebugClients", "Python", "DebugClient.py") |
|
95 else: |
|
96 debugClient = "" |
|
97 self.debugClientPicker.setText(debugClient, toNative=False) |
|
98 self.debugEnvironmentOverrideCheckBox.setChecked( |
|
99 self.project.debugProperties["ENVIRONMENTOVERRIDE"]) |
|
100 self.debugEnvironmentEdit.setText( |
|
101 self.project.debugProperties["ENVIRONMENTSTRING"]) |
|
102 self.remoteDebuggerGroup.setChecked( |
|
103 self.project.debugProperties["REMOTEDEBUGGER"]) |
|
104 self.remoteHostEdit.setText( |
|
105 self.project.debugProperties["REMOTEHOST"]) |
|
106 self.remoteCommandEdit.setText( |
|
107 self.project.debugProperties["REMOTECOMMAND"]) |
|
108 self.pathTranslationGroup.setChecked( |
|
109 self.project.debugProperties["PATHTRANSLATION"]) |
|
110 self.translationRemoteEdit.setText( |
|
111 self.project.debugProperties["REMOTEPATH"]) |
|
112 self.translationLocalEdit.setText( |
|
113 self.project.debugProperties["LOCALPATH"]) |
|
114 self.consoleDebuggerGroup.setChecked( |
|
115 self.project.debugProperties["CONSOLEDEBUGGER"]) |
|
116 self.consoleCommandEdit.setText( |
|
117 self.project.debugProperties["CONSOLECOMMAND"]) |
|
118 self.redirectCheckBox.setChecked( |
|
119 self.project.debugProperties["REDIRECT"]) |
|
120 self.noEncodingCheckBox.setChecked( |
|
121 self.project.debugProperties["NOENCODING"]) |
|
122 |
|
123 msh = self.minimumSizeHint() |
|
124 self.resize(max(self.width(), msh.width()), msh.height()) |
|
125 |
|
126 @pyqtSlot() |
|
127 def on_debugClientPicker_aboutToShowPathPickerDialog(self): |
|
128 """ |
|
129 Private slot to perform actions before the debug client selection |
|
130 dialog is shown. |
|
131 """ |
|
132 filters = self.project.getDebuggerFilters( |
|
133 self.project.pdata["PROGLANGUAGE"]) |
|
134 filters += self.tr("All Files (*)") |
|
135 self.debugClientPicker.setFilters(filters) |
|
136 |
|
137 def storeData(self): |
|
138 """ |
|
139 Public method to store the entered/modified data. |
|
140 """ |
|
141 self.project.debugProperties["VIRTUALENV"] = \ |
|
142 self.venvComboBox.currentText() |
|
143 |
|
144 self.project.debugProperties["DEBUGCLIENT"] = \ |
|
145 self.debugClientPicker.text(toNative=False) |
|
146 if not self.project.debugProperties["DEBUGCLIENT"]: |
|
147 if self.project.pdata["PROGLANGUAGE"] in ["Python", "Python2", |
|
148 "Python3"]: |
|
149 debugClient = os.path.join( |
|
150 getConfig('ericDir'), |
|
151 "DebugClients", "Python", "DebugClient.py") |
|
152 else: |
|
153 debugClient = "" |
|
154 self.project.debugProperties["DEBUGCLIENT"] = debugClient |
|
155 |
|
156 self.project.debugProperties["ENVIRONMENTOVERRIDE"] = \ |
|
157 self.debugEnvironmentOverrideCheckBox.isChecked() |
|
158 self.project.debugProperties["ENVIRONMENTSTRING"] = \ |
|
159 self.debugEnvironmentEdit.text() |
|
160 self.project.debugProperties["REMOTEDEBUGGER"] = \ |
|
161 self.remoteDebuggerGroup.isChecked() |
|
162 self.project.debugProperties["REMOTEHOST"] = \ |
|
163 self.remoteHostEdit.text() |
|
164 self.project.debugProperties["REMOTECOMMAND"] = \ |
|
165 self.remoteCommandEdit.text() |
|
166 self.project.debugProperties["PATHTRANSLATION"] = \ |
|
167 self.pathTranslationGroup.isChecked() |
|
168 self.project.debugProperties["REMOTEPATH"] = \ |
|
169 self.translationRemoteEdit.text() |
|
170 self.project.debugProperties["LOCALPATH"] = \ |
|
171 self.translationLocalEdit.text() |
|
172 self.project.debugProperties["CONSOLEDEBUGGER"] = \ |
|
173 self.consoleDebuggerGroup.isChecked() |
|
174 self.project.debugProperties["CONSOLECOMMAND"] = \ |
|
175 self.consoleCommandEdit.text() |
|
176 self.project.debugProperties["REDIRECT"] = \ |
|
177 self.redirectCheckBox.isChecked() |
|
178 self.project.debugProperties["NOENCODING"] = \ |
|
179 self.noEncodingCheckBox.isChecked() |
|
180 self.project.debugPropertiesLoaded = True |
|
181 self.project.debugPropertiesChanged = True |
|
182 |
|
183 self.__saveHistories() |
|
184 |
|
185 def __saveHistories(self): |
|
186 """ |
|
187 Private method to save the path picker histories. |
|
188 """ |
|
189 debugClient = self.debugClientPicker.text(toNative=False) |
|
190 debugClientsHistory = self.debugClientPicker.getPathItems() |
|
191 if debugClient not in debugClientsHistory: |
|
192 debugClientsHistory.insert(0, debugClient) |
|
193 Preferences.setProject("DebugClientsHistory", |
|
194 debugClientsHistory) |
|
195 |
|
196 @pyqtSlot() |
|
197 def on_debugClientClearHistoryButton_clicked(self): |
|
198 """ |
|
199 Private slot to clear the debug clients history. |
|
200 """ |
|
201 self.__clearHistory(self.debugClientPicker) |
|
202 |
|
203 def __clearHistory(self, picker): |
|
204 """ |
|
205 Private method to clear a path picker history. |
|
206 |
|
207 @param picker reference to the path picker |
|
208 @type E5ComboPathPicker |
|
209 """ |
|
210 currentText = picker.text() |
|
211 picker.clear() |
|
212 picker.setText(currentText) |
|
213 |
|
214 self.__saveHistories() |