16 from E5Gui import E5FileDialog |
16 from E5Gui import E5FileDialog |
17 |
17 |
18 from .Ui_AddProjectDialog import Ui_AddProjectDialog |
18 from .Ui_AddProjectDialog import Ui_AddProjectDialog |
19 |
19 |
20 import Utilities |
20 import Utilities |
|
21 import UI.PixmapCache |
21 |
22 |
22 |
23 |
23 class AddProjectDialog(QDialog, Ui_AddProjectDialog): |
24 class AddProjectDialog(QDialog, Ui_AddProjectDialog): |
24 """ |
25 """ |
25 Class implementing the add project dialog. |
26 Class implementing the add project dialog. |
26 """ |
27 """ |
27 def __init__(self, parent=None, startdir=None, project=None): |
28 def __init__(self, parent=None, startdir=None, project=None, |
|
29 categories=None): |
28 """ |
30 """ |
29 Constructor |
31 Constructor |
30 |
32 |
31 @param parent parent widget of this dialog (QWidget) |
33 @param parent parent widget of this dialog (QWidget) |
32 @param startdir start directory for the selection dialog (string) |
34 @param startdir start directory for the selection dialog (string) |
33 @param project dictionary containing project data |
35 @param project dictionary containing project data |
|
36 @param categories list of already used categories (list of string) |
34 """ |
37 """ |
35 super(AddProjectDialog, self).__init__(parent) |
38 super(AddProjectDialog, self).__init__(parent) |
36 self.setupUi(self) |
39 self.setupUi(self) |
37 |
40 |
|
41 self.fileButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
|
42 |
38 self.fileCompleter = E5FileCompleter(self.filenameEdit) |
43 self.fileCompleter = E5FileCompleter(self.filenameEdit) |
|
44 |
|
45 if categories: |
|
46 self.categoryComboBox.addItem("") |
|
47 self.categoryComboBox.addItems(sorted(categories)) |
39 |
48 |
40 self.startdir = startdir |
49 self.startdir = startdir |
41 |
50 |
42 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
51 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
43 self.__okButton.setEnabled(False) |
52 self.__okButton.setEnabled(False) |
44 |
53 |
45 if project is not None: |
54 if project is not None: |
46 self.setWindowTitle(self.trUtf8("Project Properties")) |
55 self.setWindowTitle(self.tr("Project Properties")) |
47 |
56 |
48 self.filenameEdit.setReadOnly(True) |
57 self.filenameEdit.setReadOnly(True) |
49 self.fileButton.setEnabled(False) |
58 self.fileButton.setEnabled(False) |
50 |
59 |
51 self.nameEdit.setText(project['name']) |
60 self.nameEdit.setText(project['name']) |
52 self.filenameEdit.setText(project['file']) |
61 self.filenameEdit.setText(project['file']) |
53 self.descriptionEdit.setPlainText(project['description']) |
62 self.descriptionEdit.setPlainText(project['description']) |
54 self.masterCheckBox.setChecked(project['master']) |
63 self.masterCheckBox.setChecked(project['master']) |
|
64 index = self.categoryComboBox.findText(project['category']) |
|
65 if index == -1: |
|
66 index = 0 |
|
67 self.categoryComboBox.setCurrentIndex(index) |
55 |
68 |
56 @pyqtSlot() |
69 @pyqtSlot() |
57 def on_fileButton_clicked(self): |
70 def on_fileButton_clicked(self): |
58 """ |
71 """ |
59 Private slot to display a file selection dialog. |
72 Private slot to display a file selection dialog. |
61 startdir = self.filenameEdit.text() |
74 startdir = self.filenameEdit.text() |
62 if not startdir and self.startdir is not None: |
75 if not startdir and self.startdir is not None: |
63 startdir = self.startdir |
76 startdir = self.startdir |
64 projectFile = E5FileDialog.getOpenFileName( |
77 projectFile = E5FileDialog.getOpenFileName( |
65 self, |
78 self, |
66 self.trUtf8("Add Project"), |
79 self.tr("Add Project"), |
67 startdir, |
80 startdir, |
68 self.trUtf8("Project Files (*.e4p)")) |
81 self.tr("Project Files (*.e4p)")) |
69 |
82 |
70 if projectFile: |
83 if projectFile: |
71 self.filenameEdit.setText( |
84 self.filenameEdit.setText( |
72 Utilities.toNativeSeparators(projectFile)) |
85 Utilities.toNativeSeparators(projectFile)) |
73 |
86 |
74 def getData(self): |
87 def getData(self): |
75 """ |
88 """ |
76 Public slot to retrieve the dialogs data. |
89 Public slot to retrieve the dialogs data. |
77 |
90 |
78 @return tuple of four values (string, string, boolean, string) giving |
91 @return tuple of five values (string, string, boolean, string, string) |
79 the project name, the name of the project file, a flag telling, |
92 giving the project name, the name of the project file, a flag |
80 whether the project shall be the main project and a short |
93 telling whether the project shall be the main project, a short |
81 description for the project |
94 description for the project and the project category |
82 """ |
95 """ |
83 return (self.nameEdit.text(), self.filenameEdit.text(), |
96 return (self.nameEdit.text(), |
|
97 self.filenameEdit.text(), |
84 self.masterCheckBox.isChecked(), |
98 self.masterCheckBox.isChecked(), |
85 self.descriptionEdit.toPlainText()) |
99 self.descriptionEdit.toPlainText(), |
|
100 self.categoryComboBox.currentText()) |
86 |
101 |
87 @pyqtSlot(str) |
102 @pyqtSlot(str) |
88 def on_nameEdit_textChanged(self, txt): |
103 def on_nameEdit_textChanged(self, txt): |
89 """ |
104 """ |
90 Private slot called when the project name has changed. |
105 Private slot called when the project name has changed. |