ProjectPyramid/CreateParametersDialog.py

changeset 2
e691c51ab655
child 19
f4adfe6e51b0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ProjectPyramid/CreateParametersDialog.py	Tue Aug 28 17:15:21 2012 +0200
@@ -0,0 +1,108 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a dialog for entering the create parameters.
+"""
+
+from PyQt4.QtCore import pyqtSlot, QProcess
+from PyQt4.QtGui import QDialog, QDialogButtonBox
+
+from E5Gui import E5MessageBox
+
+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):
+        """
+        Constructor
+        
+        @param project reference to the project object (Project)
+        @param parent reference to the parent widget (QWidget)
+        """
+        super().__init__(parent)
+        self.setupUi(self)
+        
+        self.__okButton = self.buttonBox.button(QDialogButtonBox.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.trUtf8(
+                        "The pcreate command did not finish within 30s.")
+        else:
+            errMsg = self.trUtf8("Could not start the pcreate executable.")
+        if not errMsg:
+            scaffolds = output.splitlines()
+            self.scaffoldCombo.addItem("")
+            for scaffold in sorted(scaffolds[1:]):
+                self.scaffoldCombo.addItem(scaffold.strip())
+            self.scaffoldCombo.setCurrentIndex(0)
+        else:
+            E5MessageBox.critical(None,
+                self.trUtf8('Process Generation Error'),
+                errMsg)
+    
+    @pyqtSlot(str)
+    def on_nameEdit_textChanged(self, text):
+        """
+        Private slot to handle changes of the site name.
+        
+        @param text text of the site entry (string)
+        """
+        self.__updateUi()
+    
+    @pyqtSlot(str)
+    def on_scaffoldCombo_currentIndexChanged(self, text):
+        """
+        Private slot to handle changes of the selected scaffold.
+        
+        @param text text of the combo box (string)
+        """
+        self.__updateUi()
+    
+    def __updateUi(self):
+        """
+        Private slot to update the dialog.
+        """
+        self.__okButton.setEnabled(
+            bool(self.scaffoldCombo.currentText()) and \
+            bool(self.nameEdit.text())
+        )
+    
+    def getData(self):
+        """
+        Public method to get the data.
+        
+        @return tuple giving the scaffold (string), the project name (string),
+            a flag indicating to overwrite existing files (boolean) and a flag
+            indicating to simulate the creation (boolean)
+        """
+        return (
+            self.scaffoldCombo.currentText().split(":")[0], 
+            self.nameEdit.text(), 
+            self.overwriteCheckBox.isChecked(), 
+            self.simulateCheckBox.isChecked()
+        )

eric ide

mercurial