|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2009 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Debugger Python3 configuration page. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtCore import pyqtSlot |
|
11 |
|
12 from E5Gui.E5Application import e5App |
|
13 from E5Gui.E5PathPicker import E5PathPickerModes |
|
14 |
|
15 from .ConfigurationPageBase import ConfigurationPageBase |
|
16 from .Ui_DebuggerPython3Page import Ui_DebuggerPython3Page |
|
17 |
|
18 import Preferences |
|
19 import UI.PixmapCache |
|
20 |
|
21 |
|
22 class DebuggerPython3Page(ConfigurationPageBase, Ui_DebuggerPython3Page): |
|
23 """ |
|
24 Class implementing the Debugger Python3 configuration page. |
|
25 """ |
|
26 def __init__(self): |
|
27 """ |
|
28 Constructor |
|
29 """ |
|
30 super().__init__() |
|
31 self.setupUi(self) |
|
32 self.setObjectName("DebuggerPython3Page") |
|
33 |
|
34 try: |
|
35 self.__virtualenvManager = e5App().getObject("VirtualEnvManager") |
|
36 except KeyError: |
|
37 from VirtualEnv.VirtualenvManager import VirtualenvManager |
|
38 self.__virtualenvManager = VirtualenvManager() |
|
39 |
|
40 self.venvDlgButton.setIcon(UI.PixmapCache.getIcon("virtualenv")) |
|
41 |
|
42 self.debugClientPicker.setMode(E5PathPickerModes.OpenFileMode) |
|
43 self.debugClientPicker.setToolTip(self.tr( |
|
44 "Press to select the Debug Client via a file selection dialog")) |
|
45 self.debugClientPicker.setFilters(self.tr("Python Files (*.py *.py3)")) |
|
46 |
|
47 self.__populateAndSetVenvComboBox() |
|
48 |
|
49 # set initial values |
|
50 dct = Preferences.getDebugger("DebugClientType3") |
|
51 if dct == "standard": |
|
52 self.standardButton.setChecked(True) |
|
53 else: |
|
54 self.customButton.setChecked(True) |
|
55 self.debugClientPicker.setText( |
|
56 Preferences.getDebugger("DebugClient3"), toNative=False) |
|
57 self.pyRedirectCheckBox.setChecked( |
|
58 Preferences.getDebugger("Python3Redirect")) |
|
59 self.pyNoEncodingCheckBox.setChecked( |
|
60 Preferences.getDebugger("Python3NoEncoding")) |
|
61 self.sourceExtensionsEdit.setText( |
|
62 Preferences.getDebugger("Python3Extensions")) |
|
63 |
|
64 def save(self): |
|
65 """ |
|
66 Public slot to save the Debugger Python configuration. |
|
67 """ |
|
68 Preferences.setDebugger( |
|
69 "Python3VirtualEnv", |
|
70 self.venvComboBox.currentText()) |
|
71 dct = "standard" if self.standardButton.isChecked() else "custom" |
|
72 Preferences.setDebugger("DebugClientType3", dct) |
|
73 Preferences.setDebugger( |
|
74 "DebugClient3", |
|
75 self.debugClientPicker.text(toNative=False)) |
|
76 Preferences.setDebugger( |
|
77 "Python3Redirect", |
|
78 self.pyRedirectCheckBox.isChecked()) |
|
79 Preferences.setDebugger( |
|
80 "Python3NoEncoding", |
|
81 self.pyNoEncodingCheckBox.isChecked()) |
|
82 |
|
83 def __populateAndSetVenvComboBox(self): |
|
84 """ |
|
85 Private method to populate and set the virtual environment combo box. |
|
86 """ |
|
87 self.venvComboBox.clear() |
|
88 self.venvComboBox.addItems( |
|
89 [""] + |
|
90 sorted(self.__virtualenvManager.getVirtualenvNames()) |
|
91 ) |
|
92 |
|
93 # set initial value |
|
94 venvName = Preferences.getDebugger("Python3VirtualEnv") |
|
95 if venvName: |
|
96 index = self.venvComboBox.findText(venvName) |
|
97 if index < 0: |
|
98 index = 0 |
|
99 self.venvComboBox.setCurrentIndex(index) |
|
100 |
|
101 @pyqtSlot() |
|
102 def on_refreshButton_clicked(self): |
|
103 """ |
|
104 Private slot handling a click of the refresh button. |
|
105 """ |
|
106 self.sourceExtensionsEdit.setText( |
|
107 Preferences.getDebugger("Python3Extensions")) |
|
108 |
|
109 @pyqtSlot() |
|
110 def on_venvDlgButton_clicked(self): |
|
111 """ |
|
112 Private slot to show the virtual environment manager dialog. |
|
113 """ |
|
114 self.__virtualenvManager.showVirtualenvManagerDialog(modal=True) |
|
115 self.__populateAndSetVenvComboBox() |
|
116 self.activateWindow() |
|
117 self.raise_() |
|
118 |
|
119 |
|
120 def create(dlg): |
|
121 """ |
|
122 Module function to create the configuration page. |
|
123 |
|
124 @param dlg reference to the configuration dialog |
|
125 @return reference to the instantiated page (ConfigurationPageBase) |
|
126 """ |
|
127 page = DebuggerPython3Page() |
|
128 return page |