|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2006 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Qt 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_QtPage import Ui_QtPage |
|
17 |
|
18 import Preferences |
|
19 import UI.PixmapCache |
|
20 |
|
21 |
|
22 class QtPage(ConfigurationPageBase, Ui_QtPage): |
|
23 """ |
|
24 Class implementing the Qt configuration page. |
|
25 """ |
|
26 def __init__(self): |
|
27 """ |
|
28 Constructor |
|
29 """ |
|
30 super().__init__() |
|
31 self.setupUi(self) |
|
32 self.setObjectName("QtPage") |
|
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 for button in ( |
|
43 self.pyqt5VenvDlgButton, self.pyqt6VenvDlgButton, |
|
44 self.pyside2VenvDlgButton, self.pyside6VenvDlgButton, |
|
45 ): |
|
46 button.setIcon(UI.PixmapCache.getIcon("virtualenv")) |
|
47 button.clicked.connect(self.__showVirtualEnvManager) |
|
48 button.setVisible(self.__standalone) |
|
49 |
|
50 for button in ( |
|
51 self.pyqt5VenvRefreshButton, self.pyqt6VenvRefreshButton, |
|
52 self.pyside2VenvRefreshButton, self.pyside6VenvRefreshButton, |
|
53 ): |
|
54 button.setIcon(UI.PixmapCache.getIcon("reload")) |
|
55 button.clicked.connect(self.__populateAndSetVenvComboBoxes) |
|
56 button.setVisible(not self.__standalone) |
|
57 |
|
58 self.qtTransPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) |
|
59 for picker in ( |
|
60 self.qtToolsDirPicker, |
|
61 self.pyqtToolsDirPicker, |
|
62 self.pyqt6ToolsDirPicker, |
|
63 self.pyside2ToolsDirPicker, |
|
64 self.pyside6ToolsDirPicker, |
|
65 ): |
|
66 picker.setMode(EricPathPickerModes.DIRECTORY_SHOW_FILES_MODE) |
|
67 |
|
68 self.__populateAndSetVenvComboBoxes(True) |
|
69 |
|
70 # set initial values |
|
71 self.qtTransPicker.setText( |
|
72 Preferences.getQt("Qt6TranslationsDir")) |
|
73 |
|
74 # Qt |
|
75 self.qtToolsDirPicker.setText(Preferences.getQt("QtToolsDir")) |
|
76 self.qtPrefixEdit.setText(Preferences.getQt("QtToolsPrefix")) |
|
77 self.qtPostfixEdit.setText(Preferences.getQt("QtToolsPostfix")) |
|
78 self.__updateQtSample() |
|
79 |
|
80 # PyQt 5 |
|
81 self.pyqtToolsDirPicker.setText(Preferences.getQt("PyQtToolsDir")) |
|
82 self.pyuicIndentSpinBox.setValue(Preferences.getQt("PyuicIndent")) |
|
83 self.pyuicImportsCheckBox.setChecked( |
|
84 Preferences.getQt("PyuicFromImports")) |
|
85 self.pyuicExecuteCheckBox.setChecked( |
|
86 Preferences.getQt("PyuicExecute")) |
|
87 |
|
88 # PyQt 6 |
|
89 self.pyqt6ToolsDirPicker.setText(Preferences.getQt("PyQt6ToolsDir")) |
|
90 self.pyuic6IndentSpinBox.setValue(Preferences.getQt("Pyuic6Indent")) |
|
91 self.pyuic6ExecuteCheckBox.setChecked( |
|
92 Preferences.getQt("Pyuic6Execute")) |
|
93 |
|
94 # PySide 2 |
|
95 self.pyside2ToolsDirPicker.setText( |
|
96 Preferences.getQt("PySide2ToolsDir")) |
|
97 self.pyside2uicImportsCheckBox.setChecked( |
|
98 Preferences.getQt("PySide2FromImports")) |
|
99 |
|
100 # PySide 6 |
|
101 self.pyside6ToolsDirPicker.setText( |
|
102 Preferences.getQt("PySide6ToolsDir")) |
|
103 self.pyside6uicImportsCheckBox.setChecked( |
|
104 Preferences.getQt("PySide6FromImports")) |
|
105 |
|
106 def save(self): |
|
107 """ |
|
108 Public slot to save the Qt configuration. |
|
109 """ |
|
110 Preferences.setQt("Qt6TranslationsDir", self.qtTransPicker.text()) |
|
111 Preferences.setQt("QtToolsDir", self.qtToolsDirPicker.text()) |
|
112 Preferences.setQt("QtToolsPrefix", self.qtPrefixEdit.text()) |
|
113 Preferences.setQt("QtToolsPostfix", self.qtPostfixEdit.text()) |
|
114 |
|
115 Preferences.setQt("PyQtVenvName", self.pyqt5VenvComboBox.currentText()) |
|
116 Preferences.setQt("PyQtToolsDir", self.pyqtToolsDirPicker.text()) |
|
117 Preferences.setQt("PyuicIndent", self.pyuicIndentSpinBox.value()) |
|
118 Preferences.setQt("PyuicFromImports", |
|
119 self.pyuicImportsCheckBox.isChecked()) |
|
120 Preferences.setQt("PyuicExecute", |
|
121 self.pyuicExecuteCheckBox.isChecked()) |
|
122 |
|
123 Preferences.setQt("PyQt6VenvName", |
|
124 self.pyqt6VenvComboBox.currentText()) |
|
125 Preferences.setQt("PyQt6ToolsDir", self.pyqt6ToolsDirPicker.text()) |
|
126 Preferences.setQt("Pyuic6Indent", self.pyuic6IndentSpinBox.value()) |
|
127 Preferences.setQt("Pyuic6Execute", |
|
128 self.pyuic6ExecuteCheckBox.isChecked()) |
|
129 |
|
130 Preferences.setQt("PySide2VenvName", |
|
131 self.pyside2VenvComboBox.currentText()) |
|
132 Preferences.setQt("PySide2ToolsDir", self.pyside2ToolsDirPicker.text()) |
|
133 Preferences.setQt("PySide2FromImports", |
|
134 self.pyside2uicImportsCheckBox.isChecked()) |
|
135 |
|
136 Preferences.setQt("PySide6VenvName", |
|
137 self.pyside6VenvComboBox.currentText()) |
|
138 Preferences.setQt("PySide6ToolsDir", self.pyside6ToolsDirPicker.text()) |
|
139 Preferences.setQt("PySide6FromImports", |
|
140 self.pyside6uicImportsCheckBox.isChecked()) |
|
141 |
|
142 def __updateQtSample(self): |
|
143 """ |
|
144 Private slot to update the Qt tools sample label. |
|
145 """ |
|
146 self.qtSampleLabel.setText( |
|
147 self.tr("Sample: {0}designer{1}").format( |
|
148 self.qtPrefixEdit.text(), self.qtPostfixEdit.text())) |
|
149 |
|
150 @pyqtSlot(str) |
|
151 def on_qtPrefixEdit_textChanged(self, txt): |
|
152 """ |
|
153 Private slot to handle a change in the entered Qt directory. |
|
154 |
|
155 @param txt the entered string (string) |
|
156 """ |
|
157 self.__updateQtSample() |
|
158 |
|
159 @pyqtSlot(str) |
|
160 def on_qtPostfixEdit_textChanged(self, txt): |
|
161 """ |
|
162 Private slot to handle a change in the entered Qt directory. |
|
163 |
|
164 @param txt the entered string (string) |
|
165 """ |
|
166 self.__updateQtSample() |
|
167 |
|
168 def __populateAndSetVenvComboBox(self, comboBox, envKey, initial): |
|
169 """ |
|
170 Private method to populate and set the virtual environment combo boxes. |
|
171 |
|
172 @param comboBox reference to the combo box to be populated |
|
173 @type QComboBox |
|
174 @param envKey preferences key for the environment |
|
175 @type str |
|
176 @param initial flag indicating an initial population |
|
177 @type bool |
|
178 """ |
|
179 venvName = (Preferences.getQt(envKey) if initial |
|
180 else comboBox.currentText()) |
|
181 |
|
182 comboBox.clear() |
|
183 comboBox.addItems( |
|
184 [""] + |
|
185 sorted(self.__virtualenvManager.getVirtualenvNames()) |
|
186 ) |
|
187 |
|
188 if venvName: |
|
189 index = comboBox.findText(venvName) |
|
190 if index < 0: |
|
191 index = 0 |
|
192 comboBox.setCurrentIndex(index) |
|
193 |
|
194 def __populateAndSetVenvComboBoxes(self, initial): |
|
195 """ |
|
196 Private method to populate the virtual environment combo boxes. |
|
197 |
|
198 @param initial flag indicating an initial population |
|
199 @type bool |
|
200 """ |
|
201 self.__populateAndSetVenvComboBox( |
|
202 self.pyqt5VenvComboBox, "PyQtVenvName", initial) |
|
203 self.__populateAndSetVenvComboBox( |
|
204 self.pyqt6VenvComboBox, "PyQt6VenvName", initial) |
|
205 self.__populateAndSetVenvComboBox( |
|
206 self.pyside2VenvComboBox, "PySide2VenvName", initial) |
|
207 self.__populateAndSetVenvComboBox( |
|
208 self.pyside6VenvComboBox, "PySide6VenvName", initial) |
|
209 |
|
210 def __showVirtualEnvManager(self): |
|
211 """ |
|
212 Private method to show the virtual environment manager dialog. |
|
213 """ |
|
214 self.__virtualenvManager.showVirtualenvManagerDialog(modal=True) |
|
215 self.__populateAndSetVenvComboBoxes(False) |
|
216 self.activateWindow() |
|
217 self.raise_() |
|
218 |
|
219 |
|
220 def create(dlg): |
|
221 """ |
|
222 Module function to create the configuration page. |
|
223 |
|
224 @param dlg reference to the configuration dialog |
|
225 @return reference to the instantiated page (ConfigurationPageBase) |
|
226 """ |
|
227 page = QtPage() |
|
228 return page |