|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog for entering the create parameters. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSlot, QProcess |
|
11 from PyQt4.QtGui import QDialog, QDialogButtonBox |
|
12 |
|
13 from E5Gui import E5MessageBox |
|
14 |
|
15 from .Ui_CreateParametersDialog import Ui_CreateParametersDialog |
|
16 |
|
17 import Preferences |
|
18 |
|
19 |
|
20 class CreateParametersDialog(QDialog, Ui_CreateParametersDialog): |
|
21 """ |
|
22 Class implementing a dialog for entering the create parameters. |
|
23 """ |
|
24 def __init__(self, project, parent=None): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param project reference to the project object (Project) |
|
29 @param parent reference to the parent widget (QWidget) |
|
30 """ |
|
31 super().__init__(parent) |
|
32 self.setupUi(self) |
|
33 |
|
34 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
|
35 self.__okButton.setEnabled(False) |
|
36 |
|
37 errMsg = "" |
|
38 proc = QProcess() |
|
39 args = [] |
|
40 args.append(project.getPyramidCommand("pcreate")) |
|
41 args.append("--list") |
|
42 proc.start(args[0], args[1:]) |
|
43 procStarted = proc.waitForStarted() |
|
44 if procStarted: |
|
45 finished = proc.waitForFinished(30000) |
|
46 if finished and proc.exitCode() == 0: |
|
47 output = \ |
|
48 str(proc.readAllStandardOutput(), |
|
49 Preferences.getSystem("IOEncoding"), |
|
50 'replace') |
|
51 else: |
|
52 if not finished: |
|
53 errMsg = self.trUtf8( |
|
54 "The pcreate command did not finish within 30s.") |
|
55 else: |
|
56 errMsg = self.trUtf8("Could not start the pcreate executable.") |
|
57 if not errMsg: |
|
58 scaffolds = output.splitlines() |
|
59 self.scaffoldCombo.addItem("") |
|
60 for scaffold in sorted(scaffolds[1:]): |
|
61 self.scaffoldCombo.addItem(scaffold.strip()) |
|
62 self.scaffoldCombo.setCurrentIndex(0) |
|
63 else: |
|
64 E5MessageBox.critical(None, |
|
65 self.trUtf8('Process Generation Error'), |
|
66 errMsg) |
|
67 |
|
68 @pyqtSlot(str) |
|
69 def on_nameEdit_textChanged(self, text): |
|
70 """ |
|
71 Private slot to handle changes of the site name. |
|
72 |
|
73 @param text text of the site entry (string) |
|
74 """ |
|
75 self.__updateUi() |
|
76 |
|
77 @pyqtSlot(str) |
|
78 def on_scaffoldCombo_currentIndexChanged(self, text): |
|
79 """ |
|
80 Private slot to handle changes of the selected scaffold. |
|
81 |
|
82 @param text text of the combo box (string) |
|
83 """ |
|
84 self.__updateUi() |
|
85 |
|
86 def __updateUi(self): |
|
87 """ |
|
88 Private slot to update the dialog. |
|
89 """ |
|
90 self.__okButton.setEnabled( |
|
91 bool(self.scaffoldCombo.currentText()) and \ |
|
92 bool(self.nameEdit.text()) |
|
93 ) |
|
94 |
|
95 def getData(self): |
|
96 """ |
|
97 Public method to get the data. |
|
98 |
|
99 @return tuple giving the scaffold (string), the project name (string), |
|
100 a flag indicating to overwrite existing files (boolean) and a flag |
|
101 indicating to simulate the creation (boolean) |
|
102 """ |
|
103 return ( |
|
104 self.scaffoldCombo.currentText().split(":")[0], |
|
105 self.nameEdit.text(), |
|
106 self.overwriteCheckBox.isChecked(), |
|
107 self.simulateCheckBox.isChecked() |
|
108 ) |