Sun, 27 Oct 2013 22:43:17 +0100
Python 2 compatibility for Eric 5.
# -*- coding: utf-8 -*- # Copyright (c) 2012 - 2013 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing a dialog for entering the create parameters. """ from __future__ import unicode_literals # __IGNORE_WARNING__ try: str = unicode except (NameError): pass 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(CreateParametersDialog, self).__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() )