5 |
5 |
6 """ |
6 """ |
7 Module to get the object name, class name or signatures of a Qt form (*.ui). |
7 Module to get the object name, class name or signatures of a Qt form (*.ui). |
8 """ |
8 """ |
9 |
9 |
10 import os |
|
11 import sys |
10 import sys |
12 import json |
11 import json |
13 import xml.etree.ElementTree # secok |
12 import xml.etree.ElementTree # secok |
14 import contextlib |
13 import contextlib |
15 |
14 |
16 try: |
15 try: |
17 from PyQt5.QtCore import QMetaMethod, QByteArray |
16 from PyQt5.QtCore import QByteArray, QMetaMethod |
18 from PyQt5.QtGui import QAction |
17 from PyQt5.QtWidgets import QAction, QApplication, QWidget |
19 from PyQt5.QtWidgets import QWidget, QApplication |
|
20 from PyQt5 import uic |
18 from PyQt5 import uic |
21 except ImportError: |
19 except ModuleNotFoundError: |
22 print("PyQt5 could not be found.") |
20 print("PyQt5 could not be found.") |
23 sys.exit(1) |
21 sys.exit(1) |
|
22 except ImportError as err: |
|
23 print("PyQt5 could not be imported. Issue: {0}".format(str(err))) |
|
24 sys.exit(1) |
24 |
25 |
25 with contextlib.suppress(ImportError): |
26 with contextlib.suppress(ImportError): |
26 from PyQt5 import QtWebEngineWidgets # __IGNORE_WARNING__ |
27 from PyQt5 import QtWebEngineWidgets # __IGNORE_WARNING__ |
27 |
28 |
28 sys.path.append(os.path.dirname(os.path.dirname(__file__))) |
|
29 # add the eric package directory |
|
30 |
|
31 |
29 |
32 def objectName(formFile, projectPath): |
30 def objectName(formFile, projectPath): |
33 """ |
31 """ |
34 Function to get the object name of a form. |
32 Function to get the object name of a form. |
35 |
33 |
36 @param formFile file name of the form |
34 @param formFile file name of the form |
37 @type str |
35 @type str |
38 @param projectPath directory name of the project |
36 @param projectPath directory name of the project |
39 @type str |
37 @type str |
40 """ |
38 """ |
|
39 sys.path.append(projectPath) |
|
40 |
41 app = QApplication([]) # __IGNORE_WARNING__ |
41 app = QApplication([]) # __IGNORE_WARNING__ |
42 try: |
42 try: |
43 dlg = uic.loadUi(formFile, package=projectPath) |
43 dlg = uic.loadUi(formFile, package=projectPath) |
44 print(dlg.objectName()) |
44 print(dlg.objectName()) |
45 sys.exit(0) |
45 sys.exit(0) |
56 @param formFile file name of the form |
56 @param formFile file name of the form |
57 @type str |
57 @type str |
58 @param projectPath directory name of the project |
58 @param projectPath directory name of the project |
59 @type str |
59 @type str |
60 """ |
60 """ |
|
61 sys.path.append(projectPath) |
|
62 |
61 app = QApplication([]) # __IGNORE_WARNING__ |
63 app = QApplication([]) # __IGNORE_WARNING__ |
62 try: |
64 try: |
63 dlg = uic.loadUi(formFile, package=projectPath) |
65 dlg = uic.loadUi(formFile, package=projectPath) |
64 print(dlg.metaObject().className()) |
66 print(dlg.metaObject().className()) |
65 sys.exit(0) |
67 sys.exit(0) |
107 @param formFile file name of the form |
109 @param formFile file name of the form |
108 @type str |
110 @type str |
109 @param projectPath directory name of the project |
111 @param projectPath directory name of the project |
110 @type str |
112 @type str |
111 """ |
113 """ |
|
114 sys.path.append(projectPath) |
|
115 |
112 objectsList = [] |
116 objectsList = [] |
113 |
117 |
114 app = QApplication([]) # __IGNORE_WARNING__ |
118 app = QApplication([]) # __IGNORE_WARNING__ |
115 try: |
119 try: |
116 dlg = uic.loadUi(formFile, package=projectPath) |
120 dlg = uic.loadUi(formFile, package=projectPath) |