src/eric7/MultiProject/AddProjectDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
22 22
23 class AddProjectDialog(QDialog, Ui_AddProjectDialog): 23 class AddProjectDialog(QDialog, Ui_AddProjectDialog):
24 """ 24 """
25 Class implementing the add project dialog. 25 Class implementing the add project dialog.
26 """ 26 """
27 def __init__(self, parent=None, startdir="", project=None, 27
28 categories=None, category=""): 28 def __init__(
29 self, parent=None, startdir="", project=None, categories=None, category=""
30 ):
29 """ 31 """
30 Constructor 32 Constructor
31 33
32 @param parent parent widget of this dialog 34 @param parent parent widget of this dialog
33 @type QWidget 35 @type QWidget
34 @param startdir start directory for the selection dialog 36 @param startdir start directory for the selection dialog
35 @type str 37 @type str
36 @param project dictionary containing project data 38 @param project dictionary containing project data
40 @param category category to be preset 42 @param category category to be preset
41 @type str 43 @type str
42 """ 44 """
43 super().__init__(parent) 45 super().__init__(parent)
44 self.setupUi(self) 46 self.setupUi(self)
45 47
46 self.filenamePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) 48 self.filenamePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
47 self.filenamePicker.setFilters( 49 self.filenamePicker.setFilters(
48 self.tr("Project Files (*.epj);;XML Project Files (*.e4p)")) 50 self.tr("Project Files (*.epj);;XML Project Files (*.e4p)")
51 )
49 self.filenamePicker.setDefaultDirectory( 52 self.filenamePicker.setDefaultDirectory(
50 Preferences.getMultiProject("Workspace")) 53 Preferences.getMultiProject("Workspace")
51 54 )
55
52 if categories: 56 if categories:
53 self.categoryComboBox.addItem("") 57 self.categoryComboBox.addItem("")
54 self.categoryComboBox.addItems(sorted(categories)) 58 self.categoryComboBox.addItems(sorted(categories))
55 self.categoryComboBox.setEditText(category) 59 self.categoryComboBox.setEditText(category)
56 60
57 self.startdir = startdir 61 self.startdir = startdir
58 self.uid = "" 62 self.uid = ""
59 63
60 self.__okButton = self.buttonBox.button( 64 self.__okButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok)
61 QDialogButtonBox.StandardButton.Ok)
62 self.__okButton.setEnabled(False) 65 self.__okButton.setEnabled(False)
63 66
64 if project is not None: 67 if project is not None:
65 self.setWindowTitle(self.tr("Project Properties")) 68 self.setWindowTitle(self.tr("Project Properties"))
66 69
67 self.nameEdit.setText(project['name']) 70 self.nameEdit.setText(project["name"])
68 self.filenamePicker.setText(project['file']) 71 self.filenamePicker.setText(project["file"])
69 self.descriptionEdit.setPlainText(project['description']) 72 self.descriptionEdit.setPlainText(project["description"])
70 self.masterCheckBox.setChecked(project['master']) 73 self.masterCheckBox.setChecked(project["master"])
71 index = self.categoryComboBox.findText(project['category']) 74 index = self.categoryComboBox.findText(project["category"])
72 if index == -1: 75 if index == -1:
73 index = 0 76 index = 0
74 self.categoryComboBox.setCurrentIndex(index) 77 self.categoryComboBox.setCurrentIndex(index)
75 self.uid = project["uid"] 78 self.uid = project["uid"]
76 79
77 def getData(self): 80 def getData(self):
78 """ 81 """
79 Public slot to retrieve the dialogs data. 82 Public slot to retrieve the dialogs data.
80 83
81 @return tuple of five values (string, string, boolean, string, string) 84 @return tuple of five values (string, string, boolean, string, string)
82 giving the project name, the name of the project file, a flag 85 giving the project name, the name of the project file, a flag
83 telling whether the project shall be the main project, a short 86 telling whether the project shall be the main project, a short
84 description for the project and the project category 87 description for the project and the project category
85 """ 88 """
86 if not self.uid: 89 if not self.uid:
87 # new project entry 90 # new project entry
88 from PyQt6.QtCore import QUuid 91 from PyQt6.QtCore import QUuid
92
89 self.uid = QUuid.createUuid().toString() 93 self.uid = QUuid.createUuid().toString()
90 94
91 filename = self.filenamePicker.text() 95 filename = self.filenamePicker.text()
92 if not os.path.isabs(filename): 96 if not os.path.isabs(filename):
93 filename = Utilities.toNativeSeparators( 97 filename = Utilities.toNativeSeparators(
94 os.path.join(self.startdir, filename)) 98 os.path.join(self.startdir, filename)
95 return (self.nameEdit.text(), 99 )
96 filename, 100 return (
97 self.masterCheckBox.isChecked(), 101 self.nameEdit.text(),
98 self.descriptionEdit.toPlainText(), 102 filename,
99 self.categoryComboBox.currentText(), 103 self.masterCheckBox.isChecked(),
100 self.uid) 104 self.descriptionEdit.toPlainText(),
101 105 self.categoryComboBox.currentText(),
106 self.uid,
107 )
108
102 @pyqtSlot(str) 109 @pyqtSlot(str)
103 def on_nameEdit_textChanged(self, txt): 110 def on_nameEdit_textChanged(self, txt):
104 """ 111 """
105 Private slot called when the project name has changed. 112 Private slot called when the project name has changed.
106 113
107 @param txt text of the edit (string) 114 @param txt text of the edit (string)
108 """ 115 """
109 self.__updateUi() 116 self.__updateUi()
110 117
111 @pyqtSlot(str) 118 @pyqtSlot(str)
112 def on_filenamePicker_textChanged(self, txt): 119 def on_filenamePicker_textChanged(self, txt):
113 """ 120 """
114 Private slot called when the project filename has changed. 121 Private slot called when the project filename has changed.
115 122
116 @param txt text of the edit (string) 123 @param txt text of the edit (string)
117 """ 124 """
118 self.__updateUi() 125 self.__updateUi()
119 126
120 def __updateUi(self): 127 def __updateUi(self):
121 """ 128 """
122 Private method to update the dialog. 129 Private method to update the dialog.
123 """ 130 """
124 self.__okButton.setEnabled(self.nameEdit.text() != "" and 131 self.__okButton.setEnabled(
125 self.filenamePicker.text() != "") 132 self.nameEdit.text() != "" and self.filenamePicker.text() != ""
133 )

eric ide

mercurial