ProjectPyramid/CreateParametersDialog.py

branch
eric7
changeset 148
dcbd3a96f03c
parent 147
eb28b4b6f7f5
child 150
b916658d5014
equal deleted inserted replaced
147:eb28b4b6f7f5 148:dcbd3a96f03c
5 5
6 """ 6 """
7 Module implementing a dialog for entering the create parameters. 7 Module implementing a dialog for entering the create parameters.
8 """ 8 """
9 9
10 from PyQt6.QtCore import pyqtSlot, QProcess 10 from PyQt6.QtCore import pyqtSlot
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox 11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox
12 12
13 from EricWidgets import EricMessageBox
14
15 from .Ui_CreateParametersDialog import Ui_CreateParametersDialog 13 from .Ui_CreateParametersDialog import Ui_CreateParametersDialog
16
17 import Preferences
18 14
19 15
20 class CreateParametersDialog(QDialog, Ui_CreateParametersDialog): 16 class CreateParametersDialog(QDialog, Ui_CreateParametersDialog):
21 """ 17 """
22 Class implementing a dialog for entering the create parameters. 18 Class implementing a dialog for entering the create parameters.
23 """ 19 """
24 def __init__(self, project, parent=None): 20 PyramidStarterGH = "gh:Pylons/pyramid-cookiecutter-starter"
21 PyramidStarter = "pyramid-cookiecutter-starter"
22
23 def __init__(self, parent=None):
25 """ 24 """
26 Constructor 25 Constructor
27 26
28 @param project reference to the project object
29 @type Project
30 @param parent reference to the parent widget 27 @param parent reference to the parent widget
31 @type QWidget 28 @type QWidget
32 """ 29 """
33 super().__init__(parent) 30 super().__init__(parent)
34 self.setupUi(self) 31 self.setupUi(self)
35 32
36 self.__okButton = self.buttonBox.button( 33 self.__okButton = self.buttonBox.button(
37 QDialogButtonBox.StandardButton.Ok) 34 QDialogButtonBox.StandardButton.Ok)
38 self.__okButton.setEnabled(False) 35 self.__okButton.setEnabled(False)
39 36
40 errMsg = "" 37 self.templateCombo.addItems([
41 proc = QProcess() 38 "",
42 args = [] 39 CreateParametersDialog.PyramidStarter,
43 args.append(project.getPyramidCommand("pcreate")) 40 CreateParametersDialog.PyramidStarterGH,
44 args.append("--list") 41 ])
45 proc.start(args[0], args[1:]) 42
46 procStarted = proc.waitForStarted() 43 self.templateLanguageCombo.addItem("Jinja2", "jinja")
47 if procStarted: 44 self.templateLanguageCombo.addItem("Chameleon", "chameleon")
48 finished = proc.waitForFinished(30000) 45 self.templateLanguageCombo.addItem("Mako", "mako")
49 if finished and proc.exitCode() == 0: 46
50 output = str(proc.readAllStandardOutput(), 47 self.backendCombo.addItem(self.tr("No Database"), "none")
51 Preferences.getSystem("IOEncoding"), 48 self.backendCombo.addItem("SQLAlchemy", "sqlalchemy")
52 'replace') 49 self.backendCombo.addItem("ZODB", "zodb")
53 else: 50
54 if not finished: 51 self.starterGroupBox.setEnabled(False)
55 errMsg = self.tr(
56 "The pcreate command did not finish within 30s.")
57 else:
58 errMsg = self.tr("Could not start the pcreate executable.")
59 if not errMsg:
60 lines = output.splitlines()
61 self.scaffoldCombo.addItem("")
62 for line in sorted(lines[1:]):
63 self.scaffoldCombo.addItem(
64 self.__prepareScaffoldString(line))
65 self.scaffoldCombo.setCurrentIndex(0)
66 else:
67 EricMessageBox.critical(
68 None,
69 self.tr('Process Generation Error'),
70 errMsg)
71 52
72 msh = self.minimumSizeHint() 53 msh = self.minimumSizeHint()
73 self.resize(max(self.width(), msh.width()), msh.height()) 54 self.resize(max(self.width(), msh.width()), msh.height())
74 55
75 @pyqtSlot(str) 56 @pyqtSlot(str)
76 def on_nameEdit_textChanged(self, text): 57 def on_templateCombo_currentTextChanged(self, text):
77 """
78 Private slot to handle changes of the site name.
79
80 @param text text of the site entry
81 @type str
82 """
83 self.__updateUi()
84
85 @pyqtSlot(str)
86 def on_scaffoldCombo_currentTextChanged(self, text):
87 """ 58 """
88 Private slot to handle changes of the selected scaffold. 59 Private slot to handle changes of the selected scaffold.
89 60
90 @param text text of the combo box 61 @param text text of the combo box
91 @type str 62 @type str
94 65
95 def __updateUi(self): 66 def __updateUi(self):
96 """ 67 """
97 Private slot to update the dialog. 68 Private slot to update the dialog.
98 """ 69 """
99 self.__okButton.setEnabled( 70 template = self.templateCombo.currentText()
100 bool(self.scaffoldCombo.currentText()) and 71
101 bool(self.nameEdit.text()) 72 self.__okButton.setEnabled(bool(template))
73
74 self.starterGroupBox.setEnabled(
75 template in (
76 CreateParametersDialog.PyramidStarter,
77 CreateParametersDialog.PyramidStarterGH,
78 )
102 ) 79 )
103
104 def __prepareScaffoldString(self, line):
105 """
106 Private method to prepare a scaffold string for the combo box.
107 80
108 @param line output line containing the scaffold name and some 81 self.versionEdit.setEnabled(
109 explanatory text 82 template == CreateParametersDialog.PyramidStarterGH)
110 @type str
111 @return prepared scaffold text
112 @rtype str
113 """
114 parts = [part.strip() for part in line.split(":", 1)]
115 return self.tr(
116 "{0} ({1})", "scaffold name, explanatory text").format(*parts)
117 83
118 def getData(self): 84 def getData(self):
119 """ 85 """
120 Public method to get the data. 86 Public method to get the data.
121 87
122 @return tuple giving the scaffold, the project name, a flag indicating 88 @return tuple giving the template name, an optional template version,
123 to overwrite existing files and a flag indicating to simulate the 89 a flag indicating to overwrite existing files and a dictionary
124 creation 90 containing additional context data
125 @rtype tuple of (str, str, bool, bool) 91 @rtype tuple of (str, str, bool)
126 """ 92 """
93 template = self.templateCombo.currentText()
94
95 contextData = (
96 {
97 "project_name": self.projectEdit.text(),
98 "repo_name": "_".join(self.projectEdit.text().split()).lower(),
99 "template_language": self.templateLanguageCombo.currentData(),
100 "backend": self.backendCombo.currentData(),
101 }
102 if template in (
103 CreateParametersDialog.PyramidStarter,
104 CreateParametersDialog.PyramidStarterGH,
105 ) else
106 {}
107 )
108
109 version = (
110 self.versionEdit.text()
111 if template == CreateParametersDialog.PyramidStarterGH else
112 ""
113 )
114
127 return ( 115 return (
128 self.scaffoldCombo.currentText().split(":")[0], 116 template,
129 self.nameEdit.text(), 117 version,
130 self.overwriteCheckBox.isChecked(), 118 self.overwriteCheckBox.isChecked(),
131 self.simulateCheckBox.isChecked() 119 contextData
132 ) 120 )

eric ide

mercurial