- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章python3+PyQt5 使用三种不同的简便项窗口部件显示数据的方法由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文通过将同一个数据集在三种不同的简便项窗口部件中显示。三个窗口的数据得到实时的同步,数据和视图分离。当添加或删除数据行,三个不同的视图均保持同步。数据将保存在本地文件中,而非数据库。对于小型和临时性数据集来说,这些简便窗口部件非常有用,可以用在非单独数据集中-数据自身的显示,编辑和存储.
所使用的数据集:
/home/yrd/eric_workspace/chap14/ships_conv/ships.py 。
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
#!/usr/bin/env python3
import
platform
from
pyqt5.qtcore
import
qdatastream, qfile,qiodevice,qt
from
pyqt5.qtwidgets
import
qapplication
name, owner, country, description, teu
=
range
(
5
)
magic_number
=
0x570c4
file_version
=
1
class
ship(
object
):
def
__init__(
self
, name, owner, country, teu
=
0
, description
=
""):
self
.name
=
name
self
.owner
=
owner
self
.country
=
country
self
.teu
=
teu
self
.description
=
description
def
__hash__(
self
):
return
super
(ship,
self
).__hash__()
def
__lt__(
self
, other):
return
bool
(
self
.name.lower()<other.name.lower())
def
__eq__(
self
, other):
return
bool
(
self
.name.lower()
=
=
other.name.lower())
class
shipcontainer(
object
):
def
__init__(
self
, filename
=
""):
self
.filename
=
filename
self
.dirty
=
false
self
.ships
=
{}
self
.owners
=
set
()
self
.countries
=
set
()
def
ship(
self
, identity):
return
self
.ships.get(identity)
def
addship(
self
, ship):
self
.ships[
id
(ship)]
=
ship
self
.owners.add(
str
(ship.owner))
self
.countries.add(
str
(ship.country))
self
.dirty
=
true
def
removeship(
self
, ship):
del
self
.ships[
id
(ship)]
del
ship
self
.dirty
=
true
def
__len__(
self
):
return
len
(
self
.ships)
def
__iter__(
self
):
for
ship
in
self
.ships.values():
yield
ship
def
inorder(
self
):
return
sorted
(
self
.ships.values())
def
incountryownerorder(
self
):
return
sorted
(
self
.ships.values(),
key
=
lambda
x: (x.country, x.owner, x.name))
def
load(
self
):
exception
=
none
fh
=
none
try
:
if
not
self
.filename:
raise
ioerror(
"no filename specified for loading"
)
fh
=
qfile(
self
.filename)
if
not
fh.
open
(qiodevice.readonly):
raise
ioerror(
str
(fh.errorstring()))
stream
=
qdatastream(fh)
magic
=
stream.readint32()
if
magic !
=
magic_number:
raise
ioerror(
"unrecognized file type"
)
fileversion
=
stream.readint16()
if
fileversion !
=
file_version:
raise
ioerror(
"unrecognized file type version"
)
self
.ships
=
{}
while
not
stream.atend():
name
=
""
owner
=
""
country
=
""
description
=
""
name
=
stream.readqstring()
owner
=
stream.readqstring()
country
=
stream.readqstring()
description
=
stream.readqstring()
teu
=
stream.readint32()
ship
=
ship(name, owner, country, teu, description)
self
.ships[
id
(ship)]
=
ship
self
.owners.add(
str
(owner))
self
.countries.add(
str
(country))
self
.dirty
=
false
except
ioerror as e:
exception
=
e
finally
:
if
fh
is
not
none:
fh.close()
if
exception
is
not
none:
raise
exception
def
save(
self
):
exception
=
none
fh
=
none
try
:
if
not
self
.filename:
raise
ioerror(
"no filename specified for saving"
)
fh
=
qfile(
self
.filename)
if
not
fh.
open
(qiodevice.writeonly):
raise
ioerror(
str
(fh.errorstring()))
stream
=
qdatastream(fh)
stream.writeint32(magic_number)
stream.writeint16(file_version)
stream.setversion(qdatastream.qt_5_7)
for
ship
in
self
.ships.values():
stream.writeqstring(ship.name)
stream.writeqstring(ship.owner)
stream.writeqstring(ship.country)
stream.writeqstring(ship.description)
stream.writeint32(ship.teu)
self
.dirty
=
false
except
ioerror as e:
exception
=
e
finally
:
if
fh
is
not
none:
fh.close()
if
exception
is
not
none:
raise
exception
def
generatefakeships():
for
name, owner, country, teu, description
in
(
(
"emma m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
151687
,
"<b>w\u00e4rtsil\u00e4-sulzer rta96-c</b> main engine,"
"<font color=green>109,000 hp</font>"
),
(
"msc pamela"
,
"msc"
,
"liberia"
,
90449
,
"draft <font color=green>15m</font>"
),
(
"colombo express"
,
"hapag-lloyd"
,
"germany"
,
93750
,
"main engine, <font color=green>93,500 hp</font>"
),
(
"houston express"
,
"norddeutsche reederei"
,
"germany"
,
95000
,
"features a <u>twisted leading edge full spade rudder</u>. "
"sister of <i>savannah express</i>"
),
(
"savannah express"
,
"norddeutsche reederei"
,
"germany"
,
95000
,
"sister of <i>houston express</i>"
),
(
"msc susanna"
,
"msc"
,
"liberia"
,
90449
, ""),
(
"eleonora m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
151687
,
"captain <i>hallam</i>"
),
(
"estelle m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
151687
,
"captain <i>wells</i>"
),
(
"evelyn m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
151687
,
"captain <i>byrne</i>"
),
(
"georg m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
97933
, ""),
(
"gerd m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
97933
, ""),
(
"gjertrud m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
97933
, ""),
(
"grete m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
97933
, ""),
(
"gudrun m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
97933
, ""),
(
"gunvor m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
97933
, ""),
(
"cscl le havre"
,
"danaos shipping"
,
"cyprus"
,
107200
, ""),
(
"cscl pusan"
,
"danaos shipping"
,
"cyprus"
,
107200
,
"captain <i>watts</i>"
),
(
"xin los angeles"
,
"china shipping container lines (cscl)"
,
"hong kong"
,
107200
, ""),
(
"xin shanghai"
,
"china shipping container lines (cscl)"
,
"hong kong"
,
107200
, ""),
(
"cosco beijing"
,
"costamare shipping"
,
"greece"
,
99833
, ""),
(
"cosco hellas"
,
"costamare shipping"
,
"greece"
,
99833
, ""),
(
"cosco guangzho"
,
"costamare shipping"
,
"greece"
,
99833
, ""),
(
"cosco ningbo"
,
"costamare shipping"
,
"greece"
,
99833
, ""),
(
"cosco yantian"
,
"costamare shipping"
,
"greece"
,
99833
, ""),
(
"cma cgm fidelio"
,
"cma cgm"
,
"france"
,
99500
, ""),
(
"cma cgm medea"
,
"cma cgm"
,
"france"
,
95000
, ""),
(
"cma cgm norma"
,
"cma cgm"
,
"bahamas"
,
95000
, ""),
(
"cma cgm rigoletto"
,
"cma cgm"
,
"france"
,
99500
, ""),
(
"arnold m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
93496
,
"captain <i>morrell</i>"
),
(
"anna m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
93496
,
"captain <i>lockhart</i>"
),
(
"albert m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
93496
,
"captain <i>tallow</i>"
),
(
"adrian m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
93496
,
"captain <i>g. e. ericson</i>"
),
(
"arthur m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
93496
, ""),
(
"axel m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
93496
, ""),
(
"nyk vega"
,
"nippon yusen kaisha"
,
"panama"
,
97825
, ""),
(
"msc esthi"
,
"msc"
,
"liberia"
,
99500
, ""),
(
"msc chicago"
,
"offen claus-peter"
,
"liberia"
,
90449
, ""),
(
"msc bruxelles"
,
"offen claus-peter"
,
"liberia"
,
90449
, ""),
(
"msc roma"
,
"offen claus-peter"
,
"liberia"
,
99500
, ""),
(
"msc madeleine"
,
"msc"
,
"liberia"
,
107551
, ""),
(
"msc ines"
,
"msc"
,
"liberia"
,
107551
, ""),
(
"hannover bridge"
,
"kawasaki kisen kaisha"
,
"japan"
,
99500
, ""),
(
"charlotte m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"clementine m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"columbine m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"cornelia m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"chicago express"
,
"hapag-lloyd"
,
"germany"
,
93750
, ""),
(
"kyoto express"
,
"hapag-lloyd"
,
"germany"
,
93750
, ""),
(
"clifford m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"sally m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"sine m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"skagen m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"sofie m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"sor\u00f8 m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"sovereing m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"susan m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"svend m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"svendborg m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"a.p. m\u00f8ller"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
,
"captain <i>ferraby</i>"
),
(
"caroline m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"carsten m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"chastine m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"cornelius m\u00e6rsk"
,
"m\u00e6rsk line"
,
"denmark"
,
91690
, ""),
(
"cma cgm otello"
,
"cma cgm"
,
"france"
,
91400
, ""),
(
"cma cgm tosca"
,
"cma cgm"
,
"france"
,
91400
, ""),
(
"cma cgm nabucco"
,
"cma cgm"
,
"france"
,
91400
, ""),
(
"cma cgm la traviata"
,
"cma cgm"
,
"france"
,
91400
, ""),
(
"cscl europe"
,
"danaos shipping"
,
"cyprus"
,
90645
, ""),
(
"cscl africa"
,
"seaspan container line"
,
"cyprus"
,
90645
, ""),
(
"cscl america"
,
"danaos shipping "
,
"cyprus"
,
90645
, ""),
(
"cscl asia"
,
"seaspan container line"
,
"hong kong"
,
90645
, ""),
(
"cscl oceania"
,
"seaspan container line"
,
"hong kong"
,
90645
,
"captain <i>baker</i>"
),
(
"m\u00e6rsk seville"
,
"blue star gmbh"
,
"liberia"
,
94724
, ""),
(
"m\u00e6rsk santana"
,
"blue star gmbh"
,
"liberia"
,
94724
, ""),
(
"m\u00e6rsk sheerness"
,
"blue star gmbh"
,
"liberia"
,
94724
, ""),
(
"m\u00e6rsk sarnia"
,
"blue star gmbh"
,
"liberia"
,
94724
, ""),
(
"m\u00e6rsk sydney"
,
"blue star gmbh"
,
"liberia"
,
94724
, ""),
(
"msc heidi"
,
"msc"
,
"panama"
,
95000
, ""),
(
"msc rania"
,
"msc"
,
"panama"
,
95000
, ""),
(
"msc silvana"
,
"msc"
,
"panama"
,
95000
, ""),
(
"m\u00e6rsk stralsund"
,
"blue star gmbh"
,
"liberia"
,
95000
, ""),
(
"m\u00e6rsk saigon"
,
"blue star gmbh"
,
"liberia"
,
95000
, ""),
(
"m\u00e6rsk seoul"
,
"blue star ship managment gmbh"
,
"germany"
,
95000
, ""),
(
"m\u00e6rsk surabaya"
,
"offen claus-peter"
,
"germany"
,
98400
, ""),
(
"cma cgm hugo"
,
"nsb niederelbe"
,
"germany"
,
90745
, ""),
(
"cma cgm vivaldi"
,
"cma cgm"
,
"bahamas"
,
90745
, ""),
(
"msc rachele"
,
"nsb niederelbe"
,
"germany"
,
90745
, ""),
(
"pacific link"
,
"nsb niederelbe"
,
"germany"
,
90745
, ""),
(
"cma cgm carmen"
,
"e r schiffahrt"
,
"liberia"
,
89800
, ""),
(
"cma cgm don carlos"
,
"e r schiffahrt"
,
"liberia"
,
89800
, ""),
(
"cma cgm don giovanni"
,
"e r schiffahrt"
,
"liberia"
,
89800
, ""),
(
"cma cgm parsifal"
,
"e r schiffahrt"
,
"liberia"
,
89800
, ""),
(
"cosco china"
,
"e r schiffahrt"
,
"liberia"
,
91649
, ""),
(
"cosco germany"
,
"e r schiffahrt"
,
"liberia"
,
89800
, ""),
(
"cosco napoli"
,
"e r schiffahrt"
,
"liberia"
,
89800
, ""),
(
"ym unison"
,
"yang ming line"
,
"taiwan"
,
88600
, ""),
(
"ym utmost"
,
"yang ming line"
,
"taiwan"
,
88600
, ""),
(
"msc lucy"
,
"msc"
,
"panama"
,
89954
, ""),
(
"msc maeva"
,
"msc"
,
"panama"
,
89954
, ""),
(
"msc rita"
,
"msc"
,
"panama"
,
89954
, ""),
(
"msc busan"
,
"offen claus-peter"
,
"panama"
,
89954
, ""),
(
"msc beijing"
,
"offen claus-peter"
,
"panama"
,
89954
, ""),
(
"msc toronto"
,
"offen claus-peter"
,
"panama"
,
89954
, ""),
(
"msc charleston"
,
"offen claus-peter"
,
"panama"
,
89954
, ""),
(
"msc vittoria"
,
"msc"
,
"panama"
,
89954
, ""),
(
"ever champion"
,
"nsb niederelbe"
,
"marshall islands"
,
90449
,
"captain <i>phillips</i>"
),
(
"ever charming"
,
"nsb niederelbe"
,
"marshall islands"
,
90449
,
"captain <i>tonbridge</i>"
),
(
"ever chivalry"
,
"nsb niederelbe"
,
"marshall islands"
,
90449
, ""),
(
"ever conquest"
,
"nsb niederelbe"
,
"marshall islands"
,
90449
, ""),
(
"ital contessa"
,
"nsb niederelbe"
,
"marshall islands"
,
90449
, ""),
(
"lt cortesia"
,
"nsb niederelbe"
,
"marshall islands"
,
90449
, ""),
(
"oocl asia"
,
"oocl"
,
"hong kong"
,
89097
, ""),
(
"oocl atlanta"
,
"oocl"
,
"hong kong"
,
89000
, ""),
(
"oocl europe"
,
"oocl"
,
"hong kong"
,
89097
, ""),
(
"oocl hamburg"
,
"oocl"
,
"marshall islands"
,
89097
, ""),
(
"oocl long beach"
,
"oocl"
,
"marshall islands"
,
89097
, ""),
(
"oocl ningbo"
,
"oocl"
,
"marshall islands"
,
89097
, ""),
(
"oocl shenzhen"
,
"oocl"
,
"hong kong"
,
89097
, ""),
(
"oocl tianjin"
,
"oocl"
,
"marshall islands"
,
89097
, ""),
(
"oocl tokyo"
,
"oocl"
,
"hong kong"
,
89097
, "")):
yield
ship(name, owner, country, teu, description)
|
/home/yrd/eric_workspace/chap14/ships_conv/ships-dict.pyw 。
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
#!/usr/bin/env python3
import
sys
from
pyqt5.qtcore
import
qfile, qtimer, qt
from
pyqt5.qtwidgets
import
(qapplication, qdialog, qhboxlayout, qlabel,
qlistwidget, qlistwidgetitem, qmessagebox, qpushbutton,
qsplitter, qtablewidget, qtablewidgetitem, qtreewidget,
qtreewidgetitem, qvboxlayout, qwidget)
import
ships
mac
=
true
try
:
from
pyqt5.qtgui
import
qt_mac_set_native_menubar
except
importerror:
mac
=
false
class
mainform(qdialog):
def
__init__(
self
, parent
=
none):
super
(mainform,
self
).__init__(parent)
listlabel
=
qlabel(
"&list"
)
self
.listwidget
=
qlistwidget()
listlabel.setbuddy(
self
.listwidget)
tablelabel
=
qlabel(
"&table"
)
self
.tablewidget
=
qtablewidget()
tablelabel.setbuddy(
self
.tablewidget)
treelabel
=
qlabel(
"tre&e"
)
self
.treewidget
=
qtreewidget()
treelabel.setbuddy(
self
.treewidget)
addshipbutton
=
qpushbutton(
"&add ship"
)
removeshipbutton
=
qpushbutton(
"&remove ship"
)
quitbutton
=
qpushbutton(
"&quit"
)
if
not
mac:
addshipbutton.setfocuspolicy(qt.nofocus)
removeshipbutton.setfocuspolicy(qt.nofocus)
quitbutton.setfocuspolicy(qt.nofocus)
splitter
=
qsplitter(qt.horizontal)
vbox
=
qvboxlayout()
vbox.addwidget(listlabel)
vbox.addwidget(
self
.listwidget)
widget
=
qwidget()
widget.setlayout(vbox)
splitter.addwidget(widget)
vbox
=
qvboxlayout()
vbox.addwidget(tablelabel)
vbox.addwidget(
self
.tablewidget)
widget
=
qwidget()
widget.setlayout(vbox)
splitter.addwidget(widget)
vbox
=
qvboxlayout()
vbox.addwidget(treelabel)
vbox.addwidget(
self
.treewidget)
widget
=
qwidget()
widget.setlayout(vbox)
splitter.addwidget(widget)
buttonlayout
=
qhboxlayout()
buttonlayout.addwidget(addshipbutton)
buttonlayout.addwidget(removeshipbutton)
buttonlayout.addstretch()
buttonlayout.addwidget(quitbutton)
layout
=
qvboxlayout()
layout.addwidget(splitter)
layout.addlayout(buttonlayout)
self
.setlayout(layout)
self
.tablewidget.itemchanged[qtablewidgetitem].connect(
self
.tableitemchanged)
addshipbutton.clicked.connect(
self
.addship)
removeshipbutton.clicked.connect(
self
.removeship)
quitbutton.clicked.connect(
self
.accept)
self
.ships
=
ships.shipcontainer(
"ships.dat"
)
self
.setwindowtitle(
"ships (dict)"
)
qtimer.singleshot(
0
,
self
.initialload)
def
initialload(
self
):
if
not
qfile.exists(
self
.ships.filename):
for
ship
in
ships.generatefakeships():
self
.ships.addship(ship)
self
.ships.dirty
=
false
else
:
try
:
self
.ships.load()
except
ioerror as e:
qmessagebox.warning(
self
,
"ships - error"
,
"failed to load: {0}"
.
format
(e))
self
.populatelist()
self
.populatetable()
self
.tablewidget.sortitems(
0
)
self
.populatetree()
def
reject(
self
):
self
.accept()
def
accept(
self
):
if
(
self
.ships.dirty
and
qmessagebox.question(
self
,
"ships - save?"
,
"save unsaved changes?"
,
qmessagebox.yes|qmessagebox.no)
=
=
qmessagebox.yes):
try
:
self
.ships.save()
except
ioerror as e:
qmessagebox.warning(
self
,
"ships - error"
,
"failed to save: {0}"
.
format
(e))
qdialog.accept(
self
)
def
populatelist(
self
, selectedship
=
none):
selected
=
none
self
.listwidget.clear()
for
ship
in
self
.ships.inorder():
item
=
qlistwidgetitem(
"{0} of {1}/{2} ({3:,})"
.
format
(ship.name,ship.owner,ship.country,
int
(ship.teu)))
self
.listwidget.additem(item)
if
selectedship
is
not
none
and
selectedship
=
=
id
(ship):
selected
=
item
if
selected
is
not
none:
selected.setselected(true)
self
.listwidget.setcurrentitem(selected)
def
populatetable(
self
, selectedship
=
none):
selected
=
none
self
.tablewidget.clear()
self
.tablewidget.setsortingenabled(false)
self
.tablewidget.setrowcount(
len
(
self
.ships))
headers
=
[
"name"
,
"owner"
,
"country"
,
"description"
,
"teu"
]
self
.tablewidget.setcolumncount(
len
(headers))
self
.tablewidget.sethorizontalheaderlabels(headers)
for
row, ship
in
enumerate
(
self
.ships):
item
=
qtablewidgetitem(ship.name)
item.setdata(qt.userrole,
id
(ship))
if
selectedship
is
not
none
and
selectedship
=
=
id
(ship):
selected
=
item
self
.tablewidget.setitem(row, ships.name, item)
self
.tablewidget.setitem(row, ships.owner,
qtablewidgetitem(ship.owner))
self
.tablewidget.setitem(row, ships.country,
qtablewidgetitem(ship.country))
self
.tablewidget.setitem(row, ships.description,
qtablewidgetitem(ship.description))
item
=
qtablewidgetitem(
"{0:>8}"
.
format
(ship.teu))
item.settextalignment(qt.alignright|qt.alignvcenter)
self
.tablewidget.setitem(row, ships.teu, item)
self
.tablewidget.setsortingenabled(true)
self
.tablewidget.resizecolumnstocontents()
if
selected
is
not
none:
selected.setselected(true)
self
.tablewidget.setcurrentitem(selected)
def
populatetree(
self
, selectedship
=
none):
selected
=
none
self
.treewidget.clear()
self
.treewidget.setcolumncount(
2
)
self
.treewidget.setheaderlabels([
"country/owner/name"
,
"teu"
])
self
.treewidget.setitemsexpandable(true)
parentfromcountry
=
{}
parentfromcountryowner
=
{}
for
ship
in
self
.ships.incountryownerorder():
ancestor
=
parentfromcountry.get(ship.country)
if
ancestor
is
none:
ancestor
=
qtreewidgetitem(
self
.treewidget, [ship.country])
parentfromcountry[ship.country]
=
ancestor
countryowner
=
ship.country
+
"/"
+
ship.owner
parent
=
parentfromcountryowner.get(countryowner)
if
parent
is
none:
parent
=
qtreewidgetitem(ancestor, [ship.owner])
parentfromcountryowner[countryowner]
=
parent
item
=
qtreewidgetitem(parent, [ship.name,
"{0}"
.
format
(ship.teu)])
item.settextalignment(
1
, qt.alignright|qt.alignvcenter)
if
selectedship
is
not
none
and
selectedship
=
=
id
(ship):
selected
=
item
self
.treewidget.expanditem(parent)
self
.treewidget.expanditem(ancestor)
self
.treewidget.resizecolumntocontents(
0
)
self
.treewidget.resizecolumntocontents(
1
)
if
selected
is
not
none:
selected.setselected(true)
self
.treewidget.setcurrentitem(selected)
print
(parentfromcountry)
print
(parentfromcountryowner)
def
addship(
self
):
ship
=
ships.ship(
" unknown"
,
" unknown"
,
" unknown"
)
self
.ships.addship(ship)
self
.populatelist()
self
.populatetree()
self
.populatetable(
id
(ship))
self
.tablewidget.setfocus()
self
.tablewidget.edititem(
self
.tablewidget.currentitem())
def
tableitemchanged(
self
, item):
ship
=
self
.currenttableship()
if
ship
is
none:
return
column
=
self
.tablewidget.currentcolumn()
if
column
=
=
ships.name:
ship.name
=
item.text().strip()
elif
column
=
=
ships.owner:
ship.owner
=
item.text().strip()
elif
column
=
=
ships.country:
ship.country
=
item.text().strip()
elif
column
=
=
ships.description:
ship.description
=
item.text().strip()
elif
column
=
=
ships.teu:
ship.teu
=
item.text()
self
.ships.dirty
=
true
self
.populatelist()
self
.populatetree()
def
currenttableship(
self
):
item
=
self
.tablewidget.item(
self
.tablewidget.currentrow(),
0
)
if
item
is
none:
return
none
return
self
.ships.ship(
item.data(qt.userrole))
def
removeship(
self
):
ship
=
self
.currenttableship()
if
ship
is
none:
return
if
(qmessagebox.question(
self
,
"ships - remove"
,
"remove {0} of {1}/{2}?"
.
format
(ship.name,ship.owner,ship.country),
qmessagebox.yes|qmessagebox.no)
=
=
qmessagebox.no):
return
self
.ships.removeship(ship)
self
.populatelist()
self
.populatetree()
self
.populatetable()
app
=
qapplication(sys.argv)
form
=
mainform()
form.show()
app.exec_()
|
运行结果:
以上这篇python3+pyqt5 使用三种不同的简便项窗口部件显示数据的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我.
原文链接:https://blog.csdn.net/xiaoyangyang20/article/details/70213084 。
最后此篇关于python3+PyQt5 使用三种不同的简便项窗口部件显示数据的方法的文章就讲到这里了,如果你想了解更多关于python3+PyQt5 使用三种不同的简便项窗口部件显示数据的方法的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
https://github.com/mattdiamond/Recorderjs/blob/master/recorder.js中的代码 我不明白 JavaScript 语法,比如 (functio
在 iOS 7 及更早版本中,如果我们想在应用程序中找到 topMostWindow,我们通常使用以下代码行 [[[UIApplication sharedApplication] windows]
我已经尝试解决这个问题很长一段时间了:我无法访问窗口的 url,因为它位于另一个域上..有一些解决方案吗? function login() { var cb = window.ope
是否可以将 FFMPEG 视频流传递到 C# 窗口?现在它在新窗口中作为新进程打开,我只是想将它传递给我自己的 SessionWindow。 此时我像这样执行ffplay: public void E
我有一个名为 x 的矩阵看起来像这样: pTime Close 1 1275087600 1.2268 2 1275264000 1.2264 3 1275264300 1.2
在编译时,发生搜索,grep搜索等,Emacs会在单独的窗口中创建一个新的缓冲区来显示结果,有没有自动跳转到那个窗口的方法?这很有用,因为我可以使用 n 和 p 而不是 M-g n 和 M-g p 移
我有一个启动 PowerShell 脚本的批处理文件。 批处理文件: START Powershell -executionpolicy RemoteSigned -noexit -file "MyS
我有一个基于菜单栏的应用程序,单击图标时会显示一个窗口。在 Mac OS X Lion 上一切正常,但由于某种原因,在 Snow Leopard 和早期版本的 Mac OS X 上会出现错误。任何时候
在 macOS 中,如何在 Xcode 和/或 Interface Builder 中创建带有“集成标题栏和工具栏”的窗口? 这是“宽标题栏”类型的窗口,已添加到 OS X 10.10 Yosemit
在浏览器 (Chrome) 中 JavaScript: var DataModler = { Data: { Something: 'value' }, Process: functi
我有 3 个 html 页面。第 1 页链接到第 2 页,第 2 页链接到第 3 页(为了简单起见)。 我希望页面 2 中的链接打开页面 3 并关闭页面 1(选项卡 1)。 据我了解,您无法使用 Ja
当点击“创建节点”按钮时,如何打开一个新的框架或窗口?我希望新框架包含一个文本字段和下拉菜单,以便用户可以选择一个选项。 Create node Search node
我有一个用户控件,用于编辑应用程序中的某些对象。 我最近遇到一个实例,我想弹出一个新的对话框(窗口)来托管此用户控件。 如何实例化新窗口并将需要设置的任何属性从窗口传递到用户控件? 感谢您的宝贵时间。
我有一个Observable,它发出许多对象,我想使用window或buffer操作对这些对象进行分组。但是,我不想指定count参数来确定窗口中应包含多少个对象,而是希望能够使用自定义条件。 例如,
我有以下代码,它打开一个新的 JavaFX 阶段(我们称之为窗口)。 openAlertBox.setOnAction(e -> { AlertBox alert = AlertBox
我要添加一个“在新窗口中打开”上下文菜单项,该菜单项将以新的UIScene打开我的应用程序文档之一。当然,我只想在实际上支持多个场景的设备上显示该菜单项。 目前,我只是在检查设备是否是使用旧设备的iP
我正在尝试创建一个 AIR 应用程序来记录应用程序的使用情况,使用 AIR 从系统获取信息的唯一简单方法是使用命令行工具和抓取 标准输出 . 我知道像 这样的工具顶部 和 ps 对于 OS X,但它们
所以我有这个简单的 turtle 螺旋制作器,我想知道是否有一种方法可以打印出由该程序创建的我的设计副本。 代码: import turtle x= float(input("Angle: ")) y
我正在编写一个 C# WPF 程序,它将文本消息发送到另一个程序的窗口。我有一个宏程序作为我的键盘驱动程序 (Logitech g15) 的一部分,它已经这样做了,尽管它不会将击键直接发送到进程,而是
我尝试使用以下代码通过 UDP 发送,但得到了奇怪的结果。 if((sendto(newSocket, sendBuf, totalLength, 0, (SOCKADDR *)&sendAd
我是一名优秀的程序员,十分优秀!