diff -r 012c492a9bd6 -r e691c51ab655 ProjectPyramid/DistributionTypeSelectionDialog.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ProjectPyramid/DistributionTypeSelectionDialog.py Tue Aug 28 17:15:21 2012 +0200 @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing a dialog to select the distribution file formats. +""" + +from PyQt4.QtCore import Qt, QProcess +from PyQt4.QtGui import QDialog, QListWidgetItem + +from E5Gui import E5MessageBox + +from .Ui_DistributionTypeSelectionDialog import Ui_DistributionTypeSelectionDialog + +import Preferences + + +class DistributionTypeSelectionDialog(QDialog, Ui_DistributionTypeSelectionDialog): + """ + Class implementing a dialog to select the distribution file formats. + """ + def __init__(self, project, projectPath, parent=None): + """ + Constructor + + @param project reference to the project object (ProjectPyramid.Project.Project) + @param projectPath path of the Pyramid project (string) + @param parent reference to the parent widget (QWidget) + """ + super().__init__(parent) + self.setupUi(self) + + errMsg = "" + proc = QProcess() + cmd = project.getPythonCommand() + args = [] + args.append("setup.py") + args.append("sdist") + args.append("--help-formats") + proc.setWorkingDirectory(projectPath) + proc.start(cmd, args) + 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 python setup.py command did not finish within 30s.") + else: + errMsg = self.trUtf8("Could not start the pcreate executable.") + if not errMsg: + for line in output.splitlines(): + line = line.strip() + if line.startswith("--formats="): + format, description = line.replace("--formats=", "").split(None, 1) + itm = QListWidgetItem("{0} ({1})".format(format, description), + self.formatsList) + itm.setFlags(itm.flags() | Qt.ItemIsUserCheckable) + itm.setCheckState(Qt.Unchecked) + else: + E5MessageBox.critical(None, + self.trUtf8('Process Generation Error'), + errMsg) + + def getFormats(self): + """ + Public method to retrieve the checked formats. + + @return list of selected formats (list of string) + """ + formats = [] + for row in range(self.formatsList.count()): + itm = self.formatsList.item(row) + if itm.checkState() == Qt.Checked: + format = itm.text().split(None, 1)[0].strip() + if format: + formats.append(format) + + return formats