15 |
15 |
16 class CreateParametersDialog(QDialog, Ui_CreateParametersDialog): |
16 class CreateParametersDialog(QDialog, Ui_CreateParametersDialog): |
17 """ |
17 """ |
18 Class implementing a dialog for entering the create parameters. |
18 Class implementing a dialog for entering the create parameters. |
19 """ |
19 """ |
|
20 |
20 PyramidStarterGH = "gh:Pylons/pyramid-cookiecutter-starter" |
21 PyramidStarterGH = "gh:Pylons/pyramid-cookiecutter-starter" |
21 PyramidStarter = "pyramid-cookiecutter-starter" |
22 PyramidStarter = "pyramid-cookiecutter-starter" |
22 PyramidStarterZip = "pyramid-cookiecutter-starter.zip" |
23 PyramidStarterZip = "pyramid-cookiecutter-starter.zip" |
23 |
24 |
24 def __init__(self, parent=None): |
25 def __init__(self, parent=None): |
25 """ |
26 """ |
26 Constructor |
27 Constructor |
27 |
28 |
28 @param parent reference to the parent widget |
29 @param parent reference to the parent widget |
29 @type QWidget |
30 @type QWidget |
30 """ |
31 """ |
31 super().__init__(parent) |
32 super().__init__(parent) |
32 self.setupUi(self) |
33 self.setupUi(self) |
33 |
34 |
34 self.__okButton = self.buttonBox.button( |
35 self.__okButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok) |
35 QDialogButtonBox.StandardButton.Ok) |
|
36 self.__okButton.setEnabled(False) |
36 self.__okButton.setEnabled(False) |
37 |
37 |
38 self.templateCombo.addItems([ |
38 self.templateCombo.addItems( |
39 "", |
39 [ |
40 CreateParametersDialog.PyramidStarter, |
40 "", |
41 CreateParametersDialog.PyramidStarterGH, |
41 CreateParametersDialog.PyramidStarter, |
42 CreateParametersDialog.PyramidStarterZip, |
42 CreateParametersDialog.PyramidStarterGH, |
43 ]) |
43 CreateParametersDialog.PyramidStarterZip, |
44 |
44 ] |
|
45 ) |
|
46 |
45 self.templateLanguageCombo.addItem("Jinja2", "jinja") |
47 self.templateLanguageCombo.addItem("Jinja2", "jinja") |
46 self.templateLanguageCombo.addItem("Chameleon", "chameleon") |
48 self.templateLanguageCombo.addItem("Chameleon", "chameleon") |
47 self.templateLanguageCombo.addItem("Mako", "mako") |
49 self.templateLanguageCombo.addItem("Mako", "mako") |
48 |
50 |
49 self.backendCombo.addItem(self.tr("No Database"), "none") |
51 self.backendCombo.addItem(self.tr("No Database"), "none") |
50 self.backendCombo.addItem("SQLAlchemy", "sqlalchemy") |
52 self.backendCombo.addItem("SQLAlchemy", "sqlalchemy") |
51 self.backendCombo.addItem("ZODB", "zodb") |
53 self.backendCombo.addItem("ZODB", "zodb") |
52 |
54 |
53 self.starterGroupBox.setEnabled(False) |
55 self.starterGroupBox.setEnabled(False) |
54 |
56 |
55 msh = self.minimumSizeHint() |
57 msh = self.minimumSizeHint() |
56 self.resize(max(self.width(), msh.width()), msh.height()) |
58 self.resize(max(self.width(), msh.width()), msh.height()) |
57 |
59 |
58 @pyqtSlot(str) |
60 @pyqtSlot(str) |
59 def on_templateCombo_currentTextChanged(self, text): |
61 def on_templateCombo_currentTextChanged(self, text): |
60 """ |
62 """ |
61 Private slot to handle changes of the selected scaffold. |
63 Private slot to handle changes of the selected scaffold. |
62 |
64 |
63 @param text text of the combo box |
65 @param text text of the combo box |
64 @type str |
66 @type str |
65 """ |
67 """ |
66 self.__updateUi() |
68 self.__updateUi() |
67 |
69 |
68 def __updateUi(self): |
70 def __updateUi(self): |
69 """ |
71 """ |
70 Private slot to update the dialog. |
72 Private slot to update the dialog. |
71 """ |
73 """ |
72 template = self.templateCombo.currentText() |
74 template = self.templateCombo.currentText() |
73 |
75 |
74 self.__okButton.setEnabled(bool(template)) |
76 self.__okButton.setEnabled(bool(template)) |
75 |
77 |
76 self.starterGroupBox.setEnabled( |
78 self.starterGroupBox.setEnabled( |
77 CreateParametersDialog.PyramidStarter in template) |
79 CreateParametersDialog.PyramidStarter in template |
78 |
80 ) |
79 self.versionEdit.setEnabled( |
81 |
80 template == CreateParametersDialog.PyramidStarterGH) |
82 self.versionEdit.setEnabled(template == CreateParametersDialog.PyramidStarterGH) |
81 |
83 |
82 def getData(self): |
84 def getData(self): |
83 """ |
85 """ |
84 Public method to get the data. |
86 Public method to get the data. |
85 |
87 |
86 @return tuple giving the template name, an optional template version, |
88 @return tuple giving the template name, an optional template version, |
87 a flag indicating to overwrite existing files and a dictionary |
89 a flag indicating to overwrite existing files and a dictionary |
88 containing additional context data |
90 containing additional context data |
89 @rtype tuple of (str, str, bool) |
91 @rtype tuple of (str, str, bool) |
90 """ |
92 """ |
91 template = self.templateCombo.currentText() |
93 template = self.templateCombo.currentText() |
92 |
94 |
93 contextData = ( |
95 contextData = ( |
94 { |
96 { |
95 "project_name": self.projectEdit.text(), |
97 "project_name": self.projectEdit.text(), |
96 "repo_name": ( |
98 "repo_name": ( |
97 self.projectEdit.text().lower().strip().replace(' ', '_') |
99 self.projectEdit.text() |
98 .replace(':', '_').replace('-', '_').replace('!', '_')), |
100 .lower() |
|
101 .strip() |
|
102 .replace(" ", "_") |
|
103 .replace(":", "_") |
|
104 .replace("-", "_") |
|
105 .replace("!", "_") |
|
106 ), |
99 "template_language": self.templateLanguageCombo.currentData(), |
107 "template_language": self.templateLanguageCombo.currentData(), |
100 "backend": self.backendCombo.currentData(), |
108 "backend": self.backendCombo.currentData(), |
101 } |
109 } |
102 if CreateParametersDialog.PyramidStarter in template else |
110 if CreateParametersDialog.PyramidStarter in template |
103 {} |
111 else {} |
104 ) |
112 ) |
105 |
113 |
106 version = ( |
114 version = ( |
107 self.versionEdit.text() |
115 self.versionEdit.text() |
108 if template == CreateParametersDialog.PyramidStarterGH else |
116 if template == CreateParametersDialog.PyramidStarterGH |
109 "" |
117 else "" |
110 ) |
118 ) |
111 |
119 |
112 return ( |
120 return (template, version, self.overwriteCheckBox.isChecked(), contextData) |
113 template, |
|
114 version, |
|
115 self.overwriteCheckBox.isChecked(), |
|
116 contextData |
|
117 ) |
|