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