eric6/Project/CreateDialogCodeDialog.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
child 8043
0acf98cd089a
child 8143
2c730d5fd177
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

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
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7911
diff changeset
3 # Copyright (c) 2007 - 2021 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 """
7198
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
7 Module implementing a dialog to generate code for a 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
6661
19fcbb7be3da CreateDialogCodeDialog: changed logic to always call the external UI loader in order to avoid clashes with eric classes and packages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
10 import sys
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 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
12 import json
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
7265
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
14 from PyQt5.QtCore import (
7775
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
15 pyqtSlot, Qt, QMetaObject, QRegularExpression, QSortFilterProxyModel,
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
16 QProcess, QProcessEnvironment
7265
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
17 )
7494
268c297df637 CreateDialogCodeDialog: added code to cope with dark backgrounds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
18 from PyQt5.QtGui import QStandardItemModel, QStandardItem, QBrush, QColor
6661
19fcbb7be3da CreateDialogCodeDialog: changed logic to always call the external UI loader in order to avoid clashes with eric classes and packages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
19 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
20
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 53
diff changeset
22 from E5Gui.E5Application import e5App
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 535
diff changeset
23 from E5Gui import E5MessageBox
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
25 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
26 from .NewDialogClassDialog import NewDialogClassDialog
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
3670
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
28 from eric6config import getConfig
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
7907
7991ea245c20 Added support for PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
30 import Preferences
7991ea245c20 Added support for PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
31
5736
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
32
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
33 pyqtSignatureRole = Qt.UserRole + 1
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 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
35 rubySignatureRole = Qt.UserRole + 3
4485
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
36 returnTypeRole = Qt.UserRole + 4
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
37 parameterTypesListRole = Qt.UserRole + 5
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
38 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
39
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 class CreateDialogCodeDialog(QDialog, Ui_CreateDialogCodeDialog):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
7198
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
43 Class implementing a dialog to generate code for a Qt5 dialog.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
45 DialogClasses = {
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
46 "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
47 "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
48 "QTabWidget", "QToolBox", "QStackedWidget"
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
49 }
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
50 Separator = 25 * "="
1275
3db9193a528b Fixed an issue with the Create Dialog Code dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1206
diff changeset
51
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
52 def __init__(self, formName, project, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 @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
57 @param project reference to the project object
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @param parent parent widget if the dialog (QWidget)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
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
60 super(CreateDialogCodeDialog, self).__init__(parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 self.setupUi(self)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 self.okButton = self.buttonBox.button(QDialogButtonBox.Ok)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.slotsView.header().hide()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.project = project
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 self.formFile = formName
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 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
71 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
72 filename, self.project.getDefaultSourceExtension())
0
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.slotsModel = QStandardItemModel()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.proxyModel = QSortFilterProxyModel()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.proxyModel.setDynamicSortFilter(True)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 self.proxyModel.setSourceModel(self.slotsModel)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 self.slotsView.setModel(self.proxyModel)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 # initialize some member variables
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 self.__initError = False
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.__module = None
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
7050
b66cac9a6560 Project: added an option to the UIC parameters to specify the packages root directory relative to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
84 packagesRoot = self.project.getUicParameter("PackagesRoot")
b66cac9a6560 Project: added an option to the UIC parameters to specify the packages root directory relative to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
85 if packagesRoot:
b66cac9a6560 Project: added an option to the UIC parameters to specify the packages root directory relative to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
86 self.packagesPath = os.path.join(self.project.getProjectPath(),
b66cac9a6560 Project: added an option to the UIC parameters to specify the packages root directory relative to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
87 packagesRoot)
b66cac9a6560 Project: added an option to the UIC parameters to specify the packages root directory relative to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
88 else:
b66cac9a6560 Project: added an option to the UIC parameters to specify the packages root directory relative to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
89 self.packagesPath = self.project.getProjectPath()
b66cac9a6560 Project: added an option to the UIC parameters to specify the packages root directory relative to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
90
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 if os.path.exists(self.srcFile):
53
c3eb7cc1ff8b Renamed e5App to e5App.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 45
diff changeset
92 vm = e5App().getObject("ViewManager")
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 ed = vm.getOpenEditor(self.srcFile)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 if ed and not vm.checkDirty(ed):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 self.__initError = True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97
1016
72b6b0778e06 Fixed an issue in the code creation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
98 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
99 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
100 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
101 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
102 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
103 exts = None
2408
dc3a7c9d8f6e Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
104 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
105 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
106 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
107 except ImportError:
72b6b0778e06 Fixed an issue in the code creation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
108 pass
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 if self.__module is not None:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 self.filenameEdit.setText(self.srcFile)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 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
114 vagueClassesList = []
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
115 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
116 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
117 CreateDialogCodeDialog.DialogClasses):
1275
3db9193a528b Fixed an issue with the Create Dialog Code dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1206
diff changeset
118 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
119 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
120 vagueClassesList.append(cls.name)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 classesList.sort()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 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
123 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
124 if classesList:
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
125 self.classNameCombo.addItem(
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
126 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
127 self.classNameCombo.addItems(sorted(vagueClassesList))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128
7265
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
129 if (
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
130 os.path.exists(self.srcFile) and
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
131 self.__module is not None and
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
132 self.classNameCombo.count() == 0
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
133 ):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 self.__initError = True
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
135 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
136 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
137 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
138 self.tr(
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
139 """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
140 """ any classes.""").format(self.srcFile))
0
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 self.okButton.setEnabled(self.classNameCombo.count() > 0)
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 self.__updateSlotsModel()
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 def initError(self):
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 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
149
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 @return flag indicating an initialzation error (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 return self.__initError
6590
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
153
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
154 def __runUicLoadUi(self, command):
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
155 """
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
156 Private method to run the UicLoadUi.py script with the given command
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
157 and return the output.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158
6590
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
159 @param command uic command to be run
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
160 @type str
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
161 @return tuple of process output and error flag
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
162 @rtype tuple of (str, bool)
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
163 """
7907
7991ea245c20 Added support for PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
164 venvManager = e5App().getObject("VirtualEnvManager")
7991ea245c20 Added support for PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
165 projectType = self.project.getProjectType()
7991ea245c20 Added support for PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
166
6590
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
167 venvName = self.project.getDebugProperty("VIRTUALENV")
7907
7991ea245c20 Added support for PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
168 if not venvName:
7991ea245c20 Added support for PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
169 # no project specific environment, try a type specific one
7991ea245c20 Added support for PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
170 if projectType in ("PyQt5", "E6Plugin", "PySide2"):
7991ea245c20 Added support for PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
171 venvName = Preferences.getQt("PyQtVenvName")
7911
4621c9082a43 Added support for PySide6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7907
diff changeset
172 elif projectType in ("PyQt6", "PySide6"):
7907
7991ea245c20 Added support for PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
173 venvName = Preferences.getQt("PyQt6VenvName")
6590
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
174 interpreter = venvManager.getVirtualenvInterpreter(venvName)
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
175 execPath = venvManager.getVirtualenvExecPath(venvName)
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
176
6661
19fcbb7be3da CreateDialogCodeDialog: changed logic to always call the external UI loader in order to avoid clashes with eric classes and packages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
177 if not interpreter:
19fcbb7be3da CreateDialogCodeDialog: changed logic to always call the external UI loader in order to avoid clashes with eric classes and packages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
178 interpreter = sys.executable
19fcbb7be3da CreateDialogCodeDialog: changed logic to always call the external UI loader in order to avoid clashes with eric classes and packages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
179
6590
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
180 env = QProcessEnvironment.systemEnvironment()
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
181 if execPath:
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
182 if env.contains("PATH"):
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
183 env.insert(
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
184 "PATH", os.pathsep.join([execPath, env.value("PATH")])
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
185 )
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
186 else:
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
187 env.insert("PATH", execPath)
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
188
7907
7991ea245c20 Added support for PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
189 if projectType in ("PyQt5", "E6Plugin", "PySide2"):
7991ea245c20 Added support for PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
190 loadUi = os.path.join(os.path.dirname(__file__), "UicLoadUi5.py")
7911
4621c9082a43 Added support for PySide6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7907
diff changeset
191 elif projectType in ("PyQt6", "PySide6"):
7907
7991ea245c20 Added support for PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
192 loadUi = os.path.join(os.path.dirname(__file__), "UicLoadUi6.py")
6590
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
193 args = [
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
194 loadUi,
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
195 command,
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
196 self.formFile,
7050
b66cac9a6560 Project: added an option to the UIC parameters to specify the packages root directory relative to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
197 self.packagesPath,
6590
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
198 ]
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
199
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
200 uicText = ""
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
201 ok = False
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
202
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
203 proc = QProcess()
7050
b66cac9a6560 Project: added an option to the UIC parameters to specify the packages root directory relative to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
204 proc.setWorkingDirectory(self.packagesPath)
6590
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
205 proc.setProcessEnvironment(env)
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
206 proc.start(interpreter, args)
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
207 started = proc.waitForStarted(5000)
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
208 finished = proc.waitForFinished(30000)
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
209 if started and finished:
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
210 output = proc.readAllStandardOutput()
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
211 outText = str(output, "utf-8", "replace")
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
212 if proc.exitCode() == 0:
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
213 ok = True
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
214 uicText = outText.strip()
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
215 else:
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
216 E5MessageBox.critical(
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
217 self,
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
218 self.tr("uic error"),
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
219 self.tr(
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
220 """<p>There was an error loading the form <b>{0}</b>"""
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
221 """.</p><p>{1}</p>""").format(
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
222 self.formFile, outText)
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
223 )
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
224 else:
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
225 E5MessageBox.critical(
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
226 self,
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
227 self.tr("uic error"),
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
228 self.tr(
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
229 """<p>The project specific Python interpreter <b>{0}</b>"""
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
230 """ could not be started or did not finish within 30"""
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
231 """ seconds.</p>""").format(interpreter)
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
232 )
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
233
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
234 return uicText, ok
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
235
6661
19fcbb7be3da CreateDialogCodeDialog: changed logic to always call the external UI loader in order to avoid clashes with eric classes and packages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
236 def __objectName(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
237 """
6661
19fcbb7be3da CreateDialogCodeDialog: changed logic to always call the external UI loader in order to avoid clashes with eric classes and packages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
238 Private method to get the object name of a form.
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
239
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
240 @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
241 @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
242 """
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
243 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
244
6590
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
245 output, ok = self.__runUicLoadUi("object_name")
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
246 if ok and output:
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
247 objectName = output
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
248
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
249 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
250
6661
19fcbb7be3da CreateDialogCodeDialog: changed logic to always call the external UI loader in order to avoid clashes with eric classes and packages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
251 def __className(self):
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 """
6661
19fcbb7be3da CreateDialogCodeDialog: changed logic to always call the external UI loader in order to avoid clashes with eric classes and packages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
253 Private method to get the class name of a form.
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
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working 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 @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
256 @rtype str
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 """
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
258 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
259
6590
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
260 output, ok = self.__runUicLoadUi("class_name")
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
261 if ok and output:
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
262 className = output
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
263
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working 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 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
265
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 def __signatures(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 Private slot to get the signatures.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 @return list of signatures (list of strings)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 if self.__module is None:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 return []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 signatures = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 clsName = self.classNameCombo.currentText()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 if clsName:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 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
279 for meth in list(cls.methods.values()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 if meth.name.startswith("on_"):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 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
282 sig = ", ".join(
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
283 [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
284 for t in meth.pyqtSignature.split(",")])
427
6af5d12cfecb Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
285 signatures.append("{0}({1})".format(meth.name, sig))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 signatures.append(meth.name)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 return signatures
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289
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
290 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
291 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
292 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
293 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
294
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
295 @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
296 @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
297 """
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 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
299
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
300 # 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
301 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
302
7635
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
303 # 1. check for const
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
304 mapped = mapped.replace("const ", "")
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
305
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
306 # 2. replace QString and QStringList
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
307 mapped = (
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
308 mapped
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
309 .replace("QStringList", "list")
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
310 .replace("QString", "str")
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
311 )
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
312
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
313 # 3. replace double by float
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
314 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
315
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
316 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
317
6661
19fcbb7be3da CreateDialogCodeDialog: changed logic to always call the external UI loader in order to avoid clashes with eric classes and packages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
318 def __updateSlotsModel(self):
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
319 """
6661
19fcbb7be3da CreateDialogCodeDialog: changed logic to always call the external UI loader in order to avoid clashes with eric classes and packages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
320 Private slot to update the slots tree display.
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
321 """
6661
19fcbb7be3da CreateDialogCodeDialog: changed logic to always call the external UI loader in order to avoid clashes with eric classes and packages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
322 self.filterEdit.clear()
19fcbb7be3da CreateDialogCodeDialog: changed logic to always call the external UI loader in order to avoid clashes with eric classes and packages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
323
6590
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
324 output, ok = self.__runUicLoadUi("signatures")
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
325 if ok and output:
8cad6f50ff4c CreateDialogCodeDialog: fixed an issue and applied some logic to enhance the form data loading via the external UicLoadUi.py script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6548
diff changeset
326 objectsList = json.loads(output.strip())
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
327
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working 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 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
329
6548
21f8260753b5 CreateDialogCodeDialog: fixed an oversight in the recent code changes causing the dialog to be populated multiple times.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6547
diff changeset
330 self.slotsModel.clear()
21f8260753b5 CreateDialogCodeDialog: fixed an oversight in the recent code changes causing the dialog to be populated multiple times.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6547
diff changeset
331 self.slotsModel.setHorizontalHeaderLabels([""])
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
332 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
333 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
334 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
335 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
336 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
337 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
338 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
339 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
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 if self.__module is not None:
7265
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
342 if (
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
343 methodDict["methods"][0] in signatureList or
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
344 methodDict["methods"][1] in signatureList
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
345 ):
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
346 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
347 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
348 itm2.setCheckState(Qt.Checked)
7494
268c297df637 CreateDialogCodeDialog: added code to cope with dark backgrounds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
349 if e5App().usesDarkPalette():
268c297df637 CreateDialogCodeDialog: added code to cope with dark backgrounds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
350 itm2.setForeground(QBrush(QColor("#75bfff")))
268c297df637 CreateDialogCodeDialog: added code to cope with dark backgrounds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
351 else:
268c297df637 CreateDialogCodeDialog: added code to cope with dark backgrounds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
352 itm2.setForeground(QBrush(Qt.blue))
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
353 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
354
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working 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 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
356 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
357 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
358 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
359 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
360 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
361 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
362 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
363 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
364 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
365
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working 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 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
367 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
368 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
369 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
370 )
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working 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 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
372
77c817301ca1 CreateDialogCodeDialog: third attempt on getting this working 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 self.slotsView.sortByColumn(0, Qt.AscendingOrder)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 def __generateCode(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 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
378 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 # first decide on extension
7265
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
380 if (
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
381 self.filenameEdit.text().endswith(".py") or
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
382 self.filenameEdit.text().endswith(".pyw")
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
383 ):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 self.__generatePythonCode()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 elif self.filenameEdit.text().endswith(".rb"):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 pass
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 # second decide on project language
7635
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
388 elif self.project.getProjectLanguage() == "Python3":
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 self.__generatePythonCode()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 elif self.project.getProjectLanguage() == "Ruby":
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 pass
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 # assume Python (our global default)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 self.__generatePythonCode()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 def __generatePythonCode(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 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
399 """
7635
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
400 if self.project.getProjectLanguage() != "Python3":
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
401 E5MessageBox.critical(
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
402 self,
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
403 self.tr("Code Generation"),
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
404 self.tr(
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
405 """<p>Code generation for project language"""
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
406 """ "{0}" is not supported.</p>""")
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
407 .format(self.project.getProjectLanguage()))
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
408 return
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
409
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 # init some variables
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 sourceImpl = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412 appendAtIndex = -1
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413 indentStr = " "
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
414 slotsCode = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
415
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416 if self.__module is None:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417 # new file
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418 try:
7635
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
419 if self.project.getProjectType() == "PySide2":
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
420 tmplName = os.path.join(
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
421 getConfig('ericCodeTemplatesDir'),
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
422 "impl_pyside2.py.tmpl")
7911
4621c9082a43 Added support for PySide6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7907
diff changeset
423 elif self.project.getProjectType() == "PySide6":
4621c9082a43 Added support for PySide6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7907
diff changeset
424 tmplName = os.path.join(
4621c9082a43 Added support for PySide6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7907
diff changeset
425 getConfig('ericCodeTemplatesDir'),
4621c9082a43 Added support for PySide6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7907
diff changeset
426 "impl_pyside6.py.tmpl")
7635
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
427 elif self.project.getProjectType() in [
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
428 "PyQt5", "E6Plugin"]:
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
429 tmplName = os.path.join(
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
430 getConfig('ericCodeTemplatesDir'),
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
431 "impl_pyqt5.py.tmpl")
7907
7991ea245c20 Added support for PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
432 elif self.project.getProjectType() == "PyQt6":
7991ea245c20 Added support for PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
433 tmplName = os.path.join(
7991ea245c20 Added support for PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
434 getConfig('ericCodeTemplatesDir'),
7991ea245c20 Added support for PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
435 "impl_pyqt6.py.tmpl")
1139
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
436 else:
7635
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
437 E5MessageBox.critical(
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
438 self,
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
439 self.tr("Code Generation"),
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
440 self.tr(
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
441 """<p>No code template file available for"""
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
442 """ project type "{0}".</p>""")
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
443 .format(self.project.getProjectType()))
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
444 return
7785
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
445 with open(tmplName, 'r', encoding="utf-8") as tmplFile:
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
446 template = tmplFile.read()
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7785
diff changeset
447 except OSError as why:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
448 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
449 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
450 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
451 self.tr(
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
452 """<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
453 """ "{0}".</p><p>Reason: {1}</p>""")
3038
7fe9a53280bd Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
454 .format(tmplName, str(why)))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
455 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
456
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
457 objName = self.__objectName()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
458 if objName:
7265
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
459 template = (
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
460 template
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
461 .replace(
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
462 "$FORMFILE$",
7265
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
463 os.path.splitext(os.path.basename(self.formFile))[0])
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
464 .replace("$FORMCLASS$", objName)
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
465 .replace("$CLASSNAME$", self.classNameCombo.currentText())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
466 .replace("$SUPERCLASS$", self.__className())
7265
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
467 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
468
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
469 sourceImpl = template.splitlines(True)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
470 appendAtIndex = -1
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
471
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
472 # determine indent string
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
473 for line in sourceImpl:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
474 if line.lstrip().startswith("def __init__"):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
475 indentStr = line.replace(line.lstrip(), "")
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
476 break
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
477 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
478 # extend existing file
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
479 try:
7785
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
480 with open(self.srcFile, 'r', encoding="utf-8") as srcFile:
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
481 sourceImpl = srcFile.readlines()
245
de5c4effc747 Fixed some issues related to Python's universal newline support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 124
diff changeset
482 if not sourceImpl[-1].endswith("\n"):
427
6af5d12cfecb Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
483 sourceImpl[-1] = "{0}{1}".format(sourceImpl[-1], "\n")
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7785
diff changeset
484 except OSError as why:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
485 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
486 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
487 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
488 self.tr(
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
489 """<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
490 """<p>Reason: {1}</p>""")
3038
7fe9a53280bd Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
491 .format(self.srcFile, str(why)))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
492 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
493
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
494 cls = self.__module.classes[self.classNameCombo.currentText()]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
495 if cls.endlineno == len(sourceImpl) or cls.endlineno == -1:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
496 appendAtIndex = -1
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
497 # delete empty lines at end
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
498 while not sourceImpl[-1].strip():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
499 del sourceImpl[-1]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
500 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
501 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
502 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
503 appendAtIndex -= 1
f8275b31dbe5 Fixed the dialog code creation code to respect PEP-8 rules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
504 appendAtIndex += 1
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
505
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
506 # 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
507 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
508 if line.lstrip().startswith("def __init__"):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
509 indentStr = line.replace(line.lstrip(), "")
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
510 break
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
511
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
512 # do the coding stuff
7911
4621c9082a43 Added support for PySide6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7907
diff changeset
513 if self.project.getProjectType() in ("PySide2", "PySide6"):
7635
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
514 pyqtSignatureFormat = '@Slot({0})'
1139
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
515 else:
7635
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7494
diff changeset
516 pyqtSignatureFormat = '@pyqtSlot({0})'
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
517 for row in range(self.slotsModel.rowCount()):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
518 topItem = self.slotsModel.item(row)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
519 for childRow in range(topItem.rowCount()):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
520 child = topItem.child(childRow)
7265
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
521 if (
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
522 child.checkState() and
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
523 child.flags() & Qt.ItemFlags(Qt.ItemIsUserCheckable)
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
524 ):
427
6af5d12cfecb Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
525 slotsCode.append('{0}\n'.format(indentStr))
1139
b18376d58832 Added dialog support for PySide.
detlev@die-offenbachs.de
parents: 1137
diff changeset
526 slotsCode.append('{0}{1}\n'.format(
1148
ddc482ded355 Corrected a PEP-8 related issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1139
diff changeset
527 indentStr,
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
528 pyqtSignatureFormat.format(
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
529 child.data(pyqtSignatureRole))))
427
6af5d12cfecb Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
530 slotsCode.append('{0}def {1}:\n'.format(
6af5d12cfecb Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
531 indentStr, child.data(pythonSignatureRole)))
4485
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
532 indentStr2 = indentStr * 2
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
533 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
534 slotsCode.append(
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
535 '{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
536 indentStr2))
7265
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
537 if (
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
538 child.data(returnTypeRole) or
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
539 child.data(parameterTypesListRole)
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
540 ):
4485
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
541 slotsCode.append('{0}\n'.format(indentStr2))
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
542 if child.data(parameterTypesListRole):
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
543 for name, type_ in zip(
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
544 child.data(parameterNamesListRole),
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
545 child.data(parameterTypesListRole)):
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
546 slotsCode.append(
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
547 '{0}@param {1} DESCRIPTION\n'.format(
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
548 indentStr2, name))
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
549 slotsCode.append('{0}@type {1}\n'.format(
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
550 indentStr2, type_))
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
551 if child.data(returnTypeRole):
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
552 slotsCode.append(
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
553 '{0}@returns DESCRIPTION\n'.format(
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
554 indentStr2))
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
555 slotsCode.append('{0}@rtype {1}\n'.format(
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
556 indentStr2, child.data(returnTypeRole)))
28743e3251ce Improved the dialog code generation dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
557 slotsCode.append('{0}"""\n'.format(indentStr2))
427
6af5d12cfecb Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
558 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
559 indentStr2, "TODO"))
427
6af5d12cfecb Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
560 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
561 indentStr2))
0
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 if appendAtIndex == -1:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
564 sourceImpl.extend(slotsCode)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
565 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
566 sourceImpl[appendAtIndex:appendAtIndex] = slotsCode
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
567
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
568 # write the new code
7785
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
569 if self.project.useSystemEol():
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
570 newline = None
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
571 else:
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
572 newline = self.project.getEolString()
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
573 fn = self.filenameEdit.text()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
574 try:
7785
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
575 with open(fn, 'w', encoding="utf-8", newline=newline) as srcFile:
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
576 srcFile.write("".join(sourceImpl))
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7785
diff changeset
577 except OSError as why:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
578 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
579 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
580 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
581 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
582 """<p>Reason: {1}</p>""")
7785
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
583 .format(fn, str(why)))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
584 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
585
7785
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
586 self.project.appendFile(fn)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
587
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
588 @pyqtSlot(int)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
589 def on_classNameCombo_activated(self, index):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
590 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
591 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
592
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
593 @param index index of the activated item (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
594 """
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
595 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
596 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
597 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
598 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
599 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
600 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
601 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
602 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
603 self.__updateSlotsModel()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
604
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
605 def on_filterEdit_textChanged(self, text):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
606 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
607 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
608
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
609 @param text changed text (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
610 """
7775
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
611 rx = QRegularExpression(text, QRegularExpression.CaseInsensitiveOption)
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
612 self.proxyModel.setFilterRegularExpression(rx)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
613
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
614 @pyqtSlot()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
615 def on_newButton_clicked(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
616 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
617 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
618 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
619 path, file = os.path.split(self.srcFile)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
620 objName = self.__objectName()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
621 if objName:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
622 dlg = NewDialogClassDialog(objName, file, path, self)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7635
diff changeset
623 if dlg.exec() == QDialog.Accepted:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
624 className, fileName = dlg.getData()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
625
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
626 self.classNameCombo.clear()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
627 self.classNameCombo.addItem(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
628 self.srcFile = fileName
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
629 self.filenameEdit.setText(self.srcFile)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
630 self.__module = None
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 self.okButton.setEnabled(self.classNameCombo.count() > 0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
633
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
634 def on_buttonBox_clicked(self, button):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
635 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
636 Private slot to handle the buttonBox clicked signal.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
637
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2741
diff changeset
638 @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
639 (QAbstractButton)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
640 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
641 if button == self.okButton:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
642 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
643 self.accept()

eric ide

mercurial