src/eric7/Project/PropertiesDialog.py

branch
eric7-maintenance
changeset 9654
7328efba128b
parent 9549
67295777d9fe
parent 9653
e67609152c5e
child 10174
6aac1022f330
equal deleted inserted replaced
9555:88f10deec960 9654:7328efba128b
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 2
3 # Copyright (c) 2002 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2002 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>
4 # 4 #
5 5
6 """ 6 """
7 Module implementing the project properties dialog. 7 Module implementing the project properties dialog.
8 """ 8 """
13 import trove_classifiers 13 import trove_classifiers
14 14
15 from PyQt6.QtCore import QDir, pyqtSlot 15 from PyQt6.QtCore import QDir, pyqtSlot
16 from PyQt6.QtWidgets import QDialog, QDialogButtonBox 16 from PyQt6.QtWidgets import QDialog, QDialogButtonBox
17 17
18 from eric7 import Preferences, Utilities 18 from eric7 import Preferences
19 from eric7.EricGui import EricPixmapCache 19 from eric7.EricGui import EricPixmapCache
20 from eric7.EricWidgets.EricApplication import ericApp 20 from eric7.EricWidgets.EricApplication import ericApp
21 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes 21 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes
22 from eric7.QScintilla.DocstringGenerator import getSupportedDocstringTypes 22 from eric7.QScintilla.DocstringGenerator import getSupportedDocstringTypes
23 from eric7.SystemUtilities import FileSystemUtilities, OSUtilities
23 from eric7.Testing.Interfaces import FrameworkNames 24 from eric7.Testing.Interfaces import FrameworkNames
24 25
25 from .Ui_PropertiesDialog import Ui_PropertiesDialog 26 from .Ui_PropertiesDialog import Ui_PropertiesDialog
26 27
27 28
33 def __init__(self, project, new=True, parent=None, name=None): 34 def __init__(self, project, new=True, parent=None, name=None):
34 """ 35 """
35 Constructor 36 Constructor
36 37
37 @param project reference to the project object 38 @param project reference to the project object
39 @type Project
38 @param new flag indicating the generation of a new project 40 @param new flag indicating the generation of a new project
39 @param parent parent widget of this dialog (QWidget) 41 (defaults to True)
40 @param name name of this dialog (string) 42 @type bool (optional)
43 @param parent parent widget of this dialog (defaults to None)
44 @type QWidget (optional)
45 @param name name of this dialog (defaults to None)
46 @type str (optional)
41 """ 47 """
42 super().__init__(parent) 48 super().__init__(parent)
43 if name: 49 if name:
44 self.setObjectName(name) 50 self.setObjectName(name)
45 self.setupUi(self) 51 self.setupUi(self)
56 self.project = project 62 self.project = project
57 self.newProject = new 63 self.newProject = new
58 self.transPropertiesDlg = None 64 self.transPropertiesDlg = None
59 self.spellPropertiesDlg = None 65 self.spellPropertiesDlg = None
60 self.makePropertiesDlg = None 66 self.makePropertiesDlg = None
67 self.__fileTypesDict = {}
61 68
62 patterns = [] 69 patterns = []
63 for pattern, filetype in self.project.getProjectData( 70 for pattern, filetype in self.project.getProjectData(
64 dataKey="FILETYPES" 71 dataKey="FILETYPES"
65 ).items(): 72 ).items():
77 projectTypes.append((projectTypeItem[1], projectTypeItem[0])) 84 projectTypes.append((projectTypeItem[1], projectTypeItem[0]))
78 self.projectTypeComboBox.clear() 85 self.projectTypeComboBox.clear()
79 for projectType in sorted(projectTypes): 86 for projectType in sorted(projectTypes):
80 self.projectTypeComboBox.addItem(projectType[0], projectType[1]) 87 self.projectTypeComboBox.addItem(projectType[0], projectType[1])
81 88
82 ipath = Preferences.getMultiProject("Workspace") or Utilities.getHomeDir() 89 ipath = Preferences.getMultiProject("Workspace") or OSUtilities.getHomeDir()
83 self.__initPaths = [ 90 self.__initPaths = [
84 Utilities.fromNativeSeparators(ipath), 91 FileSystemUtilities.fromNativeSeparators(ipath),
85 Utilities.fromNativeSeparators(ipath) + "/", 92 FileSystemUtilities.fromNativeSeparators(ipath) + "/",
86 ] 93 ]
87 94
88 self.licenseComboBox.lineEdit().setClearButtonEnabled(True) 95 self.licenseComboBox.lineEdit().setClearButtonEnabled(True)
89 self.__populateLicenseComboBox() 96 self.__populateLicenseComboBox()
90 97
168 self.vcsLabel.hide() 175 self.vcsLabel.hide()
169 self.vcsInfoButton.hide() 176 self.vcsInfoButton.hide()
170 if not self.project.vcsSoftwareAvailable(): 177 if not self.project.vcsSoftwareAvailable():
171 self.vcsCheckBox.hide() 178 self.vcsCheckBox.hide()
172 179
180 self.__origProgrammingLanguage = self.languageComboBox.currentText()
181 self.__origMixedFlag = self.mixedLanguageCheckBox.isChecked()
182 self.__origProjectType = self.getProjectType()
183
184 self.languageComboBox.currentTextChanged.connect(self.__initFileTypesDict)
185 self.mixedLanguageCheckBox.stateChanged.connect(self.__initFileTypesDict)
186 self.projectTypeComboBox.currentIndexChanged.connect(self.__initFileTypesDict)
187
173 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( 188 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(
174 bool(self.dirPicker.text()) 189 bool(self.dirPicker.text())
175 and self.dirPicker.text() not in self.__initPaths 190 and self.dirPicker.text() not in self.__initPaths
176 ) 191 )
177 192
224 Private slot to handle a change of the project directory. 239 Private slot to handle a change of the project directory.
225 240
226 @param txt name of the project directory (string) 241 @param txt name of the project directory (string)
227 """ 242 """
228 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( 243 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(
229 bool(txt) and Utilities.fromNativeSeparators(txt) not in self.__initPaths 244 bool(txt)
245 and FileSystemUtilities.fromNativeSeparators(txt) not in self.__initPaths
230 ) 246 )
231 247
232 @pyqtSlot() 248 @pyqtSlot()
233 def on_spellPropertiesButton_clicked(self): 249 def on_spellPropertiesButton_clicked(self):
234 """ 250 """
331 Public method to get the project path. 347 Public method to get the project path.
332 348
333 @return data of the project directory edit (string) 349 @return data of the project directory edit (string)
334 """ 350 """
335 return os.path.abspath(self.dirPicker.text()) 351 return os.path.abspath(self.dirPicker.text())
352
353 @pyqtSlot()
354 def __initFileTypesDict(self):
355 """
356 Private slot to (re-)initialize the filetype dictionary.
357 """
358 if (
359 self.__origProgrammingLanguage != self.languageComboBox.currentText()
360 or self.__origMixedFlag != self.mixedLanguageCheckBox.isChecked()
361 or self.__origProjectType != self.getProjectType()
362 ):
363 # any of the defining data got changed
364 self.__fileTypesDict = self.project.defaultFileTypes(
365 self.languageComboBox.currentText(),
366 self.mixedLanguageCheckBox.isChecked(),
367 self.getProjectType(),
368 )
369 else:
370 # all of the defining data was changed back to original
371 self.__fileTypesDict = self.project.getProjectData(dataKey="FILETYPES")
372
373 @pyqtSlot()
374 def on_filetypesButton_clicked(self):
375 """
376 Private slot to open a dialog to edit the filetype associations.
377 """
378 from .FiletypeAssociationDialog import FiletypeAssociationDialog
379
380 if not self.__fileTypesDict:
381 self.__fileTypesDict = self.project.getProjectData(dataKey="FILETYPES")
382 if (
383 not self.__fileTypesDict
384 or self.__origProgrammingLanguage != self.languageComboBox.currentText()
385 or self.__origMixedFlag != self.mixedLanguageCheckBox.isChecked()
386 or self.__origProjectType != self.getProjectType()
387 ):
388 # the associations were not defined yet or any of the defining data got
389 # changed
390 self.__fileTypesDict = self.project.defaultFileTypes(
391 self.languageComboBox.currentText(),
392 self.mixedLanguageCheckBox.isChecked(),
393 self.getProjectType(),
394 )
395
396 dlg = FiletypeAssociationDialog(self.project, self.__fileTypesDict)
397 if dlg.exec() == QDialog.DialogCode.Accepted:
398 self.__fileTypesDict = dlg.getData()
336 399
337 def storeData(self): 400 def storeData(self):
338 """ 401 """
339 Public method to store the entered/modified data. 402 Public method to store the entered/modified data.
340 """ 403 """
398 ) 461 )
399 462
400 self.project.setProjectData( 463 self.project.setProjectData(
401 self.embeddedVenvCheckBox.isChecked(), dataKey="EMBEDDED_VENV" 464 self.embeddedVenvCheckBox.isChecked(), dataKey="EMBEDDED_VENV"
402 ) 465 )
466
467 if self.__fileTypesDict:
468 self.project.setProjectData(self.__fileTypesDict, dataKey="FILETYPES")

eric ide

mercurial