15 |
15 |
16 import os |
16 import os |
17 import sys |
17 import sys |
18 import datetime |
18 import datetime |
19 |
19 |
20 from PyQt5.QtCore import pyqtSlot, Qt |
20 from PyQt5.QtCore import pyqtSlot, Qt, QUrl |
21 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem, \ |
21 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem, \ |
22 QListWidgetItem, QApplication |
22 QListWidgetItem, QApplication |
|
23 from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply |
23 |
24 |
24 from E5Gui.E5Application import e5App |
25 from E5Gui.E5Application import e5App |
25 from E5Gui import E5MessageBox, E5FileDialog |
26 from E5Gui import E5MessageBox, E5FileDialog |
26 from E5Gui.E5Completers import E5DirCompleter |
27 from E5Gui.E5Completers import E5DirCompleter |
27 |
28 |
37 Class implementing the setup.py wizard dialog. |
38 Class implementing the setup.py wizard dialog. |
38 |
39 |
39 It displays a dialog for entering the parameters |
40 It displays a dialog for entering the parameters |
40 for the E5MessageBox code generator. |
41 for the E5MessageBox code generator. |
41 """ |
42 """ |
|
43 ClassifiersUrl = "https://pypi.org/pypi?%3Aaction=list_classifiers" |
|
44 |
42 def __init__(self, parent=None): |
45 def __init__(self, parent=None): |
43 """ |
46 """ |
44 Constructor |
47 Constructor |
45 |
48 |
46 @param parent reference to the parent widget (QWidget) |
49 @param parent reference to the parent widget (QWidget) |
47 """ |
50 """ |
48 super(SetupWizardDialog, self).__init__(parent) |
51 super(SetupWizardDialog, self).__init__(parent) |
49 self.setupUi(self) |
52 self.setupUi(self) |
|
53 |
|
54 self.__replies = [] |
50 |
55 |
51 self.dataTabWidget.setCurrentIndex(0) |
56 self.dataTabWidget.setCurrentIndex(0) |
52 |
57 |
53 self.__packageDirCompleter = E5DirCompleter(self.packageEdit) |
58 self.__packageDirCompleter = E5DirCompleter(self.packageEdit) |
54 self.__packageRootDirCompleter = E5DirCompleter(self.packageRootEdit) |
59 self.__packageRootDirCompleter = E5DirCompleter(self.packageRootEdit) |
67 self.homePageUrlEdit, self.authorEdit, |
72 self.homePageUrlEdit, self.authorEdit, |
68 self.authorEmailEdit, self.maintainerEdit, |
73 self.authorEmailEdit, self.maintainerEdit, |
69 self.maintainerEmailEdit]: |
74 self.maintainerEmailEdit]: |
70 lineEdit.setStyleSheet(self.__mandatoryStyleSheet) |
75 lineEdit.setStyleSheet(self.__mandatoryStyleSheet) |
71 |
76 |
72 self.developmentStatusComboBox.addItem("", "") |
77 self.__loadClassifiersFromPyPI() |
73 |
|
74 self.__populateFromTroveLists() |
|
75 |
|
76 self.licenseClassifierComboBox.setCurrentIndex( |
|
77 self.licenseClassifierComboBox.findText( |
|
78 "(GPLv3)", Qt.MatchContains | Qt.MatchCaseSensitive)) |
|
79 |
78 |
80 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
79 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
81 self.__okButton.setEnabled(False) |
80 self.__okButton.setEnabled(False) |
82 |
81 |
83 projectOpen = e5App().getObject("Project").isOpen() |
82 projectOpen = e5App().getObject("Project").isOpen() |
107 self.homePageUrlEdit.text().startswith(("http://", "https://")) |
106 self.homePageUrlEdit.text().startswith(("http://", "https://")) |
108 ) |
107 ) |
109 |
108 |
110 self.__okButton.setEnabled(enable) |
109 self.__okButton.setEnabled(enable) |
111 |
110 |
112 def __populateFromTroveLists(self): |
111 def __loadClassifiersFromPyPI(self): |
|
112 """ |
|
113 Private method to populate the classifiers list with data retrieved |
|
114 from PyPI. |
|
115 """ |
|
116 request = QNetworkRequest(QUrl(SetupWizardDialog.ClassifiersUrl)) |
|
117 request.setAttribute(QNetworkRequest.CacheLoadControlAttribute, |
|
118 QNetworkRequest.AlwaysNetwork) |
|
119 reply = e5App().getObject("UserInterface").networkAccessManager().get( |
|
120 request) |
|
121 reply.finished.connect(lambda: self.__classifiersDownloadDone(reply)) |
|
122 self.__replies.append(reply) |
|
123 |
|
124 @pyqtSlot() |
|
125 def __classifiersDownloadDone(self, reply): |
|
126 """ |
|
127 Private slot called, after the classifiers file has been downloaded |
|
128 from the internet. |
|
129 |
|
130 @param reply reference to the network reply |
|
131 @type QNetworkReply |
|
132 """ |
|
133 reply.deleteLater() |
|
134 if reply in self.__replies: |
|
135 self.__replies.remove(reply) |
|
136 if reply.error() == QNetworkReply.NoError: |
|
137 ioEncoding = Preferences.getSystem("IOEncoding") |
|
138 lines = str(reply.readAll(), ioEncoding, 'replace').splitlines() |
|
139 |
|
140 self.__populateClassifiers(lines) |
|
141 |
|
142 reply.close() |
|
143 |
|
144 @pyqtSlot() |
|
145 def on_localClassifiersButton_clicked(self): |
113 """ |
146 """ |
114 Private method to populate lists from the Trove list file. |
147 Private method to populate lists from the Trove list file. |
|
148 |
|
149 Note: The trove list file was created from querying |
|
150 "https://pypi.org/pypi?%3Aaction=list_classifiers". |
115 """ |
151 """ |
116 filename = os.path.join(os.path.dirname(__file__), |
152 filename = os.path.join(os.path.dirname(__file__), |
117 "data", "trove_classifiers.txt") |
153 "data", "trove_classifiers.txt") |
118 try: |
154 try: |
119 f = open(filename, "r") |
155 f = open(filename, "r") |
126 self.tr("""<p>The Trove Classifiers file <b>{0}</b>""" |
162 self.tr("""<p>The Trove Classifiers file <b>{0}</b>""" |
127 """ could not be read.</p><p>Reason: {1}</p>""") |
163 """ could not be read.</p><p>Reason: {1}</p>""") |
128 .format(filename, str(err))) |
164 .format(filename, str(err))) |
129 return |
165 return |
130 |
166 |
|
167 self.__populateClassifiers(lines) |
|
168 |
|
169 def __populateClassifiers(self, classifiers): |
|
170 """ |
|
171 Private method to populate the classifiers. |
|
172 |
|
173 @param classifiers list of classifiers read from a local file or |
|
174 retrieved from PyPI |
|
175 @type list of str |
|
176 """ |
|
177 self.licenseClassifierComboBox.clear() |
|
178 self.classifiersList.clear() |
|
179 self.developmentStatusComboBox.clear() |
|
180 |
|
181 self.developmentStatusComboBox.addItem("", "") |
|
182 |
131 self.__classifiersDict = {} |
183 self.__classifiersDict = {} |
132 for line in lines: |
184 for line in classifiers: |
133 line = line.strip() |
185 line = line.strip() |
134 if line.startswith("License "): |
186 if line.startswith("License "): |
135 self.licenseClassifierComboBox.addItem( |
187 self.licenseClassifierComboBox.addItem( |
136 "/".join(line.split(" :: ")[1:]), |
188 "/".join(line.split(" :: ")[1:]), |
137 line |
189 line |
140 self.developmentStatusComboBox.addItem( |
192 self.developmentStatusComboBox.addItem( |
141 line.split(" :: ")[1], line) |
193 line.split(" :: ")[1], line) |
142 else: |
194 else: |
143 self.__addClassifierEntry(line) |
195 self.__addClassifierEntry(line) |
144 self.__classifiersDict = {} |
196 self.__classifiersDict = {} |
|
197 |
|
198 self.licenseClassifierComboBox.setCurrentIndex( |
|
199 self.licenseClassifierComboBox.findText( |
|
200 "(GPLv3)", Qt.MatchContains | Qt.MatchCaseSensitive)) |
145 |
201 |
146 def __addClassifierEntry(self, line): |
202 def __addClassifierEntry(self, line): |
147 """ |
203 """ |
148 Private method to add a new entry to the list of trove classifiers. |
204 Private method to add a new entry to the list of trove classifiers. |
149 |
205 |