src/eric7/MultiProject/AddProjectDialog.py

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

eric ide

mercurial