eric7/Preferences/ConfigurationPages/QtPage.py

branch
eric7
changeset 8312
800c432b34c8
parent 8234
fcb6b4b96274
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2006 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Qt 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_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 = e5App().getObject("VirtualEnvManager")
36 except KeyError:
37 from VirtualEnv.VirtualenvManager import VirtualenvManager
38 self.__virtualenvManager = VirtualenvManager()
39
40 for button in (
41 self.pyqt5VenvDlgButton, self.pyqt6VenvDlgButton,
42 self.pyside2VenvDlgButton, self.pyside6VenvDlgButton,
43 ):
44 button.setIcon(UI.PixmapCache.getIcon("virtualenv"))
45
46 self.qtTransPicker.setMode(E5PathPickerModes.DirectoryMode)
47 for picker in (
48 self.qtToolsDirPicker,
49 self.pyqtToolsDirPicker,
50 self.pyqt6ToolsDirPicker,
51 self.pyside2ToolsDirPicker,
52 self.pyside6ToolsDirPicker,
53 ):
54 picker.setMode(E5PathPickerModes.DirectoryShowFilesMode)
55
56 self.__populateAndSetVenvComboBoxes(True)
57
58 # set initial values
59 self.qtTransPicker.setText(
60 Preferences.getQt("Qt5TranslationsDir"))
61
62 # Qt
63 self.qtToolsDirPicker.setText(Preferences.getQt("QtToolsDir"))
64 self.qtPrefixEdit.setText(Preferences.getQt("QtToolsPrefix"))
65 self.qtPostfixEdit.setText(Preferences.getQt("QtToolsPostfix"))
66 self.__updateQtSample()
67
68 # PyQt 5
69 self.pyqtToolsDirPicker.setText(Preferences.getQt("PyQtToolsDir"))
70 self.pyuicIndentSpinBox.setValue(Preferences.getQt("PyuicIndent"))
71 self.pyuicImportsCheckBox.setChecked(
72 Preferences.getQt("PyuicFromImports"))
73 self.pyuicExecuteCheckBox.setChecked(
74 Preferences.getQt("PyuicExecute"))
75
76 # PyQt 6
77 self.pyqt6ToolsDirPicker.setText(Preferences.getQt("PyQt6ToolsDir"))
78 self.pyuic6IndentSpinBox.setValue(Preferences.getQt("Pyuic6Indent"))
79 self.pyuic6ExecuteCheckBox.setChecked(
80 Preferences.getQt("Pyuic6Execute"))
81
82 # PySide 2
83 self.pyside2ToolsDirPicker.setText(
84 Preferences.getQt("PySide2ToolsDir"))
85 self.pyside2uicImportsCheckBox.setChecked(
86 Preferences.getQt("PySide2FromImports"))
87
88 # PySide 6
89 self.pyside6ToolsDirPicker.setText(
90 Preferences.getQt("PySide6ToolsDir"))
91 self.pyside6uicImportsCheckBox.setChecked(
92 Preferences.getQt("PySide6FromImports"))
93
94 def save(self):
95 """
96 Public slot to save the Qt configuration.
97 """
98 Preferences.setQt("Qt5TranslationsDir", self.qtTransPicker.text())
99 Preferences.setQt("QtToolsDir", self.qtToolsDirPicker.text())
100 Preferences.setQt("QtToolsPrefix", self.qtPrefixEdit.text())
101 Preferences.setQt("QtToolsPostfix", self.qtPostfixEdit.text())
102
103 Preferences.setQt("PyQtVenvName", self.pyqt5VenvComboBox.currentText())
104 Preferences.setQt("PyQtToolsDir", self.pyqtToolsDirPicker.text())
105 Preferences.setQt("PyuicIndent", self.pyuicIndentSpinBox.value())
106 Preferences.setQt("PyuicFromImports",
107 self.pyuicImportsCheckBox.isChecked())
108 Preferences.setQt("PyuicExecute",
109 self.pyuicExecuteCheckBox.isChecked())
110
111 Preferences.setQt("PyQt6VenvName",
112 self.pyqt6VenvComboBox.currentText())
113 Preferences.setQt("PyQt6ToolsDir", self.pyqt6ToolsDirPicker.text())
114 Preferences.setQt("Pyuic6Indent", self.pyuic6IndentSpinBox.value())
115 Preferences.setQt("Pyuic6Execute",
116 self.pyuic6ExecuteCheckBox.isChecked())
117
118 Preferences.setQt("PySide2VenvName",
119 self.pyside2VenvComboBox.currentText())
120 Preferences.setQt("PySide2ToolsDir", self.pyside2ToolsDirPicker.text())
121 Preferences.setQt("PySide2FromImports",
122 self.pyside2uicImportsCheckBox.isChecked())
123
124 Preferences.setQt("PySide6VenvName",
125 self.pyside6VenvComboBox.currentText())
126 Preferences.setQt("PySide6ToolsDir", self.pyside6ToolsDirPicker.text())
127 Preferences.setQt("PySide6FromImports",
128 self.pyside6uicImportsCheckBox.isChecked())
129
130 def __updateQtSample(self):
131 """
132 Private slot to update the Qt tools sample label.
133 """
134 self.qtSampleLabel.setText(
135 self.tr("Sample: {0}designer{1}").format(
136 self.qtPrefixEdit.text(), self.qtPostfixEdit.text()))
137
138 @pyqtSlot(str)
139 def on_qtPrefixEdit_textChanged(self, txt):
140 """
141 Private slot to handle a change in the entered Qt directory.
142
143 @param txt the entered string (string)
144 """
145 self.__updateQtSample()
146
147 @pyqtSlot(str)
148 def on_qtPostfixEdit_textChanged(self, txt):
149 """
150 Private slot to handle a change in the entered Qt directory.
151
152 @param txt the entered string (string)
153 """
154 self.__updateQtSample()
155
156 def __populateAndSetVenvComboBox(self, comboBox, envKey, initial):
157 """
158 Private method to populate and set the virtual environment combo boxes.
159
160 @param comboBox reference to the combo box to be populated
161 @type QComboBox
162 @param envKey preferences key for the environment
163 @type str
164 @param initial flag indicating an initial population
165 @type bool
166 """
167 venvName = (Preferences.getQt(envKey) if initial
168 else comboBox.currentText())
169
170 comboBox.clear()
171 comboBox.addItems(
172 [""] +
173 sorted(self.__virtualenvManager.getVirtualenvNames())
174 )
175
176 if venvName:
177 index = comboBox.findText(venvName)
178 if index < 0:
179 index = 0
180 comboBox.setCurrentIndex(index)
181
182 def __populateAndSetVenvComboBoxes(self, initial):
183 """
184 Private method to populate the virtual environment combo boxes.
185
186 @param initial flag indicating an initial population
187 @type bool
188 """
189 self.__populateAndSetVenvComboBox(
190 self.pyqt5VenvComboBox, "PyQtVenvName", initial)
191 self.__populateAndSetVenvComboBox(
192 self.pyqt6VenvComboBox, "PyQt6VenvName", initial)
193 self.__populateAndSetVenvComboBox(
194 self.pyside2VenvComboBox, "PySide2VenvName", initial)
195 self.__populateAndSetVenvComboBox(
196 self.pyside6VenvComboBox, "PySide6VenvName", initial)
197
198 def __showVirtualEnvManager(self):
199 """
200 Private method to show the virtual environment manager dialog.
201 """
202 self.__virtualenvManager.showVirtualenvManagerDialog(modal=True)
203 self.__populateAndSetVenvComboBoxes(False)
204 self.activateWindow()
205 self.raise_()
206
207 @pyqtSlot()
208 def on_pyqt5VenvDlgButton_clicked(self):
209 """
210 Private slot to show the virtual environment manager dialog.
211 """
212 self.__showVirtualEnvManager()
213
214 @pyqtSlot()
215 def on_pyqt6VenvDlgButton_clicked(self):
216 """
217 Private slot to show the virtual environment manager dialog.
218 """
219 self.__showVirtualEnvManager()
220
221 @pyqtSlot()
222 def on_pyside2VenvDlgButton_clicked(self):
223 """
224 Private slot to show the virtual environment manager dialog.
225 """
226 self.__showVirtualEnvManager()
227
228 @pyqtSlot()
229 def on_pyside6VenvDlgButton_clicked(self):
230 """
231 Private slot to show the virtual environment manager dialog.
232 """
233 self.__showVirtualEnvManager()
234
235
236 def create(dlg):
237 """
238 Module function to create the configuration page.
239
240 @param dlg reference to the configuration dialog
241 @return reference to the instantiated page (ConfigurationPageBase)
242 """
243 page = QtPage()
244 return page

eric ide

mercurial