Project/CreateDialogCodeDialog.py

Wed, 17 Oct 2018 19:53:13 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 17 Oct 2018 19:53:13 +0200
changeset 6547
77c817301ca1
parent 6544
51996454f89f
child 6548
21f8260753b5
permissions
-rw-r--r--

CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
6048
82ad8ec9548c Updated copyright for 2018.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
3 # Copyright (c) 2007 - 2018 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
2297
e8a46f81517c Adjusted some display strings to be independant of the Qt version (Qt4/Qt5).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2223
diff changeset
7 Module implementing a dialog to generate code for a Qt4/Qt5 dialog.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3142
diff changeset
10 from __future__ import unicode_literals
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
11 try:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
12 str = unicode # __IGNORE_EXCEPTION__
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
13 except NameError:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
14 pass
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2492
diff changeset
15
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 import os
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
17 import json
4259
c90a1cb373f2 Added code to intercept a parse error of form files to the dialog code creation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4094
diff changeset
18 import xml.etree.ElementTree
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
20 from PyQt5.QtCore import QMetaObject, QByteArray, QRegExp, Qt, pyqtSlot, \
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
21 QMetaMethod, QSortFilterProxyModel, QProcess
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
22 from PyQt5.QtGui import QStandardItemModel, QBrush, QStandardItem
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
23 from PyQt5.QtWidgets import QWidget, QDialog, QDialogButtonBox, QAction
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
24 from PyQt5 import uic
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
25
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 53
diff changeset
27 from E5Gui.E5Application import e5App
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 535
diff changeset
28 from E5Gui import E5MessageBox
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
30 from .Ui_CreateDialogCodeDialog import Ui_CreateDialogCodeDialog
3110
af7a8dda4c32 Corrected a not working import in the dialog creation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3038
diff changeset
31 from .NewDialogClassDialog import NewDialogClassDialog
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
3670
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
33 from eric6config import getConfig
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
5736
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
35 from Globals import qVersionTuple
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
36
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
37
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
38 pyqtSignatureRole = Qt.UserRole + 1
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 pythonSignatureRole = Qt.UserRole + 2
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
40 rubySignatureRole = Qt.UserRole + 3
4485
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
41 returnTypeRole = Qt.UserRole + 4
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
42 parameterTypesListRole = Qt.UserRole + 5
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
43 parameterNamesListRole = Qt.UserRole + 6
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
44
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 class CreateDialogCodeDialog(QDialog, Ui_CreateDialogCodeDialog):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 """
2297
e8a46f81517c Adjusted some display strings to be independant of the Qt version (Qt4/Qt5).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2223
diff changeset
48 Class implementing a dialog to generate code for a Qt4/Qt5 dialog.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 """
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
50 DialogClasses = {
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
51 "QDialog", "QWidget", "QMainWindow", "QWizard", "QWizardPage",
2492
91ab554e3465 Added support for more widgets in the code creation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2408
diff changeset
52 "QDockWidget", "QFrame", "QGroupBox", "QScrollArea", "QMdiArea",
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
53 "QTabWidget", "QToolBox", "QStackedWidget"
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
54 }
1869
3e34d5c362d9 Enhanced the dialog code generation dialog by presenting classes not directly derived from QWidget, QDialog, QMainWindow or QWizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1862
diff changeset
55 Separator = 25 * "="
1275
3db9193a528b Fixed an issue with the Create Dialog Code dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1206
diff changeset
56
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
57 def __init__(self, formName, project, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 @param formName name of the file containing the form (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 @param project reference to the project object
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 @param parent parent widget if the dialog (QWidget)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2492
diff changeset
65 super(CreateDialogCodeDialog, self).__init__(parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 self.setupUi(self)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 self.okButton = self.buttonBox.button(QDialogButtonBox.Ok)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 self.slotsView.header().hide()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 self.project = project
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 self.formFile = formName
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 filename, ext = os.path.splitext(self.formFile)
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
76 self.srcFile = '{0}{1}'.format(
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
77 filename, self.project.getDefaultSourceExtension())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 self.slotsModel = QStandardItemModel()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 self.proxyModel = QSortFilterProxyModel()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 self.proxyModel.setDynamicSortFilter(True)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.proxyModel.setSourceModel(self.slotsModel)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.slotsView.setModel(self.proxyModel)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 # initialize some member variables
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self.__initError = False
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 self.__module = None
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 if os.path.exists(self.srcFile):
53
c3eb7cc1ff8b Renamed e5App to e5App.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 45
diff changeset
90 vm = e5App().getObject("ViewManager")
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 ed = vm.getOpenEditor(self.srcFile)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 if ed and not vm.checkDirty(ed):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 self.__initError = True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95
1016
72b6b0778e06 Fixed an issue in the code creation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
96 try:
1844
0388a36b5fcf Fixed an issue in the dialog code creation dialog with scanning a Python source file not having the standard extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1819
diff changeset
97 splitExt = os.path.splitext(self.srcFile)
0388a36b5fcf Fixed an issue in the dialog code creation dialog with scanning a Python source file not having the standard extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1819
diff changeset
98 if len(splitExt) == 2:
0388a36b5fcf Fixed an issue in the dialog code creation dialog with scanning a Python source file not having the standard extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1819
diff changeset
99 exts = [splitExt[1]]
0388a36b5fcf Fixed an issue in the dialog code creation dialog with scanning a Python source file not having the standard extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1819
diff changeset
100 else:
0388a36b5fcf Fixed an issue in the dialog code creation dialog with scanning a Python source file not having the standard extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1819
diff changeset
101 exts = None
2408
dc3a7c9d8f6e Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
102 from Utilities import ModuleParser
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
103 self.__module = ModuleParser.readModule(
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
104 self.srcFile, extensions=exts, caching=False)
1016
72b6b0778e06 Fixed an issue in the code creation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
105 except ImportError:
72b6b0778e06 Fixed an issue in the code creation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
106 pass
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 if self.__module is not None:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 self.filenameEdit.setText(self.srcFile)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 classesList = []
1869
3e34d5c362d9 Enhanced the dialog code generation dialog by presenting classes not directly derived from QWidget, QDialog, QMainWindow or QWizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1862
diff changeset
112 vagueClassesList = []
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
113 for cls in list(self.__module.classes.values()):
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
114 if not set(cls.super).isdisjoint(
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
115 CreateDialogCodeDialog.DialogClasses):
1275
3db9193a528b Fixed an issue with the Create Dialog Code dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1206
diff changeset
116 classesList.append(cls.name)
1869
3e34d5c362d9 Enhanced the dialog code generation dialog by presenting classes not directly derived from QWidget, QDialog, QMainWindow or QWizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1862
diff changeset
117 else:
3e34d5c362d9 Enhanced the dialog code generation dialog by presenting classes not directly derived from QWidget, QDialog, QMainWindow or QWizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1862
diff changeset
118 vagueClassesList.append(cls.name)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 classesList.sort()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 self.classNameCombo.addItems(classesList)
1869
3e34d5c362d9 Enhanced the dialog code generation dialog by presenting classes not directly derived from QWidget, QDialog, QMainWindow or QWizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1862
diff changeset
121 if vagueClassesList:
3e34d5c362d9 Enhanced the dialog code generation dialog by presenting classes not directly derived from QWidget, QDialog, QMainWindow or QWizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1862
diff changeset
122 if classesList:
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
123 self.classNameCombo.addItem(
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
124 CreateDialogCodeDialog.Separator)
1869
3e34d5c362d9 Enhanced the dialog code generation dialog by presenting classes not directly derived from QWidget, QDialog, QMainWindow or QWizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1862
diff changeset
125 self.classNameCombo.addItems(sorted(vagueClassesList))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126
1016
72b6b0778e06 Fixed an issue in the code creation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
127 if os.path.exists(self.srcFile) and \
72b6b0778e06 Fixed an issue in the code creation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
128 self.__module is not None and \
72b6b0778e06 Fixed an issue in the code creation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
129 self.classNameCombo.count() == 0:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 self.__initError = True
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
131 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
132 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
133 self.tr("Create Dialog Code"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
134 self.tr(
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
135 """The file <b>{0}</b> exists but does not contain"""
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
136 """ any classes.""").format(self.srcFile))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 self.okButton.setEnabled(self.classNameCombo.count() > 0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 self.__updateSlotsModel()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 def initError(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 Public method to determine, if there was an initialzation error.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 @return flag indicating an initialzation error (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 return self.__initError
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
150 def __objectNameExternal(self):
6544
51996454f89f CreateDialogCodeDialog: extended the logic to support projects loading custom widgets from outside the eric or project directories (via a virtual environment).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6291
diff changeset
151 """
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
152 Private method to get the object name of a form via an external
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
153 interpreter.
6544
51996454f89f CreateDialogCodeDialog: extended the logic to support projects loading custom widgets from outside the eric or project directories (via a virtual environment).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6291
diff changeset
154
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
155 @return object name
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
156 @rtype str
6544
51996454f89f CreateDialogCodeDialog: extended the logic to support projects loading custom widgets from outside the eric or project directories (via a virtual environment).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6291
diff changeset
157 """
51996454f89f CreateDialogCodeDialog: extended the logic to support projects loading custom widgets from outside the eric or project directories (via a virtual environment).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6291
diff changeset
158 interpreter = self.project.getDebugProperty("INTERPRETER")
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
159 objectName = ""
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
160
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
161 loadUi = os.path.join(os.path.dirname(__file__), "UicLoadUi.py")
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
162 args = [
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
163 loadUi,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
164 "object_name",
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
165 self.formFile,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
166 self.project.getProjectPath(),
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
167 ]
6544
51996454f89f CreateDialogCodeDialog: extended the logic to support projects loading custom widgets from outside the eric or project directories (via a virtual environment).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6291
diff changeset
168
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
169 proc = QProcess()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
170 proc.start(interpreter, args)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
171 finished = proc.waitForFinished(30000)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
172 if finished:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
173 text = proc.readAllStandardOutput()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
174 if proc.exitCode() == 0:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
175 objectName = str(text, "utf-8", "replace").strip()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
176 else:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
177 errorText = str(text, "utf-8", "replace")
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
178 E5MessageBox.critical(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
179 self,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
180 self.tr("uic error"),
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
181 self.tr(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
182 """<p>There was an error loading the form <b>{0}</b>"""
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
183 """.</p><p>{1}</p>""").format(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
184 self.formFile, errorText))
6544
51996454f89f CreateDialogCodeDialog: extended the logic to support projects loading custom widgets from outside the eric or project directories (via a virtual environment).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6291
diff changeset
185
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
186 return objectName
6544
51996454f89f CreateDialogCodeDialog: extended the logic to support projects loading custom widgets from outside the eric or project directories (via a virtual environment).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6291
diff changeset
187
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 def __objectName(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 """
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
190 Private method to get the object name of a form.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
192 @return object name
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
193 @rtype str
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
194 """
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
195 if self.project.getDebugProperty("INTERPRETER"):
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
196 return self.__objectNameExternal()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
197 else:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
198 try:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
199 dlg = uic.loadUi(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
200 self.formFile, package=self.project.getProjectPath())
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
201 return dlg.objectName()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
202 except (AttributeError, ImportError,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
203 xml.etree.ElementTree.ParseError) as err:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
204 E5MessageBox.critical(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
205 self,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
206 self.tr("uic error"),
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
207 self.tr(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
208 """<p>There was an error loading the form <b>{0}</b>"""
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
209 """.</p><p>{1}</p>""").format(self.formFile, str(err)))
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
210 return ""
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
211
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
212 def __classNameExternal(self):
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
213 """
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
214 Private method to get the class name of a form via an external
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
215 interpreter.
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
216
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
217 @return class name
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
218 @rtype str
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 """
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
220 interpreter = self.project.getDebugProperty("INTERPRETER")
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
221 className = ""
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
222
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
223 loadUi = os.path.join(os.path.dirname(__file__), "UicLoadUi.py")
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
224 args = [
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
225 loadUi,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
226 "class_name",
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
227 self.formFile,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
228 self.project.getProjectPath(),
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
229 ]
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
231 proc = QProcess()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
232 proc.start(interpreter, args)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
233 finished = proc.waitForFinished(30000)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
234 if finished:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
235 text = proc.readAllStandardOutput()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
236 if proc.exitCode() == 0:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
237 className = str(text, "utf-8", "replace").strip()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
238 else:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
239 errorText = str(text, "utf-8", "replace")
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
240 E5MessageBox.critical(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
241 self,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
242 self.tr("uic error"),
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
243 self.tr(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
244 """<p>There was an error loading the form <b>{0}</b>"""
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
245 """.</p><p>{1}</p>""").format(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
246 self.formFile, errorText))
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
247
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
248 return className
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
249
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 def __className(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 """
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
252 Private method to get the class name of a form.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
254 @return class name
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
255 @rtype str
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 """
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
257 if self.project.getDebugProperty("INTERPRETER"):
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
258 return self.__objectNameExternal()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
259 else:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
260 try:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
261 dlg = uic.loadUi(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
262 self.formFile, package=self.project.getProjectPath())
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
263 return dlg.metaObject().className()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
264 except (AttributeError, ImportError,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
265 xml.etree.ElementTree.ParseError) as err:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
266 E5MessageBox.critical(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
267 self,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
268 self.tr("uic error"),
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
269 self.tr(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
270 """<p>There was an error loading the form <b>{0}</b>"""
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
271 """.</p><p>{1}</p>""").format(self.formFile, str(err)))
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
272 return ""
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
273
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 def __signatures(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 Private slot to get the signatures.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 @return list of signatures (list of strings)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 if self.__module is None:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 return []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 signatures = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 clsName = self.classNameCombo.currentText()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 if clsName:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 cls = self.__module.classes[clsName]
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
287 for meth in list(cls.methods.values()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 if meth.name.startswith("on_"):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 if meth.pyqtSignature is not None:
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
290 sig = ", ".join(
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
291 [bytes(QMetaObject.normalizedType(t)).decode()
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
292 for t in meth.pyqtSignature.split(",")])
427
6af5d12cfecb Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
293 signatures.append("{0}({1})".format(meth.name, sig))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 signatures.append(meth.name)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 return signatures
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297
42
23b45a742e17 Fixed a bunch of issues including a workaround for a bug in the Python email package (s. EmailDialog.py).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 15
diff changeset
298 def __mapType(self, type_):
23b45a742e17 Fixed a bunch of issues including a workaround for a bug in the Python email package (s. EmailDialog.py).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 15
diff changeset
299 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
300 Private method to map a type as reported by Qt's meta object to the
42
23b45a742e17 Fixed a bunch of issues including a workaround for a bug in the Python email package (s. EmailDialog.py).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 15
diff changeset
301 correct Python type.
23b45a742e17 Fixed a bunch of issues including a workaround for a bug in the Python email package (s. EmailDialog.py).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 15
diff changeset
302
23b45a742e17 Fixed a bunch of issues including a workaround for a bug in the Python email package (s. EmailDialog.py).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 15
diff changeset
303 @param type_ type as reported by Qt (QByteArray)
23b45a742e17 Fixed a bunch of issues including a workaround for a bug in the Python email package (s. EmailDialog.py).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 15
diff changeset
304 @return mapped Python type (string)
23b45a742e17 Fixed a bunch of issues including a workaround for a bug in the Python email package (s. EmailDialog.py).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 15
diff changeset
305 """
23b45a742e17 Fixed a bunch of issues including a workaround for a bug in the Python email package (s. EmailDialog.py).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 15
diff changeset
306 mapped = bytes(type_).decode()
23b45a742e17 Fixed a bunch of issues including a workaround for a bug in the Python email package (s. EmailDialog.py).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 15
diff changeset
307
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
308 # I. always check for *
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
309 mapped = mapped.replace("*", "")
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
310
1139
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
311 if self.project.getProjectLanguage() != "Python2" or \
6291
94e0e688dcad PySide2 support: started to implement support for PySide2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
312 self.project.getProjectType in ("PySide", "PySide2"):
1139
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
313 # 1. check for const
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
314 mapped = mapped.replace("const ", "")
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
315
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
316 # 2. replace QString and QStringList
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
317 mapped = mapped.replace("QStringList", "list")\
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
318 .replace("QString", "str")
1139
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
319
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
320 # 3. replace double by float
1139
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
321 mapped = mapped.replace("double", "float")
42
23b45a742e17 Fixed a bunch of issues including a workaround for a bug in the Python email package (s. EmailDialog.py).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 15
diff changeset
322
23b45a742e17 Fixed a bunch of issues including a workaround for a bug in the Python email package (s. EmailDialog.py).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 15
diff changeset
323 return mapped
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
324
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
325 def __updateSlotsModelExternal(self):
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
326 """
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
327 Private slot to update the slots tree display getting the data via an
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
328 external interpreter.
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
329 """
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
330 interpreter = self.project.getDebugProperty("INTERPRETER")
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
331 objectsList = []
42
23b45a742e17 Fixed a bunch of issues including a workaround for a bug in the Python email package (s. EmailDialog.py).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 15
diff changeset
332
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
333 loadUi = os.path.join(os.path.dirname(__file__), "UicLoadUi.py")
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
334 args = [
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
335 loadUi,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
336 "signatures",
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
337 self.formFile,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
338 self.project.getProjectPath(),
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
339 ]
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
340
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
341 proc = QProcess()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
342 proc.start(interpreter, args)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
343 finished = proc.waitForFinished(30000)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
344 if not finished:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
345 return
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
346
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
347 text = proc.readAllStandardOutput()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
348 if proc.exitCode() != 0:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
349 errorText = str(text, "utf-8", "replace")
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
350 E5MessageBox.critical(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
351 self,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
352 self.tr("uic error"),
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
353 self.tr(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
354 """<p>There was an error loading the form <b>{0}</b>"""
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
355 """.</p><p>{1}</p>""").format(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
356 self.formFile, errorText))
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
357 else:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
358 objectsListStr = str(text, "utf-8", "replace").strip()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
359 objectsList = json.loads(objectsListStr)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
360
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
361 signatureList = self.__signatures()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
362
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
363 for objectDict in objectsList:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
364 itm = QStandardItem("{0} ({1})".format(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
365 objectDict["name"],
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
366 objectDict["class_name"]))
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
367 self.slotsModel.appendRow(itm)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
368 for methodDict in objectDict["methods"]:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
369 itm2 = QStandardItem(methodDict["signature"])
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
370 itm.appendRow(itm2)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
371
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
372 if self.__module is not None:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
373 if methodDict["methods"][0] in signatureList or \
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
374 methodDict["methods"][1] in signatureList:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
375 itm2.setFlags(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
376 Qt.ItemFlags(Qt.ItemIsEnabled))
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
377 itm2.setCheckState(Qt.Checked)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
378 itm2.setForeground(QBrush(Qt.blue))
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
379 continue
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
380
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
381 itm2.setData(methodDict["pyqt_signature"],
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
382 pyqtSignatureRole)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
383 itm2.setData(methodDict["python_signature"],
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
384 pythonSignatureRole)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
385 itm2.setData(methodDict["return_type"],
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
386 returnTypeRole)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
387 itm2.setData(methodDict["parameter_types"],
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
388 parameterTypesListRole)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
389 itm2.setData(methodDict["parameter_names"],
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
390 parameterNamesListRole)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
391
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
392 itm2.setFlags(Qt.ItemFlags(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
393 Qt.ItemIsUserCheckable |
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
394 Qt.ItemIsEnabled |
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
395 Qt.ItemIsSelectable)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
396 )
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
397 itm2.setCheckState(Qt.Unchecked)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
398
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
399 self.slotsView.sortByColumn(0, Qt.AscendingOrder)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
400
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 def __updateSlotsModel(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 Private slot to update the slots tree display.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 self.filterEdit.clear()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
407 if self.project.getDebugProperty("INTERPRETER"):
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
408 self.__updateSlotsModelExternal()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
409 else:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
410 try:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
411 dlg = uic.loadUi(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
412 self.formFile, package=self.project.getProjectPath())
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
413 objects = dlg.findChildren(QWidget) + dlg.findChildren(QAction)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
414
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
415 signatureList = self.__signatures()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
417 self.slotsModel.clear()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
418 self.slotsModel.setHorizontalHeaderLabels([""])
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
419 for obj in objects:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
420 name = obj.objectName()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
421 if not name or name.startswith("qt_"):
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
422 # ignore un-named or internal objects
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
423 continue
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
424
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
425 metaObject = obj.metaObject()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
426 className = metaObject.className()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
427 itm = QStandardItem("{0} ({1})".format(name, className))
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
428 self.slotsModel.appendRow(itm)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
429 for index in range(metaObject.methodCount()):
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
430 metaMethod = metaObject.method(index)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
431 if metaMethod.methodType() == QMetaMethod.Signal:
5736
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
432 if qVersionTuple() >= (5, 0, 0):
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
433 itm2 = QStandardItem("on_{0}_{1}".format(
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
434 name,
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
435 bytes(metaMethod.methodSignature())
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
436 .decode()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
437 ))
2094
88620e11c67c Made the seventh set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1870
diff changeset
438 else:
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
439 itm2 = QStandardItem("on_{0}_{1}".format(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
440 name, metaMethod.signature()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
441 ))
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
442 itm.appendRow(itm2)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
443 if self.__module is not None:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
444 if qVersionTuple() >= (5, 0, 0):
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
445 method = "on_{0}_{1}".format(
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
446 name,
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
447 bytes(metaMethod.methodSignature())
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
448 .decode().split("(")[0])
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
449 else:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
450 method = "on_{0}_{1}".format(
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
451 name,
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
452 metaMethod.signature().split("(")[0])
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
453 method2 = "{0}({1})".format(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
454 method,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
455 ", ".join([
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
456 self.__mapType(t)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
457 for t in metaMethod.parameterTypes()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
458 ])
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
459 )
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
460
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
461 if method2 in signatureList or \
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
462 method in signatureList:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
463 itm2.setFlags(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
464 Qt.ItemFlags(Qt.ItemIsEnabled))
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
465 itm2.setCheckState(Qt.Checked)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
466 itm2.setForeground(QBrush(Qt.blue))
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
467 continue
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
468
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
469 returnType = self.__mapType(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
470 metaMethod.typeName().encode())
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
471 if returnType == 'void':
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
472 returnType = ""
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
473 parameterTypesList = [
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
474 self.__mapType(t)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
475 for t in metaMethod.parameterTypes()]
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
476 pyqtSignature = ", ".join(parameterTypesList)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
477
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
478 parameterNames = metaMethod.parameterNames()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
479 if parameterNames:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
480 for index in range(len(parameterNames)):
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
481 if not parameterNames[index]:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
482 parameterNames[index] = \
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
483 QByteArray("p{0:d}".format(index)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
484 .encode("utf-8"))
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
485 parameterNamesList = [bytes(n).decode()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
486 for n in parameterNames]
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
487 methNamesSig = ", ".join(parameterNamesList)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
488
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
489 if methNamesSig:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
490 if qVersionTuple() >= (5, 0, 0):
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
491 pythonSignature = \
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
492 "on_{0}_{1}(self, {2})".format(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
493 name,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
494 bytes(metaMethod.methodSignature())
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
495 .decode().split("(")[0],
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
496 methNamesSig)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
497 else:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
498 pythonSignature = \
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
499 "on_{0}_{1}(self, {2})".format(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
500 name,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
501 metaMethod.signature()
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
502 .split("(")[0],
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
503 methNamesSig)
2094
88620e11c67c Made the seventh set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1870
diff changeset
504 else:
6547
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
505 if qVersionTuple() >= (5, 0, 0):
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
506 pythonSignature = "on_{0}_{1}(self)"\
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
507 .format(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
508 name,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
509 bytes(metaMethod.methodSignature())
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
510 .decode().split("(")[0])
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
511 else:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
512 pythonSignature = "on_{0}_{1}(self)"\
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
513 .format(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
514 name,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
515 metaMethod.signature().split(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
516 "(")[0])
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
517 itm2.setData(pyqtSignature, pyqtSignatureRole)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
518 itm2.setData(pythonSignature, pythonSignatureRole)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
519 itm2.setData(returnType, returnTypeRole)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
520 itm2.setData(parameterTypesList,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
521 parameterTypesListRole)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
522 itm2.setData(parameterNamesList,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
523 parameterNamesListRole)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
524
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
525 itm2.setFlags(Qt.ItemFlags(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
526 Qt.ItemIsUserCheckable |
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
527 Qt.ItemIsEnabled |
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
528 Qt.ItemIsSelectable)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
529 )
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
530 itm2.setCheckState(Qt.Unchecked)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
531
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
532 self.slotsView.sortByColumn(0, Qt.AscendingOrder)
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
533 except (AttributeError, ImportError,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
534 xml.etree.ElementTree.ParseError) as err:
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
535 E5MessageBox.critical(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
536 self,
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
537 self.tr("uic error"),
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
538 self.tr(
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
539 """<p>There was an error loading the form <b>{0}</b>"""
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6544
diff changeset
540 """.</p><p>{1}</p>""").format(self.formFile, str(err)))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
541
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
542 def __generateCode(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
543 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
544 Private slot to generate the code as requested by the user.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
545 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
546 # first decide on extension
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
547 if self.filenameEdit.text().endswith(".py") or \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
548 self.filenameEdit.text().endswith(".pyw"):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
549 self.__generatePythonCode()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
550 elif self.filenameEdit.text().endswith(".rb"):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
551 pass
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
552 # second decide on project language
1137
1a37887aefa7 Fixed a little error in the code generation dialog.
detlev@die-offenbachs.de
parents: 1132
diff changeset
553 elif self.project.getProjectLanguage() in ["Python2", "Python3"]:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
554 self.__generatePythonCode()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
555 elif self.project.getProjectLanguage() == "Ruby":
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
556 pass
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
557 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
558 # assume Python (our global default)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
559 self.__generatePythonCode()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
560
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
561 def __generatePythonCode(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
562 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
563 Private slot to generate Python code as requested by the user.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
564 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
565 # init some variables
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
566 sourceImpl = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
567 appendAtIndex = -1
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
568 indentStr = " "
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
569 slotsCode = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
570
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
571 if self.__module is None:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
572 # new file
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
573 try:
1139
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
574 if self.project.getProjectLanguage() == "Python2":
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
575 if self.project.getProjectType() == "PySide":
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
576 tmplName = os.path.join(
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
577 getConfig('ericCodeTemplatesDir'),
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
578 "impl_pyside.py2.tmpl")
6291
94e0e688dcad PySide2 support: started to implement support for PySide2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
579 elif self.project.getProjectType() == "PySide2":
94e0e688dcad PySide2 support: started to implement support for PySide2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
580 tmplName = os.path.join(
94e0e688dcad PySide2 support: started to implement support for PySide2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
581 getConfig('ericCodeTemplatesDir'),
94e0e688dcad PySide2 support: started to implement support for PySide2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
582 "impl_pyside2.py2.tmpl")
2741
d0d7836d0c01 Added PyQt5 support to the project resources and translations viewers and the code creation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2737
diff changeset
583 elif self.project.getProjectType() == "PyQt5":
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
584 tmplName = os.path.join(
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
585 getConfig('ericCodeTemplatesDir'),
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
586 "impl_pyqt5.py2.tmpl")
1139
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
587 else:
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
588 tmplName = os.path.join(
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
589 getConfig('ericCodeTemplatesDir'),
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
590 "impl_pyqt.py2.tmpl")
1139
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
591 else:
1862
b1498278335f Added dialog code generation capability for PySide and Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1844
diff changeset
592 if self.project.getProjectType() == "PySide":
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
593 tmplName = os.path.join(
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
594 getConfig('ericCodeTemplatesDir'),
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
595 "impl_pyside.py.tmpl")
6291
94e0e688dcad PySide2 support: started to implement support for PySide2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
596 elif self.project.getProjectType() == "PySide2":
94e0e688dcad PySide2 support: started to implement support for PySide2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
597 tmplName = os.path.join(
94e0e688dcad PySide2 support: started to implement support for PySide2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
598 getConfig('ericCodeTemplatesDir'),
94e0e688dcad PySide2 support: started to implement support for PySide2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
599 "impl_pyside2.py.tmpl")
3858
4f4684967fee Fixed a few little issues in eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3670
diff changeset
600 elif self.project.getProjectType() in [
4f4684967fee Fixed a few little issues in eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3670
diff changeset
601 "PyQt5", "E6Plugin"]:
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
602 tmplName = os.path.join(
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
603 getConfig('ericCodeTemplatesDir'),
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
604 "impl_pyqt5.py.tmpl")
1862
b1498278335f Added dialog code generation capability for PySide and Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1844
diff changeset
605 else:
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
606 tmplName = os.path.join(
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
607 getConfig('ericCodeTemplatesDir'),
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
608 "impl_pyqt.py.tmpl")
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
609 tmplFile = open(tmplName, 'r', encoding="utf-8")
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
610 template = tmplFile.read()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
611 tmplFile.close()
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
612 except IOError as why:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
613 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
614 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
615 self.tr("Code Generation"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
616 self.tr(
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
617 """<p>Could not open the code template file"""
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
618 """ "{0}".</p><p>Reason: {1}</p>""")
3038
7fe9a53280bd Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
619 .format(tmplName, str(why)))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
620 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
621
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
622 objName = self.__objectName()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
623 if objName:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
624 template = template\
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
625 .replace(
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
626 "$FORMFILE$",
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
627 os.path.splitext(os.path.basename(self.formFile))[0])\
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
628 .replace("$FORMCLASS$", objName)\
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
629 .replace("$CLASSNAME$", self.classNameCombo.currentText())\
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
630 .replace("$SUPERCLASS$", self.__className())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
631
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
632 sourceImpl = template.splitlines(True)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
633 appendAtIndex = -1
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
634
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
635 # determine indent string
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
636 for line in sourceImpl:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
637 if line.lstrip().startswith("def __init__"):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
638 indentStr = line.replace(line.lstrip(), "")
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
639 break
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
640 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
641 # extend existing file
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
642 try:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
643 srcFile = open(self.srcFile, 'r', encoding="utf-8")
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
644 sourceImpl = srcFile.readlines()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
645 srcFile.close()
245
de5c4effc747 Fixed some issues related to Python's universal newline support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 124
diff changeset
646 if not sourceImpl[-1].endswith("\n"):
427
6af5d12cfecb Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
647 sourceImpl[-1] = "{0}{1}".format(sourceImpl[-1], "\n")
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
648 except IOError as why:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
649 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
650 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
651 self.tr("Code Generation"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
652 self.tr(
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
653 """<p>Could not open the source file "{0}".</p>"""
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
654 """<p>Reason: {1}</p>""")
3038
7fe9a53280bd Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
655 .format(self.srcFile, str(why)))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
656 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
657
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
658 cls = self.__module.classes[self.classNameCombo.currentText()]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
659 if cls.endlineno == len(sourceImpl) or cls.endlineno == -1:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
660 appendAtIndex = -1
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
661 # delete empty lines at end
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
662 while not sourceImpl[-1].strip():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
663 del sourceImpl[-1]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
664 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
665 appendAtIndex = cls.endlineno - 1
1132
f8275b31dbe5 Fixed the dialog code creation code to respect PEP-8 rules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
666 while not sourceImpl[appendAtIndex].strip():
f8275b31dbe5 Fixed the dialog code creation code to respect PEP-8 rules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
667 appendAtIndex -= 1
f8275b31dbe5 Fixed the dialog code creation code to respect PEP-8 rules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
668 appendAtIndex += 1
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
669
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
670 # determine indent string
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
671 for line in sourceImpl[cls.lineno:cls.endlineno + 1]:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
672 if line.lstrip().startswith("def __init__"):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
673 indentStr = line.replace(line.lstrip(), "")
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
674 break
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
675
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
676 # do the coding stuff
1139
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
677 if self.project.getProjectLanguage() == "Python2":
6291
94e0e688dcad PySide2 support: started to implement support for PySide2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
678 if self.project.getProjectType() in ("PySide", "PySide2"):
1139
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
679 pyqtSignatureFormat = '@Slot({0})'
2741
d0d7836d0c01 Added PyQt5 support to the project resources and translations viewers and the code creation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2737
diff changeset
680 elif self.project.getProjectType() == "PyQt5":
d0d7836d0c01 Added PyQt5 support to the project resources and translations viewers and the code creation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2737
diff changeset
681 pyqtSignatureFormat = '@pyqtSlot({0})'
1139
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
682 else:
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
683 pyqtSignatureFormat = '@pyqtSignature("{0}")'
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
684 else:
6291
94e0e688dcad PySide2 support: started to implement support for PySide2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
685 if self.project.getProjectType() in ("PySide", "PySide2"):
1862
b1498278335f Added dialog code generation capability for PySide and Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1844
diff changeset
686 pyqtSignatureFormat = '@Slot({0})'
b1498278335f Added dialog code generation capability for PySide and Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1844
diff changeset
687 else:
b1498278335f Added dialog code generation capability for PySide and Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1844
diff changeset
688 pyqtSignatureFormat = '@pyqtSlot({0})'
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
689 for row in range(self.slotsModel.rowCount()):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
690 topItem = self.slotsModel.item(row)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
691 for childRow in range(topItem.rowCount()):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
692 child = topItem.child(childRow)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
693 if child.checkState() and \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
694 child.flags() & Qt.ItemFlags(Qt.ItemIsUserCheckable):
427
6af5d12cfecb Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
695 slotsCode.append('{0}\n'.format(indentStr))
1139
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
696 slotsCode.append('{0}{1}\n'.format(
1148
ddc482ded355 Corrected a PEP-8 related issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1139
diff changeset
697 indentStr,
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
698 pyqtSignatureFormat.format(
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
699 child.data(pyqtSignatureRole))))
427
6af5d12cfecb Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
700 slotsCode.append('{0}def {1}:\n'.format(
6af5d12cfecb Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
701 indentStr, child.data(pythonSignatureRole)))
4485
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
702 indentStr2 = indentStr * 2
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
703 slotsCode.append('{0}"""\n'.format(indentStr2))
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
704 slotsCode.append(
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
705 '{0}Slot documentation goes here.\n'.format(
4485
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
706 indentStr2))
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
707 if child.data(returnTypeRole) or \
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
708 child.data(parameterTypesListRole):
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
709 slotsCode.append('{0}\n'.format(indentStr2))
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
710 if child.data(parameterTypesListRole):
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
711 for name, type_ in zip(
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
712 child.data(parameterNamesListRole),
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
713 child.data(parameterTypesListRole)):
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
714 slotsCode.append(
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
715 '{0}@param {1} DESCRIPTION\n'.format(
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
716 indentStr2, name))
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
717 slotsCode.append('{0}@type {1}\n'.format(
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
718 indentStr2, type_))
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
719 if child.data(returnTypeRole):
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
720 slotsCode.append(
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
721 '{0}@returns DESCRIPTION\n'.format(
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
722 indentStr2))
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
723 slotsCode.append('{0}@rtype {1}\n'.format(
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
724 indentStr2, child.data(returnTypeRole)))
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
725 slotsCode.append('{0}"""\n'.format(indentStr2))
427
6af5d12cfecb Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
726 slotsCode.append('{0}# {1}: not implemented yet\n'.format(
4485
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
727 indentStr2, "TODO"))
427
6af5d12cfecb Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
728 slotsCode.append('{0}raise NotImplementedError\n'.format(
4485
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
729 indentStr2))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
730
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
731 if appendAtIndex == -1:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
732 sourceImpl.extend(slotsCode)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
733 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
734 sourceImpl[appendAtIndex:appendAtIndex] = slotsCode
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
735
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
736 # write the new code
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
737 try:
253
3ccdf551bde7 Changed code to improve development on multiple platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
738 if self.project.useSystemEol():
3ccdf551bde7 Changed code to improve development on multiple platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
739 newline = None
3ccdf551bde7 Changed code to improve development on multiple platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
740 else:
3ccdf551bde7 Changed code to improve development on multiple platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
741 newline = self.project.getEolString()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
742 srcFile = open(self.filenameEdit.text(), 'w', encoding="utf-8",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
743 newline=newline)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
744 srcFile.write("".join(sourceImpl))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
745 srcFile.close()
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
746 except IOError as why:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
747 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
748 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
749 self.tr("Code Generation"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
750 self.tr("""<p>Could not write the source file "{0}".</p>"""
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
751 """<p>Reason: {1}</p>""")
3038
7fe9a53280bd Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
752 .format(self.filenameEdit.text(), str(why)))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
753 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
754
6
52e8c820d0dd Removed some superfluous unicode() calls.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
755 self.project.appendFile(self.filenameEdit.text())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
756
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
757 @pyqtSlot(int)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
758 def on_classNameCombo_activated(self, index):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
759 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
760 Private slot to handle the activated signal of the classname combo.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
761
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
762 @param index index of the activated item (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
763 """
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
764 if (self.classNameCombo.currentText() ==
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
765 CreateDialogCodeDialog.Separator):
1869
3e34d5c362d9 Enhanced the dialog code generation dialog by presenting classes not directly derived from QWidget, QDialog, QMainWindow or QWizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1862
diff changeset
766 self.okButton.setEnabled(False)
3e34d5c362d9 Enhanced the dialog code generation dialog by presenting classes not directly derived from QWidget, QDialog, QMainWindow or QWizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1862
diff changeset
767 self.filterEdit.clear()
3e34d5c362d9 Enhanced the dialog code generation dialog by presenting classes not directly derived from QWidget, QDialog, QMainWindow or QWizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1862
diff changeset
768 self.slotsModel.clear()
3e34d5c362d9 Enhanced the dialog code generation dialog by presenting classes not directly derived from QWidget, QDialog, QMainWindow or QWizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1862
diff changeset
769 self.slotsModel.setHorizontalHeaderLabels([""])
3e34d5c362d9 Enhanced the dialog code generation dialog by presenting classes not directly derived from QWidget, QDialog, QMainWindow or QWizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1862
diff changeset
770 else:
3e34d5c362d9 Enhanced the dialog code generation dialog by presenting classes not directly derived from QWidget, QDialog, QMainWindow or QWizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1862
diff changeset
771 self.okButton.setEnabled(True)
3e34d5c362d9 Enhanced the dialog code generation dialog by presenting classes not directly derived from QWidget, QDialog, QMainWindow or QWizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1862
diff changeset
772 self.__updateSlotsModel()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
773
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
774 def on_filterEdit_textChanged(self, text):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
775 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
776 Private slot called, when thext of the filter edit has changed.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
777
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
778 @param text changed text (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
779 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
780 re = QRegExp(text, Qt.CaseInsensitive, QRegExp.RegExp2)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
781 self.proxyModel.setFilterRegExp(re)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
782
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
783 @pyqtSlot()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
784 def on_newButton_clicked(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
785 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
786 Private slot called to enter the data for a new dialog class.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
787 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
788 path, file = os.path.split(self.srcFile)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
789 objName = self.__objectName()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
790 if objName:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
791 dlg = NewDialogClassDialog(objName, file, path, self)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
792 if dlg.exec_() == QDialog.Accepted:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
793 className, fileName = dlg.getData()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
794
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
795 self.classNameCombo.clear()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
796 self.classNameCombo.addItem(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
797 self.srcFile = fileName
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
798 self.filenameEdit.setText(self.srcFile)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
799 self.__module = None
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
800
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
801 self.okButton.setEnabled(self.classNameCombo.count() > 0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
802
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
803 def on_buttonBox_clicked(self, button):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
804 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
805 Private slot to handle the buttonBox clicked signal.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
806
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
807 @param button reference to the button that was clicked
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
808 (QAbstractButton)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
809 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
810 if button == self.okButton:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
811 self.__generateCode()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
812 self.accept()

eric ide

mercurial