ProjectPyramid/DistributionTypeSelectionDialog.py

branch
eric7
changeset 159
d4e7f5a389e6
parent 156
62170c2682a3
child 160
41b23683d5a1
equal deleted inserted replaced
158:24582cac737e 159:d4e7f5a389e6
10 from PyQt6.QtCore import Qt, QProcess 10 from PyQt6.QtCore import Qt, QProcess
11 from PyQt6.QtWidgets import QDialog, QListWidgetItem 11 from PyQt6.QtWidgets import QDialog, QListWidgetItem
12 12
13 from EricWidgets import EricMessageBox 13 from EricWidgets import EricMessageBox
14 14
15 from .Ui_DistributionTypeSelectionDialog import ( 15 from .Ui_DistributionTypeSelectionDialog import Ui_DistributionTypeSelectionDialog
16 Ui_DistributionTypeSelectionDialog
17 )
18 16
19 import Preferences 17 import Preferences
20 18
21 19
22 class DistributionTypeSelectionDialog( 20 class DistributionTypeSelectionDialog(QDialog, Ui_DistributionTypeSelectionDialog):
23 QDialog, Ui_DistributionTypeSelectionDialog):
24 """ 21 """
25 Class implementing a dialog to select the distribution file formats. 22 Class implementing a dialog to select the distribution file formats.
26 """ 23 """
24
27 def __init__(self, project, projectPath, parent=None): 25 def __init__(self, project, projectPath, parent=None):
28 """ 26 """
29 Constructor 27 Constructor
30 28
31 @param project reference to the project object 29 @param project reference to the project object
32 @type Project 30 @type Project
33 @param projectPath path of the Pyramid project 31 @param projectPath path of the Pyramid project
34 @type str 32 @type str
35 @param parent reference to the parent widget 33 @param parent reference to the parent widget
36 @type QWidget 34 @type QWidget
37 """ 35 """
38 super().__init__(parent) 36 super().__init__(parent)
39 self.setupUi(self) 37 self.setupUi(self)
40 38
41 errMsg = "" 39 errMsg = ""
42 proc = QProcess() 40 proc = QProcess()
43 cmd = project.getPyramidCommand( 41 cmd = project.getPyramidCommand(
44 "python", 42 "python", virtualEnv=project.getProjectVirtualEnvironment()
45 virtualEnv=project.getProjectVirtualEnvironment()
46 ) 43 )
47 args = [] 44 args = []
48 args.append("setup.py") 45 args.append("setup.py")
49 args.append("sdist") 46 args.append("sdist")
50 args.append("--help-formats") 47 args.append("--help-formats")
52 proc.start(cmd, args) 49 proc.start(cmd, args)
53 procStarted = proc.waitForStarted() 50 procStarted = proc.waitForStarted()
54 if procStarted: 51 if procStarted:
55 finished = proc.waitForFinished(30000) 52 finished = proc.waitForFinished(30000)
56 if finished and proc.exitCode() == 0: 53 if finished and proc.exitCode() == 0:
57 output = str(proc.readAllStandardOutput(), 54 output = str(
58 Preferences.getSystem("IOEncoding"), 55 proc.readAllStandardOutput(),
59 'replace') 56 Preferences.getSystem("IOEncoding"),
57 "replace",
58 )
60 else: 59 else:
61 if not finished: 60 if not finished:
62 errMsg = self.tr( 61 errMsg = self.tr(
63 "The python setup.py command did not finish within" 62 "The python setup.py command did not finish within" " 30s."
64 " 30s.") 63 )
65 else: 64 else:
66 errMsg = self.tr("Could not start the python executable.") 65 errMsg = self.tr("Could not start the python executable.")
67 if not errMsg: 66 if not errMsg:
68 for line in output.splitlines(): 67 for line in output.splitlines():
69 line = line.strip() 68 line = line.strip()
70 if line.startswith("--formats="): 69 if line.startswith("--formats="):
71 fileFormat, description = ( 70 fileFormat, description = line.replace("--formats=", "").split(
72 line.replace("--formats=", "").split(None, 1)) 71 None, 1
72 )
73 itm = QListWidgetItem( 73 itm = QListWidgetItem(
74 "{0} ({1})".format(fileFormat, description), 74 "{0} ({1})".format(fileFormat, description), self.formatsList
75 self.formatsList) 75 )
76 itm.setFlags(itm.flags() | Qt.ItemFlag.ItemIsUserCheckable) 76 itm.setFlags(itm.flags() | Qt.ItemFlag.ItemIsUserCheckable)
77 itm.setCheckState(Qt.CheckState.Unchecked) 77 itm.setCheckState(Qt.CheckState.Unchecked)
78 else: 78 else:
79 EricMessageBox.critical( 79 EricMessageBox.critical(None, self.tr("Process Generation Error"), errMsg)
80 None, 80
81 self.tr('Process Generation Error'),
82 errMsg)
83
84 def getFormats(self): 81 def getFormats(self):
85 """ 82 """
86 Public method to retrieve the checked formats. 83 Public method to retrieve the checked formats.
87 84
88 @return list of selected formats 85 @return list of selected formats
89 @rtype list of str 86 @rtype list of str
90 """ 87 """
91 formats = [] 88 formats = []
92 for row in range(self.formatsList.count()): 89 for row in range(self.formatsList.count()):
93 itm = self.formatsList.item(row) 90 itm = self.formatsList.item(row)
94 if itm.checkState() == Qt.CheckState.Checked: 91 if itm.checkState() == Qt.CheckState.Checked:
95 fileFormat = itm.text().split(None, 1)[0].strip() 92 fileFormat = itm.text().split(None, 1)[0].strip()
96 if fileFormat: 93 if fileFormat:
97 formats.append(fileFormat) 94 formats.append(fileFormat)
98 95
99 return formats 96 return formats

eric ide

mercurial