|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2013 - 2017 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the setup.py wizard dialog. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 try: |
|
12 str = unicode # __IGNORE_WARNING__ |
|
13 except NameError: |
|
14 pass |
|
15 |
|
16 import os |
|
17 import sys |
|
18 import datetime |
|
19 |
|
20 from PyQt5.QtCore import pyqtSlot, Qt |
|
21 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem, \ |
|
22 QListWidgetItem, QApplication |
|
23 |
|
24 from E5Gui.E5Application import e5App |
|
25 from E5Gui import E5MessageBox, E5FileDialog |
|
26 from E5Gui.E5Completers import E5DirCompleter |
|
27 |
|
28 from .Ui_SetupWizardDialog import Ui_SetupWizardDialog |
|
29 |
|
30 import UI.PixmapCache |
|
31 import Utilities |
|
32 import Preferences |
|
33 |
|
34 |
|
35 class SetupWizardDialog(QDialog, Ui_SetupWizardDialog): |
|
36 """ |
|
37 Class implementing the setup.py wizard dialog. |
|
38 |
|
39 It displays a dialog for entering the parameters |
|
40 for the E5MessageBox code generator. |
|
41 """ |
|
42 def __init__(self, parent=None): |
|
43 """ |
|
44 Constructor |
|
45 |
|
46 @param parent reference to the parent widget (QWidget) |
|
47 """ |
|
48 super(SetupWizardDialog, self).__init__(parent) |
|
49 self.setupUi(self) |
|
50 |
|
51 self.dataTabWidget.setCurrentIndex(0) |
|
52 |
|
53 self.__packageDirCompleter = E5DirCompleter(self.packageEdit) |
|
54 self.__packageRootDirCompleter = E5DirCompleter(self.packageRootEdit) |
|
55 self.__sourceDirCompleter = E5DirCompleter(self.sourceDirectoryEdit) |
|
56 |
|
57 self.packageRootDirButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
|
58 self.packageDirButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
|
59 self.sourceDirectoryButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
|
60 |
|
61 self.variantComboBox.addItem(self.tr("distutils"), "distutils.core") |
|
62 self.variantComboBox.addItem(self.tr("setuptools"), "setuptools") |
|
63 |
|
64 self.__mandatoryStyleSheet = "QLineEdit {border: 2px solid;}" |
|
65 for lineEdit in [self.nameEdit, self.versionEdit, |
|
66 self.homePageUrlEdit, self.authorEdit, |
|
67 self.authorEmailEdit, self.maintainerEdit, |
|
68 self.maintainerEmailEdit]: |
|
69 lineEdit.setStyleSheet(self.__mandatoryStyleSheet) |
|
70 |
|
71 self.developmentStatusComboBox.addItem("", "") |
|
72 |
|
73 self.__populateFromTroveLists() |
|
74 |
|
75 self.licenseClassifierComboBox.setCurrentIndex( |
|
76 self.licenseClassifierComboBox.findText( |
|
77 "(GPLv3)", Qt.MatchContains | Qt.MatchCaseSensitive)) |
|
78 |
|
79 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
|
80 self.__okButton.setEnabled(False) |
|
81 |
|
82 projectOpen = e5App().getObject("Project").isOpen() |
|
83 self.projectButton.setEnabled(projectOpen) |
|
84 self.autodiscoverPackagesButton.setEnabled(projectOpen) |
|
85 |
|
86 self.homePageUrlEdit.textChanged.connect(self.__enableOkButton) |
|
87 self.nameEdit.textChanged.connect(self.__enableOkButton) |
|
88 self.versionEdit.textChanged.connect(self.__enableOkButton) |
|
89 self.authorEdit.textChanged.connect(self.__enableOkButton) |
|
90 self.authorEmailEdit.textChanged.connect(self.__enableOkButton) |
|
91 self.maintainerEdit.textChanged.connect(self.__enableOkButton) |
|
92 self.maintainerEmailEdit.textChanged.connect(self.__enableOkButton) |
|
93 |
|
94 def __enableOkButton(self): |
|
95 """ |
|
96 Private slot to set the state of the OK button. |
|
97 """ |
|
98 enable = ( |
|
99 bool(self.nameEdit.text()) and |
|
100 bool(self.versionEdit.text()) and |
|
101 bool(self.homePageUrlEdit.text()) and |
|
102 ((bool(self.authorEdit.text()) and |
|
103 bool(self.authorEmailEdit.text())) or |
|
104 (bool(self.maintainerEdit.text()) and |
|
105 bool(self.maintainerEmailEdit.text()))) and |
|
106 self.homePageUrlEdit.text().startswith(("http://", "https://")) |
|
107 ) |
|
108 |
|
109 self.__okButton.setEnabled(enable) |
|
110 |
|
111 def __populateFromTroveLists(self): |
|
112 """ |
|
113 Private method to populate lists from the Trove list file. |
|
114 """ |
|
115 filename = os.path.join(os.path.dirname(__file__), |
|
116 "data", "trove_classifiers.txt") |
|
117 try: |
|
118 f = open(filename, "r") |
|
119 lines = f.readlines() |
|
120 f.close() |
|
121 except (IOError, OSError) as err: |
|
122 E5MessageBox.warning( |
|
123 self, |
|
124 self.tr("Reading Trove Classifiers"), |
|
125 self.tr("""<p>The Trove Classifiers file <b>{0}</b>""" |
|
126 """ could not be read.</p><p>Reason: {1}</p>""") |
|
127 .format(filename, str(err))) |
|
128 return |
|
129 |
|
130 self.__classifiersDict = {} |
|
131 for line in lines: |
|
132 line = line.strip() |
|
133 if line.startswith("License "): |
|
134 self.licenseClassifierComboBox.addItem( |
|
135 "/".join(line.split(" :: ")[1:]), |
|
136 line |
|
137 ) |
|
138 elif line.startswith("Development Status "): |
|
139 self.developmentStatusComboBox.addItem( |
|
140 line.split(" :: ")[1], line) |
|
141 else: |
|
142 self.__addClassifierEntry(line) |
|
143 self.__classifiersDict = {} |
|
144 |
|
145 def __addClassifierEntry(self, line): |
|
146 """ |
|
147 Private method to add a new entry to the list of trove classifiers. |
|
148 |
|
149 @param line line containing the data for the entry (string) |
|
150 """ |
|
151 itm = None |
|
152 pitm = None |
|
153 dataList = line.split(" :: ") |
|
154 for index in range(len(dataList)): |
|
155 key = " :: ".join(dataList[:index + 1]) |
|
156 if key not in self.__classifiersDict: |
|
157 if pitm is None: |
|
158 itm = QTreeWidgetItem( |
|
159 self.classifiersList, [dataList[index]]) |
|
160 pitm = itm |
|
161 else: |
|
162 itm = QTreeWidgetItem(pitm, [dataList[index]]) |
|
163 itm.setExpanded(True) |
|
164 self.__classifiersDict[key] = itm |
|
165 else: |
|
166 pitm = self.__classifiersDict[key] |
|
167 itm.setCheckState(0, Qt.Unchecked) |
|
168 itm.setData(0, Qt.UserRole, line) |
|
169 |
|
170 def __getLicenseText(self): |
|
171 """ |
|
172 Private method to get the license text. |
|
173 |
|
174 @return license text (string) |
|
175 """ |
|
176 if not self.licenseClassifierCheckBox.isChecked(): |
|
177 return self.licenseEdit.text() |
|
178 else: |
|
179 lic = self.licenseClassifierComboBox.currentText() |
|
180 if "(" in lic: |
|
181 lic = lic.rsplit("(", 1)[1].split(")", 1)[0] |
|
182 return lic |
|
183 |
|
184 def getCode(self, indLevel, indString): |
|
185 """ |
|
186 Public method to get the source code. |
|
187 |
|
188 @param indLevel indentation level (int) |
|
189 @param indString string used for indentation (space or tab) (string) |
|
190 @return generated code (string) |
|
191 """ |
|
192 # Note: all paths are created with '/'; setup will do the right thing |
|
193 |
|
194 # calculate our indentation level and the indentation string |
|
195 il = indLevel + 1 |
|
196 istring = il * indString |
|
197 i1string = (il + 1) * indString |
|
198 i2string = (il + 2) * indString |
|
199 estring = os.linesep + indLevel * indString |
|
200 |
|
201 # now generate the code |
|
202 if self.introCheckBox.isChecked(): |
|
203 code = "#!/usr/bin/env python{0}{1}".format( |
|
204 sys.version_info[0], os.linesep) |
|
205 code += "# -*- coding: utf-8 -*-{0}{0}".format(os.linesep) |
|
206 else: |
|
207 code = "" |
|
208 |
|
209 if self.metaDataCheckBox.isChecked(): |
|
210 code += '# metadata{0}'.format(os.linesep) |
|
211 code += '"{0}"{1}'.format( |
|
212 self.summaryEdit.text() or "Setup routine", |
|
213 os.linesep |
|
214 ) |
|
215 code += '__version__ = "{0}"{1}'.format( |
|
216 self.versionEdit.text(), os.linesep) |
|
217 code += '__license__ = "{0}"{1}'.format( |
|
218 self.__getLicenseText(), os.linesep) |
|
219 code += '__author__ = "{0}"{1}'.format( |
|
220 self.authorEdit.text() or self.maintainerEdit.text(), |
|
221 os.linesep) |
|
222 code += '__email__ = "{0}"{1}'.format( |
|
223 self.authorEmailEdit.text() or self.maintainerEmailEdit.text(), |
|
224 os.linesep) |
|
225 code += '__url__ = "{0}"{1}'.format( |
|
226 self.homePageUrlEdit.text(), os.linesep) |
|
227 code += '__date__ = "{0}"{1}'.format( |
|
228 datetime.datetime.now().isoformat().split('.')[0], os.linesep) |
|
229 code += '__prj__ = "{0}"{1}'.format( |
|
230 self.nameEdit.text(), os.linesep) |
|
231 code += os.linesep |
|
232 |
|
233 if self.descriptionFromFilesCheckBox.isChecked(): |
|
234 code += "from __future__ import with_statement{0}".format( |
|
235 os.linesep) |
|
236 |
|
237 if self.importCheckBox.isChecked(): |
|
238 variant = self.variantComboBox.itemData( |
|
239 self.variantComboBox.currentIndex()) |
|
240 if variant == "setuptools": |
|
241 additionalImport = ", find_packages" |
|
242 else: |
|
243 additionalImport = "" |
|
244 code += "from {0} import setup{1}{2}".format( |
|
245 variant, additionalImport, os.linesep) |
|
246 if code: |
|
247 code += "{0}{0}".format(os.linesep) |
|
248 |
|
249 if self.descriptionFromFilesCheckBox.isChecked(): |
|
250 code += 'def get_long_description():{0}'.format(os.linesep) |
|
251 code += '{0}descr = []{1}'.format(istring, os.linesep) |
|
252 code += '{0}for fname in "{1}":{2}'.format( |
|
253 istring, |
|
254 '", "'.join(self.descriptionEdit.toPlainText().splitlines()), |
|
255 os.linesep) |
|
256 code += '{0}{0}with open(fname) as f:{1}'.format( |
|
257 istring, os.linesep) |
|
258 code += '{0}{0}{0}descr.append(f.read()){1}'.format( |
|
259 istring, os.linesep) |
|
260 code += '{0}return "\\n\\n".join(descr){1}'.format( |
|
261 istring, os.linesep) |
|
262 code += "{0}{0}".format(os.linesep) |
|
263 |
|
264 code += 'setup({0}'.format(os.linesep) |
|
265 code += '{0}name="{1}",{2}'.format( |
|
266 istring, self.nameEdit.text(), os.linesep) |
|
267 code += '{0}version="{1}",{2}'.format( |
|
268 istring, self.versionEdit.text(), os.linesep) |
|
269 |
|
270 if self.summaryEdit.text(): |
|
271 code += '{0}description="{1}",{2}'.format( |
|
272 istring, self.summaryEdit.text(), os.linesep) |
|
273 |
|
274 if self.descriptionFromFilesCheckBox.isChecked(): |
|
275 code += '{0}long_description=get_long_description(),{1}'.format( |
|
276 istring, os.linesep) |
|
277 elif self.descriptionEdit.toPlainText(): |
|
278 code += '{0}long_description="""{1}""",{2}'.format( |
|
279 istring, self.descriptionEdit.toPlainText(), os.linesep) |
|
280 |
|
281 if self.authorEdit.text(): |
|
282 code += '{0}author="{1}",{2}'.format( |
|
283 istring, self.authorEdit.text(), os.linesep) |
|
284 code += '{0}author_email="{1}",{2}'.format( |
|
285 istring, self.authorEmailEdit.text(), os.linesep) |
|
286 |
|
287 if self.maintainerEdit.text(): |
|
288 code += '{0}maintainer="{1}",{2}'.format( |
|
289 istring, self.maintainerEdit.text(), os.linesep) |
|
290 code += '{0}maintainer_email="{1}",{2}'.format( |
|
291 istring, self.maintainerEmailEdit.text(), os.linesep) |
|
292 |
|
293 code += '{0}url="{1}",{2}'.format( |
|
294 istring, self.homePageUrlEdit.text(), os.linesep) |
|
295 if self.downloadUrlEdit.text(): |
|
296 code += '{0}download_url="{1}",{2}'.format( |
|
297 istring, self.downloadUrlEdit.text(), os.linesep) |
|
298 |
|
299 classifiers = [] |
|
300 if not self.licenseClassifierCheckBox.isChecked(): |
|
301 code += '{0}license="{1}",{2}'.format( |
|
302 istring, self.licenseEdit.text(), os.linesep) |
|
303 else: |
|
304 classifiers.append( |
|
305 self.licenseClassifierComboBox.itemData( |
|
306 self.licenseClassifierComboBox.currentIndex())) |
|
307 |
|
308 platforms = self.platformsEdit.toPlainText().splitlines() |
|
309 if platforms: |
|
310 code += '{0}platforms=[{1}'.format(istring, os.linesep) |
|
311 code += '{0}"{1}"{2}'.format( |
|
312 i1string, |
|
313 '",{0}{1}"'.format(os.linesep, i1string).join(platforms), |
|
314 os.linesep) |
|
315 code += '{0}],{1}'.format(istring, os.linesep) |
|
316 |
|
317 if self.developmentStatusComboBox.currentIndex() != 0: |
|
318 classifiers.append( |
|
319 self.developmentStatusComboBox.itemData( |
|
320 self.developmentStatusComboBox.currentIndex())) |
|
321 |
|
322 itm = self.classifiersList.topLevelItem(0) |
|
323 while itm: |
|
324 itm.setExpanded(True) |
|
325 if itm.checkState(0) == Qt.Checked: |
|
326 classifiers.append(itm.data(0, Qt.UserRole)) |
|
327 itm = self.classifiersList.itemBelow(itm) |
|
328 |
|
329 if classifiers: |
|
330 code += '{0}classifiers=[{1}'.format(istring, os.linesep) |
|
331 code += '{0}"{1}"{2}'.format( |
|
332 i1string, |
|
333 '",{0}{1}"'.format(os.linesep, i1string).join(classifiers), |
|
334 os.linesep) |
|
335 code += '{0}],{1}'.format(istring, os.linesep) |
|
336 del classifiers |
|
337 |
|
338 if self.keywordsEdit.text(): |
|
339 code += '{0}keywords="{1}",{2}'.format( |
|
340 istring, self.keywordsEdit.text(), os.linesep) |
|
341 |
|
342 if self.variantComboBox.currentIndex() == 0: |
|
343 # distutils |
|
344 packages = [] |
|
345 for row in range(self.packagesList.count()): |
|
346 packages.append(self.packagesList.item(row).text()) |
|
347 if packages: |
|
348 code += '{0}packages=[{1}'.format(istring, os.linesep) |
|
349 code += '{0}"{1}"{2}'.format( |
|
350 i1string, |
|
351 '",{0}{1}"'.format(os.linesep, i1string).join(packages), |
|
352 os.linesep) |
|
353 code += '{0}],{1}'.format(istring, os.linesep) |
|
354 del packages |
|
355 elif self.variantComboBox.currentIndex() == 1: |
|
356 # setuptools |
|
357 code += '{0}packages=find_packages('.format(istring) |
|
358 src = Utilities.fromNativeSeparators( |
|
359 self.sourceDirectoryEdit.text()) |
|
360 excludePatterns = [] |
|
361 for row in range(self.excludePatternList.count()): |
|
362 excludePatterns.append( |
|
363 self.excludePatternList.item(row).text()) |
|
364 if src: |
|
365 code += '{0}{1}"{2}"'.format(os.linesep, i1string, src) |
|
366 if excludePatterns: |
|
367 code += ',' |
|
368 else: |
|
369 code += '{0}{1}'.format(os.linesep, istring) |
|
370 if excludePatterns: |
|
371 code += '{0}{1}exclude=[{0}'.format(os.linesep, i1string) |
|
372 code += '{0}"{1}"{2}'.format( |
|
373 i2string, |
|
374 '",{0}{1}"'.format(os.linesep, i2string) |
|
375 .join(excludePatterns), |
|
376 os.linesep) |
|
377 code += '{0}]{1}{2}'.format(i1string, os.linesep, istring) |
|
378 code += '),{0}'.format(os.linesep) |
|
379 |
|
380 if self.includePackageDataCheckBox.isChecked(): |
|
381 code += '{0}include_package_data = True,{1}'.format( |
|
382 istring, os.linesep) |
|
383 |
|
384 modules = [] |
|
385 for row in range(self.modulesList.count()): |
|
386 modules.append(self.modulesList.item(row).text()) |
|
387 if modules: |
|
388 code += '{0}py_modules=[{1}'.format(istring, os.linesep) |
|
389 code += '{0}"{1}"{2}'.format( |
|
390 i1string, |
|
391 '",{0}{1}"'.format(os.linesep, i1string).join(modules), |
|
392 os.linesep) |
|
393 code += '{0}],{1}'.format(istring, os.linesep) |
|
394 del modules |
|
395 |
|
396 scripts = [] |
|
397 for row in range(self.scriptsList.count()): |
|
398 scripts.append(self.scriptsList.item(row).text()) |
|
399 if scripts: |
|
400 code += '{0}scripts=[{1}'.format(istring, os.linesep) |
|
401 code += '{0}"{1}"{2}'.format( |
|
402 i1string, |
|
403 '",{0}{1}"'.format(os.linesep, i1string).join(scripts), |
|
404 os.linesep) |
|
405 code += '{0}],{1}'.format(istring, os.linesep) |
|
406 del scripts |
|
407 |
|
408 code += "){0}".format(estring) |
|
409 return code |
|
410 |
|
411 @pyqtSlot() |
|
412 def on_projectButton_clicked(self): |
|
413 """ |
|
414 Private slot to populate some fields with data retrieved from the |
|
415 current project. |
|
416 """ |
|
417 project = e5App().getObject("Project") |
|
418 |
|
419 self.nameEdit.setText(project.getProjectName()) |
|
420 try: |
|
421 self.versionEdit.setText(project.getProjectVersion()) |
|
422 self.authorEdit.setText(project.getProjectAuthor()) |
|
423 self.authorEmailEdit.setText(project.getProjectAuthorEmail()) |
|
424 description = project.getProjectDescription() |
|
425 except AttributeError: |
|
426 self.versionEdit.setText(project.pdata["VERSION"][0]) |
|
427 self.authorEdit.setText(project.pdata["AUTHOR"][0]) |
|
428 self.authorEmailEdit.setText(project.pdata["EMAIL"][0]) |
|
429 description = project.pdata["DESCRIPTION"][0] |
|
430 |
|
431 summary = description.split(".", 1)[0]\ |
|
432 .replace("\r", "").replace("\n", "") + "." |
|
433 self.summaryEdit.setText(summary) |
|
434 self.descriptionEdit.setPlainText(description) |
|
435 |
|
436 self.packageRootEdit.setText(project.getProjectPath()) |
|
437 |
|
438 # prevent overwriting of entries by disabling the button |
|
439 self.projectButton.setEnabled(False) |
|
440 |
|
441 @pyqtSlot() |
|
442 def on_packagesList_itemSelectionChanged(self): |
|
443 """ |
|
444 Private slot to handle a change of selected items of the |
|
445 packages list. |
|
446 """ |
|
447 self.deletePackageButton.setEnabled( |
|
448 len(self.packagesList.selectedItems()) > 0) |
|
449 |
|
450 @pyqtSlot() |
|
451 def on_deletePackageButton_clicked(self): |
|
452 """ |
|
453 Private slot to delete the selected package items. |
|
454 """ |
|
455 for itm in self.packagesList.selectedItems(): |
|
456 self.packagesList.takeItem( |
|
457 self.packagesList.row(itm)) |
|
458 del itm |
|
459 |
|
460 @pyqtSlot() |
|
461 def on_addPackageButton_clicked(self): |
|
462 """ |
|
463 Private slot to add a package to the list. |
|
464 """ |
|
465 pkg = Utilities.toNativeSeparators(self.packageEdit.text()) |
|
466 self.__addPackage(pkg) |
|
467 |
|
468 @pyqtSlot() |
|
469 def on_packageEdit_returnPressed(self): |
|
470 """ |
|
471 Private slot handling a press of the return button of the |
|
472 package edit. |
|
473 """ |
|
474 self.on_addPackageButton_clicked() |
|
475 |
|
476 @pyqtSlot(str) |
|
477 def on_packageEdit_textChanged(self, txt): |
|
478 """ |
|
479 Private slot to handle a change of the package text. |
|
480 |
|
481 @param txt text of the line edit (string) |
|
482 """ |
|
483 self.addPackageButton.setEnabled(bool(txt)) |
|
484 |
|
485 @pyqtSlot() |
|
486 def on_packageDirButton_clicked(self): |
|
487 """ |
|
488 Private slot to select a package directory via a directory |
|
489 selection dialog. |
|
490 """ |
|
491 startDir = self.packageEdit.text() |
|
492 if not startDir: |
|
493 startDir = self.packageRootEdit.text() or self.__getStartDir() |
|
494 packageDir = E5FileDialog.getExistingDirectory( |
|
495 self, |
|
496 self.tr("Package Directory"), |
|
497 Utilities.fromNativeSeparators(startDir)) |
|
498 if packageDir: |
|
499 self.packageEdit.setText( |
|
500 Utilities.toNativeSeparators(packageDir)) |
|
501 |
|
502 @pyqtSlot() |
|
503 def on_autodiscoverPackagesButton_clicked(self): |
|
504 """ |
|
505 Private slot to discover packages automatically. |
|
506 """ |
|
507 self.autodiscoverPackagesButton.setEnabled(False) |
|
508 QApplication.setOverrideCursor(Qt.WaitCursor) |
|
509 startDir = self.packageRootEdit.text() or self.__getStartDir() |
|
510 if startDir: |
|
511 self.packagesList.clear() |
|
512 for dirpath, dirnames, filenames in os.walk(startDir): |
|
513 if "__init__.py" in filenames: |
|
514 self.__addPackage(dirpath) |
|
515 self.autodiscoverPackagesButton.setEnabled(True) |
|
516 QApplication.restoreOverrideCursor() |
|
517 |
|
518 @pyqtSlot() |
|
519 def on_packageRootDirButton_clicked(self): |
|
520 """ |
|
521 Private slot to select the packages root directory via a |
|
522 directory selection dialog. |
|
523 """ |
|
524 startDir = self.packageRootEdit.text() |
|
525 if not startDir: |
|
526 startDir = self.__getStartDir() |
|
527 packagesRootDir = E5FileDialog.getExistingDirectory( |
|
528 self, |
|
529 self.tr("Packages Root Directory"), |
|
530 Utilities.fromNativeSeparators(startDir), |
|
531 E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) |
|
532 if packagesRootDir: |
|
533 self.packageRootEdit.setText( |
|
534 Utilities.toNativeSeparators(packagesRootDir)) |
|
535 |
|
536 @pyqtSlot(str) |
|
537 def on_packageRootEdit_textChanged(self, txt): |
|
538 """ |
|
539 Private slot handling the entering of a packages root. |
|
540 |
|
541 @param txt text of the line edit (string) |
|
542 """ |
|
543 projectOpen = e5App().getObject("Project").isOpen() |
|
544 validPackagesRoot = bool(txt) and os.path.exists(txt) |
|
545 self.autodiscoverPackagesButton.setEnabled( |
|
546 projectOpen or validPackagesRoot) |
|
547 |
|
548 def __addPackage(self, pkgDir): |
|
549 """ |
|
550 Private method to add a package to the list. |
|
551 |
|
552 @param pkgDir name of the package directory (string) |
|
553 """ |
|
554 if pkgDir: |
|
555 if "\\" in pkgDir or "/" in pkgDir: |
|
556 # It is a directory. Check for an __init__.py file. |
|
557 if os.path.isabs(pkgDir): |
|
558 prefix = "" |
|
559 else: |
|
560 prefix = self.packageRootEdit.text() |
|
561 initName = os.path.join( |
|
562 prefix, |
|
563 Utilities.toNativeSeparators(pkgDir), |
|
564 "__init__.py") |
|
565 if not os.path.exists(initName): |
|
566 res = E5MessageBox.information( |
|
567 self, |
|
568 self.tr("Add Package"), |
|
569 self.tr("""<p>The directory <b>{0}</b> is not""" |
|
570 """ a Python package.</p>""") |
|
571 .format(pkgDir), |
|
572 E5MessageBox.StandardButtons( |
|
573 E5MessageBox.Ignore | |
|
574 E5MessageBox.Ok)) |
|
575 if res == E5MessageBox.Ok: |
|
576 return |
|
577 |
|
578 pkg = pkgDir.replace( |
|
579 Utilities.toNativeSeparators(self.packageRootEdit.text()), "") |
|
580 if pkg.startswith(("\\", "/")): |
|
581 pkg = pkg[1:] |
|
582 if pkg: |
|
583 QListWidgetItem( |
|
584 pkg.replace("\\", ".").replace("/", "."), |
|
585 self.packagesList) |
|
586 self.packageEdit.clear() |
|
587 |
|
588 def __getStartDir(self): |
|
589 """ |
|
590 Private method to get the start directory for selection dialogs. |
|
591 |
|
592 @return start directory (string) |
|
593 """ |
|
594 return (Preferences.getMultiProject("Workspace") or |
|
595 Utilities.getHomeDir()) |
|
596 |
|
597 @pyqtSlot() |
|
598 def on_scriptsList_itemSelectionChanged(self): |
|
599 """ |
|
600 Private slot to handle a change of selected items of the |
|
601 scripts list. |
|
602 """ |
|
603 self.deleteScriptButton.setEnabled( |
|
604 len(self.scriptsList.selectedItems()) > 0) |
|
605 |
|
606 @pyqtSlot() |
|
607 def on_deleteScriptButton_clicked(self): |
|
608 """ |
|
609 Private slot to delete the selected script items. |
|
610 """ |
|
611 for itm in self.scriptsList.selectedItems(): |
|
612 self.scriptsList.takeItem( |
|
613 self.scriptsList.row(itm)) |
|
614 del itm |
|
615 |
|
616 @pyqtSlot() |
|
617 def on_addScriptButton_clicked(self): |
|
618 """ |
|
619 Private slot to add scripts to the list. |
|
620 """ |
|
621 startDir = self.packageRootEdit.text() or self.__getStartDir() |
|
622 scriptsList = E5FileDialog.getOpenFileNames( |
|
623 self, |
|
624 self.tr("Add Scripts"), |
|
625 startDir, |
|
626 self.tr("Python Files (*.py);;All Files(*)")) |
|
627 for script in scriptsList: |
|
628 script = script.replace( |
|
629 Utilities.toNativeSeparators(startDir), "") |
|
630 if script.startswith(("\\", "/")): |
|
631 script = script[1:] |
|
632 if script: |
|
633 QListWidgetItem(Utilities.fromNativeSeparators(script), |
|
634 self.scriptsList) |
|
635 |
|
636 @pyqtSlot() |
|
637 def on_modulesList_itemSelectionChanged(self): |
|
638 """ |
|
639 Private slot to handle a change of selected items of the |
|
640 modules list. |
|
641 """ |
|
642 self.deleteModuleButton.setEnabled( |
|
643 len(self.modulesList.selectedItems()) > 0) |
|
644 |
|
645 @pyqtSlot() |
|
646 def on_deleteModuleButton_clicked(self): |
|
647 """ |
|
648 Private slot to delete the selected script items. |
|
649 """ |
|
650 for itm in self.modulesList.selectedItems(): |
|
651 self.modulesList.takeItem( |
|
652 self.modulesList.row(itm)) |
|
653 del itm |
|
654 |
|
655 @pyqtSlot() |
|
656 def on_addModuleButton_clicked(self): |
|
657 """ |
|
658 Private slot to add Python modules to the list. |
|
659 """ |
|
660 startDir = self.packageRootEdit.text() or self.__getStartDir() |
|
661 modulesList = E5FileDialog.getOpenFileNames( |
|
662 self, |
|
663 self.tr("Add Python Modules"), |
|
664 startDir, |
|
665 self.tr("Python Files (*.py)")) |
|
666 for module in modulesList: |
|
667 module = module.replace( |
|
668 Utilities.toNativeSeparators(startDir), "") |
|
669 if module.startswith(("\\", "/")): |
|
670 module = module[1:] |
|
671 if module: |
|
672 QListWidgetItem(os.path.splitext(module)[0] |
|
673 .replace("\\", ".").replace("/", "."), |
|
674 self.modulesList) |
|
675 |
|
676 @pyqtSlot(int) |
|
677 def on_variantComboBox_currentIndexChanged(self, index): |
|
678 """ |
|
679 Private slot handling a change of the setup variant. |
|
680 |
|
681 @param index index of the selected entry (integer) |
|
682 """ |
|
683 self.packagesStackedWidget.setCurrentIndex(index) |
|
684 |
|
685 @pyqtSlot() |
|
686 def on_excludePatternList_itemSelectionChanged(self): |
|
687 """ |
|
688 Private slot to handle a change of selected items of the |
|
689 exclude pattern list. |
|
690 """ |
|
691 self.deleteExcludePatternButton.setEnabled( |
|
692 len(self.excludePatternList.selectedItems()) > 0) |
|
693 |
|
694 @pyqtSlot() |
|
695 def on_deleteExcludePatternButton_clicked(self): |
|
696 """ |
|
697 Private slot to delete the selected exclude pattern items. |
|
698 """ |
|
699 for itm in self.excludePatternList.selectedItems(): |
|
700 self.excludePatternList.takeItem( |
|
701 self.excludePatternList.row(itm)) |
|
702 del itm |
|
703 |
|
704 @pyqtSlot() |
|
705 def on_addExludePatternButton_clicked(self): |
|
706 """ |
|
707 Private slot to add an exclude pattern to the list. |
|
708 """ |
|
709 pattern = self.excludePatternEdit.text()\ |
|
710 .replace("\\", ".").replace("/", ".") |
|
711 if not self.excludePatternList.findItems( |
|
712 pattern, Qt.MatchExactly | Qt.MatchCaseSensitive): |
|
713 QListWidgetItem(pattern, self.excludePatternList) |
|
714 |
|
715 @pyqtSlot(str) |
|
716 def on_excludePatternEdit_textChanged(self, txt): |
|
717 """ |
|
718 Private slot to handle a change of the exclude pattern text. |
|
719 |
|
720 @param txt text of the line edit (string) |
|
721 """ |
|
722 self.addExludePatternButton.setEnabled(bool(txt)) |
|
723 |
|
724 @pyqtSlot() |
|
725 def on_excludePatternEdit_returnPressed(self): |
|
726 """ |
|
727 Private slot handling a press of the return button of the |
|
728 exclude pattern edit. |
|
729 """ |
|
730 self.on_addExludePatternButton_clicked() |
|
731 |
|
732 @pyqtSlot() |
|
733 def on_sourceDirectoryButton_clicked(self): |
|
734 """ |
|
735 Private slot to select the packages root directory via a |
|
736 directory selection dialog. |
|
737 """ |
|
738 startDir = self.sourceDirectoryEdit.text() or self.__getStartDir() |
|
739 sourceDirectory = E5FileDialog.getExistingDirectory( |
|
740 self, |
|
741 self.tr("Source Directory"), |
|
742 Utilities.fromNativeSeparators(startDir), |
|
743 E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) |
|
744 if sourceDirectory: |
|
745 self.sourceDirectoryEdit.setText( |
|
746 Utilities.toNativeSeparators(sourceDirectory)) |