|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2009 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Debugger Python3 configuration page. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import pyqtSlot |
|
11 |
|
12 from EricWidgets.EricApplication import ericApp |
|
13 from EricWidgets.EricPathPicker import EricPathPickerModes |
|
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 = ericApp().getObject("VirtualEnvManager") |
|
36 self.__standalone = False |
|
37 except KeyError: |
|
38 from VirtualEnv.VirtualenvManager import VirtualenvManager |
|
39 self.__virtualenvManager = VirtualenvManager() |
|
40 self.__standalone = True |
|
41 |
|
42 self.venvDlgButton.setVisible(self.__standalone) |
|
43 self.venvDlgButton.setIcon(UI.PixmapCache.getIcon("virtualenv")) |
|
44 |
|
45 self.venvRefreshButton.setVisible(not self.__standalone) |
|
46 self.venvRefreshButton.setIcon(UI.PixmapCache.getIcon("reload")) |
|
47 |
|
48 self.debugClientPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) |
|
49 self.debugClientPicker.setToolTip(self.tr( |
|
50 "Press to select the Debug Client via a file selection dialog")) |
|
51 self.debugClientPicker.setFilters(self.tr("Python Files (*.py *.py3)")) |
|
52 |
|
53 self.__populateAndSetVenvComboBox() |
|
54 |
|
55 # set initial values |
|
56 dct = Preferences.getDebugger("DebugClientType3") |
|
57 if dct == "standard": |
|
58 self.standardButton.setChecked(True) |
|
59 else: |
|
60 self.customButton.setChecked(True) |
|
61 self.debugClientPicker.setText( |
|
62 Preferences.getDebugger("DebugClient3"), toNative=False) |
|
63 self.pyRedirectCheckBox.setChecked( |
|
64 Preferences.getDebugger("Python3Redirect")) |
|
65 self.pyNoEncodingCheckBox.setChecked( |
|
66 Preferences.getDebugger("Python3NoEncoding")) |
|
67 self.sourceExtensionsEdit.setText( |
|
68 Preferences.getDebugger("Python3Extensions")) |
|
69 |
|
70 def save(self): |
|
71 """ |
|
72 Public slot to save the Debugger Python configuration. |
|
73 """ |
|
74 Preferences.setDebugger( |
|
75 "Python3VirtualEnv", |
|
76 self.venvComboBox.currentText()) |
|
77 dct = "standard" if self.standardButton.isChecked() else "custom" |
|
78 Preferences.setDebugger("DebugClientType3", dct) |
|
79 Preferences.setDebugger( |
|
80 "DebugClient3", |
|
81 self.debugClientPicker.text(toNative=False)) |
|
82 Preferences.setDebugger( |
|
83 "Python3Redirect", |
|
84 self.pyRedirectCheckBox.isChecked()) |
|
85 Preferences.setDebugger( |
|
86 "Python3NoEncoding", |
|
87 self.pyNoEncodingCheckBox.isChecked()) |
|
88 |
|
89 def __populateAndSetVenvComboBox(self): |
|
90 """ |
|
91 Private method to populate and set the virtual environment combo box. |
|
92 """ |
|
93 self.venvComboBox.clear() |
|
94 self.venvComboBox.addItems( |
|
95 [""] + |
|
96 sorted(self.__virtualenvManager.getVirtualenvNames()) |
|
97 ) |
|
98 |
|
99 # set initial value |
|
100 venvName = Preferences.getDebugger("Python3VirtualEnv") |
|
101 if venvName: |
|
102 index = self.venvComboBox.findText(venvName) |
|
103 if index < 0: |
|
104 index = 0 |
|
105 self.venvComboBox.setCurrentIndex(index) |
|
106 |
|
107 @pyqtSlot() |
|
108 def on_refreshButton_clicked(self): |
|
109 """ |
|
110 Private slot handling a click of the refresh button. |
|
111 """ |
|
112 self.sourceExtensionsEdit.setText( |
|
113 Preferences.getDebugger("Python3Extensions")) |
|
114 |
|
115 @pyqtSlot() |
|
116 def on_venvDlgButton_clicked(self): |
|
117 """ |
|
118 Private slot to show the virtual environment manager dialog. |
|
119 """ |
|
120 if self.__standalone: |
|
121 self.__virtualenvManager.showVirtualenvManagerDialog(modal=True) |
|
122 self.__populateAndSetVenvComboBox() |
|
123 self.activateWindow() |
|
124 self.raise_() |
|
125 |
|
126 @pyqtSlot() |
|
127 def on_venvRefreshButton_clicked(self): |
|
128 """ |
|
129 Private slot to reload the list of virtual environments. |
|
130 """ |
|
131 self.__populateAndSetVenvComboBox() |
|
132 |
|
133 |
|
134 def create(dlg): |
|
135 """ |
|
136 Module function to create the configuration page. |
|
137 |
|
138 @param dlg reference to the configuration dialog |
|
139 @return reference to the instantiated page (ConfigurationPageBase) |
|
140 """ |
|
141 page = DebuggerPython3Page() |
|
142 return page |