|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2008 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the add project dialog. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtGui import * |
|
11 from PyQt4.QtCore import * |
|
12 |
|
13 from E4Gui.E4Completers import E4FileCompleter |
|
14 |
|
15 from Ui_AddProjectDialog import Ui_AddProjectDialog |
|
16 |
|
17 import Utilities |
|
18 |
|
19 class AddProjectDialog(QDialog, Ui_AddProjectDialog): |
|
20 """ |
|
21 Class implementing the add project dialog. |
|
22 """ |
|
23 def __init__(self, parent = None, startdir = None, project = None): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param parent parent widget of this dialog (QWidget) |
|
28 @param startdir start directory for the selection dialog (string) |
|
29 @param project dictionary containing project data |
|
30 """ |
|
31 QDialog.__init__(self, parent) |
|
32 self.setupUi(self) |
|
33 |
|
34 self.fileCompleter = E4FileCompleter(self.filenameEdit) |
|
35 |
|
36 self.startdir = startdir |
|
37 |
|
38 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
|
39 self.__okButton.setEnabled(False) |
|
40 |
|
41 if project is not None: |
|
42 self.setWindowTitle(self.trUtf8("Project Properties")) |
|
43 |
|
44 self.filenameEdit.setReadOnly(True) |
|
45 self.fileButton.setEnabled(False) |
|
46 |
|
47 self.nameEdit.setText(project['name']) |
|
48 self.filenameEdit.setText(project['file']) |
|
49 self.descriptionEdit.setPlainText(project['description']) |
|
50 self.masterCheckBox.setChecked(project['master']) |
|
51 |
|
52 @pyqtSlot() |
|
53 def on_fileButton_clicked(self): |
|
54 """ |
|
55 Private slot to display a file selection dialog. |
|
56 """ |
|
57 startdir = self.filenameEdit.text() |
|
58 if not startdir and self.startdir is not None: |
|
59 startdir = self.startdir |
|
60 projectFile = QFileDialog.getOpenFileName( |
|
61 self, |
|
62 self.trUtf8("Add Project"), |
|
63 startdir, |
|
64 self.trUtf8("Project Files (*.e4p *.e4pz)")) |
|
65 |
|
66 if projectFile: |
|
67 self.filenameEdit.setText(Utilities.toNativeSeparators(projectFile)) |
|
68 |
|
69 def getData(self): |
|
70 """ |
|
71 Public slot to retrieve the dialogs data. |
|
72 |
|
73 @return tuple of four values (string, string, boolean, string) giving the |
|
74 project name, the name of the project file, a flag telling, whether |
|
75 the project shall be the master project and a short description |
|
76 for the project |
|
77 """ |
|
78 return (self.nameEdit.text(), self.filenameEdit.text(), |
|
79 self.masterCheckBox.isChecked(), |
|
80 self.descriptionEdit.toPlainText()) |
|
81 |
|
82 @pyqtSlot(str) |
|
83 def on_nameEdit_textChanged(self, p0): |
|
84 """ |
|
85 Private slot called when the project name has changed. |
|
86 """ |
|
87 self.__updateUi() |
|
88 |
|
89 @pyqtSlot(str) |
|
90 def on_filenameEdit_textChanged(self, p0): |
|
91 """ |
|
92 Private slot called when the project filename has changed. |
|
93 """ |
|
94 self.__updateUi() |
|
95 |
|
96 def __updateUi(self): |
|
97 """ |
|
98 Private method to update the dialog. |
|
99 """ |
|
100 self.__okButton.setEnabled(self.nameEdit.text() != "" and \ |
|
101 self.filenameEdit.text() != "") |