Как говорится, любопытство сгубило кошку Вот погонял я придуманный инструмент на своих поделках (в том числе и выполненных в системе разделения труда) и всё мне нравилось. Но взбрело же в голову посмотреть в сторону стандартных диалогов. Их же настоящие профи делали. Любопытно же, там-то как всё устроено? И, недолго думая, слепил очередной тест:
stddlg_inspect.py
| Python | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
| #!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# StdDlg Inspect v0.01
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
def make_root(x):
z = x.parent()
a = '{!s} {!s}({!s})'.format(
'None' if x.parent() is None else hex(id(x.parent())),
'*' if x.parent() is None else
'*' if len(x.parent().objectName()) < 1 else
x.parent().objectName(),
'NoneType' if x.parent() is None
else x.parent().metaObject().className()
)
b = '{!s} {!s}({!s})'.format(
hex(id(x)),
'*' if len(x.objectName()) < 1 else x.objectName(),
x.metaObject().className())
c = '{!s} ==> {!s}'.format(a, b)
return(c)
def make_tree(x, c=''):
t = []
t.append(c)
for i in x.findChildren(QtCore.QObject):
x = make_root(i)
t.append(x)
return(t)
def build_tree(wdt):
c = make_root(wdt)
z = list()
z.append(c.split(' ')[0])
z_list = list()
z_list.append(c.split(' ')[1])
max_zli = len(z_list[0])
rc = make_tree(wdt, c)
for i in rc:
z_idx = -1
try:
z_idx = z.index(i.split(' ')[0])
except:
z.append(i.split(' ')[0])
else:
if z_idx > -1:
for z_i in range(len(z) - z_idx - 1):
z_item = z.pop()
z.append(i.split(' ')[3])
zli_new = '{!s}{!s}{!s}'.format(
''.rjust(5 * (len(z) - 2)),
'+==> ',
i.split(' ')[4]
)
max_zli = len(zli_new) if len(
zli_new) > max_zli else max_zli
z_list.append(zli_new)
z_list.reverse()
z_prep = list()
for z_list_i in z_list:
z_prep_i = '{!s}{!s}'.format(
z_list_i, '?' * (max_zli - len(z_list_i)))
z_prep.append(z_prep_i)
z_matr = list()
for z_prep_i in z_prep:
z_matr.append(list())
i = 0
for z_matr_i in z_matr:
j = 0
for j in range(max_zli):
z_matr_i.append([z_prep[i][j]])
j += 1
i += 1
z_tran = [[z_matr[j][i] for j in range(len(z_matr))]
for i in range(len(z_matr[0]))]
for z_tran_i in z_tran:
is_plus = False
for x_tran_i in z_tran_i:
if x_tran_i[0] == '+':
is_plus = True
elif x_tran_i[0] != ' ':
is_plus = False
elif is_plus and x_tran_i[0] == ' ':
x_tran_i[0] = '|'
z_retr = [[z_tran[j][i] for j in range(len(z_tran))]
for i in range(len(z_tran[0]))]
z_itgo = list()
for z_retr_i in z_retr:
s_ix = ''
for z_retr_ix in z_retr_i:
if z_retr_ix[0] != '?':
s_ix += z_retr_ix[0]
z_itgo.append(s_ix)
z_itgo.reverse()
for z_itgo_i in z_itgo:
print(z_itgo_i)
def prepare_tree(wdt):
print('- - - tree is ready - - -')
build_tree(wdt)
def inspect_dlg(wdt):
QtCore.QTimer.singleShot(
2000, lambda: prepare_tree(wdt))
QtCore.QTimer.singleShot(
2500, lambda: wdt.close())
wdt.exec()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
color_dlg = QtWidgets.QColorDialog(None)
color_dlg.setOption(
QtWidgets.QColorDialog.DontUseNativeDialog, True)
inspect_dlg(color_dlg)
font_dlg = QtWidgets.QFontDialog(None)
font_dlg.setOption(
QtWidgets.QFontDialog.DontUseNativeDialog, True)
inspect_dlg(font_dlg)
inpt_dlg = QtWidgets.QInputDialog(None)
inpt_dlg.setTextValue('Here is your text')
inspect_dlg(inpt_dlg)
mesg_box = QtWidgets.QMessageBox(None)
mesg_box.setText('Something happened?')
mesg_box.setStandardButtons(
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.YesToAll |
QtWidgets.QMessageBox.No | QtWidgets.QMessageBox.NoToAll |
QtWidgets.QMessageBox.Open | QtWidgets.QMessageBox.Close)
inspect_dlg(mesg_box)
file_dlg = QtWidgets.QFileDialog(None)
file_dlg.setOption(
QtWidgets.QFileDialog.DontUseNativeDialog, True)
inspect_dlg(file_dlg)
sys.exit() |
|
Остаётся только запустить его из командной строки
| Bash | 1
| c:\qtprobe\stddlg_tree>py stddlg_inspect.py |
|
и дождаться завершения работы. Результаты будут отображены на экране:
| Bash | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
| c:\qtprobe\stddlg_tree>py stddlg_inspect.py
- - - tree is ready - - -
*(NoneType)
+==> *(QColorDialog)
+==> *(QVBoxLayout)
| +==> *(QHBoxLayout)
| +==> *(QVBoxLayout)
| +==> *(QVBoxLayout)
| +==> *(QHBoxLayout)
| +==> *(QVBoxLayout)
+==> *(QWellArray)
+==> *(QLabel)
+==> *(QPushButton)
+==> *(QLabel)
+==> *(QWellArray)
+==> *(QLabel)
+==> *(QPushButton)
+==> *(QColorPicker)
+==> *(QColorLuminancePicker)
+==> *(QColorShower)
| +==> *(QGridLayout)
| +==> *(QColorShowLabel)
| +==> *(QSpinBox)
| | +==> qt_spinbox_lineedit(QLineEdit)
| | | +==> *(QWidgetLineControl)
| | +==> qt_spinboxvalidator(QValidator)
| +==> *(QLabel)
| +==> *(QSpinBox)
| | +==> qt_spinbox_lineedit(QLineEdit)
| | | +==> *(QWidgetLineControl)
| | +==> qt_spinboxvalidator(QValidator)
| +==> *(QLabel)
| +==> *(QSpinBox)
| | +==> qt_spinbox_lineedit(QLineEdit)
| | | +==> *(QWidgetLineControl)
| | +==> qt_spinboxvalidator(QValidator)
| +==> *(QLabel)
| +==> *(QSpinBox)
| | +==> qt_spinbox_lineedit(QLineEdit)
| | | +==> *(QWidgetLineControl)
| | +==> qt_spinboxvalidator(QValidator)
| +==> *(QLabel)
| +==> *(QSpinBox)
| | +==> qt_spinbox_lineedit(QLineEdit)
| | | +==> *(QWidgetLineControl)
| | +==> qt_spinboxvalidator(QValidator)
| +==> *(QLabel)
| +==> *(QSpinBox)
| | +==> qt_spinbox_lineedit(QLineEdit)
| | | +==> *(QWidgetLineControl)
| | +==> qt_spinboxvalidator(QValidator)
| +==> *(QLabel)
| +==> *(QSpinBox)
| | +==> qt_spinbox_lineedit(QLineEdit)
| | | +==> *(QWidgetLineControl)
| | +==> qt_spinboxvalidator(QValidator)
| +==> *(QLabel)
| +==> *(QLabel)
| +==> *(QLineEdit)
| | +==> *(QWidgetLineControl)
| +==> *(QRegularExpressionValidator)
+==> *(QDialogButtonBox)
| +==> *(QHBoxLayout)
| +==> *(QPushButton)
| | +==> *(QWindowsVistaPulse)
| +==> *(QPushButton)
+==> *(QTimer)
- - - tree is ready - - -
*(NoneType)
+==> *(QFontDialog)
+==> *(QLineEdit)
| +==> *(QWidgetLineControl)
+==> *(QFontListView)
| +==> qt_scrollarea_viewport(QWidget)
| +==> qt_scrollarea_hcontainer(QWidget)
| | +==> *(QScrollBar)
| | +==> *(QBoxLayout)
| +==> *(QStyledItemDelegate)
| +==> *(QItemSelectionModel)
| +==> qt_scrollarea_vcontainer(QWidget)
| +==> *(QScrollBar)
| +==> *(QBoxLayout)
+==> *(QStringListModel)
+==> *(QLabel)
+==> *(QLineEdit)
| +==> *(QWidgetLineControl)
+==> *(QFontListView)
| +==> qt_scrollarea_viewport(QWidget)
| +==> qt_scrollarea_hcontainer(QWidget)
| | +==> *(QScrollBar)
| | +==> *(QBoxLayout)
| +==> qt_scrollarea_vcontainer(QWidget)
| | +==> *(QScrollBar)
| | +==> *(QBoxLayout)
| +==> *(QStyledItemDelegate)
| +==> *(QItemSelectionModel)
+==> *(QStringListModel)
+==> *(QLabel)
+==> *(QLineEdit)
| +==> *(QWidgetLineControl)
+==> *(QIntValidator)
+==> *(QFontListView)
| +==> qt_scrollarea_viewport(QWidget)
| +==> qt_scrollarea_hcontainer(QWidget)
| | +==> *(QScrollBar)
| | +==> *(QBoxLayout)
| +==> *(QStyledItemDelegate)
| +==> *(QItemSelectionModel)
| +==> qt_scrollarea_vcontainer(QWidget)
| +==> *(QScrollBar)
| +==> *(QBoxLayout)
+==> *(QStringListModel)
+==> *(QLabel)
+==> *(QGroupBox)
| +==> *(QVBoxLayout)
| +==> *(QCheckBox)
| +==> *(QCheckBox)
+==> *(QGroupBox)
| +==> *(QHBoxLayout)
| +==> qt_fontDialog_sampleEdit(QLineEdit)
| +==> *(QWidgetLineControl)
+==> *(QComboBox)
| +==> *(QStandardItemModel)
+==> *(QLabel)
+==> *(QGridLayout)
+==> *(QDialogButtonBox)
| +==> *(QHBoxLayout)
| +==> *(QPushButton)
| | +==> *(QWindowsVistaPulse)
| +==> *(QPushButton)
+==> *(QSizeGrip)
- - - tree is ready - - -
*(NoneType)
+==> *(QInputDialog)
+==> *(QLineEdit)
| +==> *(QWidgetLineControl)
+==> *(QLabel)
+==> *(QDialogButtonBox)
| +==> *(QHBoxLayout)
| +==> *(QPushButton)
| | +==> *(QWindowsVistaPulse)
| +==> *(QPushButton)
+==> *(QVBoxLayout)
- - - tree is ready - - -
*(NoneType)
+==> *(QMessageBox)
+==> qt_msgboxex_icon_label(QLabel)
+==> *(QGridLayout)
+==> qt_msgbox_label(QLabel)
+==> qt_msgbox_buttonbox(QDialogButtonBox)
+==> *(QHBoxLayout)
+==> *(QPushButton)
| +==> *(QWindowsVistaPulse)
+==> *(QPushButton)
+==> *(QPushButton)
+==> *(QPushButton)
+==> *(QPushButton)
+==> *(QPushButton)
- - - tree is ready - - -
Traceback (most recent call last):
File "stddlg_inspect.py", line 106, in <lambda>
2000, lambda: prepare_tree(wdt))
File "stddlg_inspect.py", line 102, in prepare_tree
build_tree(wdt)
File "stddlg_inspect.py", line 40, in build_tree
rc = make_tree(wdt, c)
File "stddlg_inspect.py", line 29, in make_tree
x = make_root(i)
File "stddlg_inspect.py", line 9, in make_root
z = x.parent()
TypeError: parent(self, QModelIndex): not enough arguments
c:\qtprobe\stddlg_tree> |
|
И такой облом на QFileDialog был неприятным сюрпризом Впрочем, Linux выдаёт более внятное описание ошибки, позволяющее понять почему это происходит (после вдумчивого чтения документации ):
| Bash | 1
2
3
4
5
6
7
8
9
10
11
12
13
| - - - tree is ready - - -
Traceback (most recent call last):
File "stddlg_inspect.py", line 106, in <lambda>
2000, lambda: prepare_tree(wdt))
File "stddlg_inspect.py", line 102, in prepare_tree
build_tree(wdt)
File "stddlg_inspect.py", line 40, in build_tree
rc = make_tree(wdt, c)
File "stddlg_inspect.py", line 29, in make_tree
x = make_root(i)
File "stddlg_inspect.py", line 9, in make_root
z = x.parent()
TypeError: QFileSystemModel.parent(QModelIndex): not enough arguments |
|
Но как с этим бороться - рецепта нет. Также непонятно, почему под Windows среди детей экземпляра QColorDialog присутствует некий экземпляр QTimer (под Linux такого нет).
|