ProjectPyramid/CreateParametersDialog.py

branch
eric7
changeset 148
dcbd3a96f03c
parent 147
eb28b4b6f7f5
child 150
b916658d5014
diff -r eb28b4b6f7f5 -r dcbd3a96f03c ProjectPyramid/CreateParametersDialog.py
--- a/ProjectPyramid/CreateParametersDialog.py	Tue Jun 01 19:37:46 2021 +0200
+++ b/ProjectPyramid/CreateParametersDialog.py	Sun Jun 06 16:30:37 2021 +0200
@@ -7,26 +7,23 @@
 Module implementing a dialog for entering the create parameters.
 """
 
-from PyQt6.QtCore import pyqtSlot, QProcess
+from PyQt6.QtCore import pyqtSlot
 from PyQt6.QtWidgets import QDialog, QDialogButtonBox
 
-from EricWidgets import EricMessageBox
-
 from .Ui_CreateParametersDialog import Ui_CreateParametersDialog
 
-import Preferences
-
 
 class CreateParametersDialog(QDialog, Ui_CreateParametersDialog):
     """
     Class implementing a dialog for entering the create parameters.
     """
-    def __init__(self, project, parent=None):
+    PyramidStarterGH = "gh:Pylons/pyramid-cookiecutter-starter"
+    PyramidStarter = "pyramid-cookiecutter-starter"
+    
+    def __init__(self, parent=None):
         """
         Constructor
         
-        @param project reference to the project object
-        @type Project
         @param parent reference to the parent widget
         @type QWidget
         """
@@ -37,53 +34,27 @@
             QDialogButtonBox.StandardButton.Ok)
         self.__okButton.setEnabled(False)
         
-        errMsg = ""
-        proc = QProcess()
-        args = []
-        args.append(project.getPyramidCommand("pcreate"))
-        args.append("--list")
-        proc.start(args[0], args[1:])
-        procStarted = proc.waitForStarted()
-        if procStarted:
-            finished = proc.waitForFinished(30000)
-            if finished and proc.exitCode() == 0:
-                output = str(proc.readAllStandardOutput(),
-                             Preferences.getSystem("IOEncoding"),
-                             'replace')
-            else:
-                if not finished:
-                    errMsg = self.tr(
-                        "The pcreate command did not finish within 30s.")
-        else:
-            errMsg = self.tr("Could not start the pcreate executable.")
-        if not errMsg:
-            lines = output.splitlines()
-            self.scaffoldCombo.addItem("")
-            for line in sorted(lines[1:]):
-                self.scaffoldCombo.addItem(
-                    self.__prepareScaffoldString(line))
-            self.scaffoldCombo.setCurrentIndex(0)
-        else:
-            EricMessageBox.critical(
-                None,
-                self.tr('Process Generation Error'),
-                errMsg)
+        self.templateCombo.addItems([
+            "",
+            CreateParametersDialog.PyramidStarter,
+            CreateParametersDialog.PyramidStarterGH,
+        ])
+        
+        self.templateLanguageCombo.addItem("Jinja2", "jinja")
+        self.templateLanguageCombo.addItem("Chameleon", "chameleon")
+        self.templateLanguageCombo.addItem("Mako", "mako")
+        
+        self.backendCombo.addItem(self.tr("No Database"), "none")
+        self.backendCombo.addItem("SQLAlchemy", "sqlalchemy")
+        self.backendCombo.addItem("ZODB", "zodb")
+        
+        self.starterGroupBox.setEnabled(False)
         
         msh = self.minimumSizeHint()
         self.resize(max(self.width(), msh.width()), msh.height())
     
     @pyqtSlot(str)
-    def on_nameEdit_textChanged(self, text):
-        """
-        Private slot to handle changes of the site name.
-        
-        @param text text of the site entry
-        @type str
-        """
-        self.__updateUi()
-    
-    @pyqtSlot(str)
-    def on_scaffoldCombo_currentTextChanged(self, text):
+    def on_templateCombo_currentTextChanged(self, text):
         """
         Private slot to handle changes of the selected scaffold.
         
@@ -96,37 +67,54 @@
         """
         Private slot to update the dialog.
         """
-        self.__okButton.setEnabled(
-            bool(self.scaffoldCombo.currentText()) and
-            bool(self.nameEdit.text())
-        )
-    
-    def __prepareScaffoldString(self, line):
-        """
-        Private method to prepare a scaffold string for the combo box.
+        template = self.templateCombo.currentText()
+        
+        self.__okButton.setEnabled(bool(template))
         
-        @param line output line containing the scaffold name and some
-            explanatory text
-        @type str
-        @return prepared scaffold text
-        @rtype str
-        """
-        parts = [part.strip() for part in line.split(":", 1)]
-        return self.tr(
-            "{0} ({1})", "scaffold name, explanatory text").format(*parts)
+        self.starterGroupBox.setEnabled(
+            template in (
+                CreateParametersDialog.PyramidStarter,
+                CreateParametersDialog.PyramidStarterGH,
+            )
+        )
+        
+        self.versionEdit.setEnabled(
+            template == CreateParametersDialog.PyramidStarterGH)
     
     def getData(self):
         """
         Public method to get the data.
         
-        @return tuple giving the scaffold, the project name, a flag indicating
-            to overwrite existing files and a flag indicating to simulate the
-            creation
-        @rtype tuple of (str, str, bool, bool)
+        @return tuple giving the template name, an optional template version,
+            a flag indicating to overwrite existing files and a dictionary
+            containing additional context data
+        @rtype tuple of (str, str, bool)
         """
+        template = self.templateCombo.currentText()
+        
+        contextData = (
+            {
+                "project_name": self.projectEdit.text(),
+                "repo_name": "_".join(self.projectEdit.text().split()).lower(),
+                "template_language": self.templateLanguageCombo.currentData(),
+                "backend": self.backendCombo.currentData(),
+            }
+            if template in (
+                CreateParametersDialog.PyramidStarter,
+                CreateParametersDialog.PyramidStarterGH,
+            ) else
+            {}
+        )
+        
+        version = (
+            self.versionEdit.text()
+            if template == CreateParametersDialog.PyramidStarterGH else
+            ""
+        )
+        
         return (
-            self.scaffoldCombo.currentText().split(":")[0],
-            self.nameEdit.text(),
+            template,
+            version,
             self.overwriteCheckBox.isChecked(),
-            self.simulateCheckBox.isChecked()
+            contextData
         )

eric ide

mercurial