BERATools 0.2.0__py3-none-any.whl → 0.2.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- beratools/__init__.py +1 -7
- beratools/core/algo_centerline.py +491 -351
- beratools/core/algo_common.py +497 -0
- beratools/core/algo_cost.py +192 -0
- beratools/core/{dijkstra_algorithm.py → algo_dijkstra.py} +503 -460
- beratools/core/algo_footprint_rel.py +577 -0
- beratools/core/algo_line_grouping.py +944 -0
- beratools/core/algo_merge_lines.py +214 -0
- beratools/core/algo_split_with_lines.py +304 -0
- beratools/core/algo_tiler.py +428 -0
- beratools/core/algo_vertex_optimization.py +469 -0
- beratools/core/constants.py +52 -86
- beratools/core/logger.py +76 -85
- beratools/core/tool_base.py +196 -133
- beratools/gui/__init__.py +11 -15
- beratools/gui/{beratools.json → assets/beratools.json} +2185 -2300
- beratools/gui/batch_processing_dlg.py +513 -463
- beratools/gui/bt_data.py +481 -487
- beratools/gui/bt_gui_main.py +710 -691
- beratools/gui/main.py +26 -0
- beratools/gui/map_window.py +162 -146
- beratools/gui/tool_widgets.py +725 -493
- beratools/tools/Beratools_r_script.r +1120 -1120
- beratools/tools/Ht_metrics.py +116 -116
- beratools/tools/__init__.py +7 -7
- beratools/tools/batch_processing.py +136 -132
- beratools/tools/canopy_threshold_relative.py +672 -670
- beratools/tools/canopycostraster.py +222 -222
- beratools/tools/centerline.py +136 -176
- beratools/tools/common.py +857 -885
- beratools/tools/fl_regen_csf.py +428 -428
- beratools/tools/forest_line_attributes.py +408 -408
- beratools/tools/line_footprint_absolute.py +213 -363
- beratools/tools/line_footprint_fixed.py +436 -282
- beratools/tools/line_footprint_functions.py +733 -720
- beratools/tools/line_footprint_relative.py +73 -64
- beratools/tools/line_grouping.py +45 -0
- beratools/tools/ln_relative_metrics.py +615 -615
- beratools/tools/r_cal_lpi_elai.r +24 -24
- beratools/tools/r_generate_pd_focalraster.r +100 -100
- beratools/tools/r_interface.py +79 -79
- beratools/tools/r_point_density.r +8 -8
- beratools/tools/rpy_chm2trees.py +86 -86
- beratools/tools/rpy_dsm_chm_by.py +81 -81
- beratools/tools/rpy_dtm_by.py +63 -63
- beratools/tools/rpy_find_cellsize.py +43 -43
- beratools/tools/rpy_gnd_csf.py +74 -74
- beratools/tools/rpy_hummock_hollow.py +85 -85
- beratools/tools/rpy_hummock_hollow_raster.py +71 -71
- beratools/tools/rpy_las_info.py +51 -51
- beratools/tools/rpy_laz2las.py +40 -40
- beratools/tools/rpy_lpi_elai_lascat.py +466 -466
- beratools/tools/rpy_normalized_lidar_by.py +56 -56
- beratools/tools/rpy_percent_above_dbh.py +80 -80
- beratools/tools/rpy_points2trees.py +88 -88
- beratools/tools/rpy_vegcoverage.py +94 -94
- beratools/tools/tiler.py +48 -206
- beratools/tools/tool_template.py +69 -54
- beratools/tools/vertex_optimization.py +61 -620
- beratools/tools/zonal_threshold.py +144 -144
- beratools-0.2.2.dist-info/METADATA +108 -0
- beratools-0.2.2.dist-info/RECORD +74 -0
- {beratools-0.2.0.dist-info → beratools-0.2.2.dist-info}/WHEEL +1 -1
- {beratools-0.2.0.dist-info → beratools-0.2.2.dist-info}/licenses/LICENSE +22 -22
- beratools/gui/cli.py +0 -18
- beratools/gui/gui.json +0 -8
- beratools/gui_tk/ASCII Banners.txt +0 -248
- beratools/gui_tk/__init__.py +0 -20
- beratools/gui_tk/beratools_main.py +0 -515
- beratools/gui_tk/bt_widgets.py +0 -442
- beratools/gui_tk/cli.py +0 -18
- beratools/gui_tk/img/BERALogo.png +0 -0
- beratools/gui_tk/img/closed.gif +0 -0
- beratools/gui_tk/img/closed.png +0 -0
- beratools/gui_tk/img/open.gif +0 -0
- beratools/gui_tk/img/open.png +0 -0
- beratools/gui_tk/img/tool.gif +0 -0
- beratools/gui_tk/img/tool.png +0 -0
- beratools/gui_tk/main.py +0 -14
- beratools/gui_tk/map_window.py +0 -144
- beratools/gui_tk/runner.py +0 -1481
- beratools/gui_tk/tooltip.py +0 -55
- beratools/third_party/pyqtlet2/__init__.py +0 -9
- beratools/third_party/pyqtlet2/leaflet/__init__.py +0 -26
- beratools/third_party/pyqtlet2/leaflet/control/__init__.py +0 -6
- beratools/third_party/pyqtlet2/leaflet/control/control.py +0 -59
- beratools/third_party/pyqtlet2/leaflet/control/draw.py +0 -52
- beratools/third_party/pyqtlet2/leaflet/control/layers.py +0 -20
- beratools/third_party/pyqtlet2/leaflet/core/Parser.py +0 -24
- beratools/third_party/pyqtlet2/leaflet/core/__init__.py +0 -2
- beratools/third_party/pyqtlet2/leaflet/core/evented.py +0 -180
- beratools/third_party/pyqtlet2/leaflet/layer/__init__.py +0 -5
- beratools/third_party/pyqtlet2/leaflet/layer/featuregroup.py +0 -34
- beratools/third_party/pyqtlet2/leaflet/layer/icon/__init__.py +0 -1
- beratools/third_party/pyqtlet2/leaflet/layer/icon/icon.py +0 -30
- beratools/third_party/pyqtlet2/leaflet/layer/imageoverlay.py +0 -18
- beratools/third_party/pyqtlet2/leaflet/layer/layer.py +0 -105
- beratools/third_party/pyqtlet2/leaflet/layer/layergroup.py +0 -45
- beratools/third_party/pyqtlet2/leaflet/layer/marker/__init__.py +0 -1
- beratools/third_party/pyqtlet2/leaflet/layer/marker/marker.py +0 -91
- beratools/third_party/pyqtlet2/leaflet/layer/tile/__init__.py +0 -2
- beratools/third_party/pyqtlet2/leaflet/layer/tile/gridlayer.py +0 -4
- beratools/third_party/pyqtlet2/leaflet/layer/tile/tilelayer.py +0 -16
- beratools/third_party/pyqtlet2/leaflet/layer/vector/__init__.py +0 -5
- beratools/third_party/pyqtlet2/leaflet/layer/vector/circle.py +0 -15
- beratools/third_party/pyqtlet2/leaflet/layer/vector/circlemarker.py +0 -18
- beratools/third_party/pyqtlet2/leaflet/layer/vector/path.py +0 -5
- beratools/third_party/pyqtlet2/leaflet/layer/vector/polygon.py +0 -14
- beratools/third_party/pyqtlet2/leaflet/layer/vector/polyline.py +0 -18
- beratools/third_party/pyqtlet2/leaflet/layer/vector/rectangle.py +0 -14
- beratools/third_party/pyqtlet2/leaflet/map/__init__.py +0 -1
- beratools/third_party/pyqtlet2/leaflet/map/map.py +0 -220
- beratools/third_party/pyqtlet2/mapwidget.py +0 -45
- beratools/third_party/pyqtlet2/web/custom.js +0 -43
- beratools/third_party/pyqtlet2/web/map.html +0 -23
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/images/layers-2x.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/images/layers.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/images/marker-icon-2x.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/images/marker-icon.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/images/marker-shadow.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/leaflet.css +0 -656
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/leaflet.js +0 -6
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/.codeclimate.yml +0 -14
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/.editorconfig +0 -4
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/.gitattributes +0 -22
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/.travis.yml +0 -43
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/LICENSE +0 -20
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/layers-2x.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/layers.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/marker-icon-2x.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/marker-icon.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/marker-shadow.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/spritesheet-2x.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/spritesheet.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/spritesheet.svg +0 -156
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/leaflet.draw.css +0 -10
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/leaflet.draw.js +0 -10
- beratools/third_party/pyqtlet2/web/modules/leaflet_rotatedMarker_020/LICENSE +0 -22
- beratools/third_party/pyqtlet2/web/modules/leaflet_rotatedMarker_020/leaflet.rotatedMarker.js +0 -57
- beratools/tools/forest_line_ecosite.py +0 -216
- beratools/tools/lapis_all.py +0 -103
- beratools/tools/least_cost_path_from_chm.py +0 -152
- beratools-0.2.0.dist-info/METADATA +0 -63
- beratools-0.2.0.dist-info/RECORD +0 -142
- /beratools/gui/{img → assets}/BERALogo.png +0 -0
- /beratools/gui/{img → assets}/closed.gif +0 -0
- /beratools/gui/{img → assets}/closed.png +0 -0
- /beratools/{gui_tk → gui/assets}/gui.json +0 -0
- /beratools/gui/{img → assets}/open.gif +0 -0
- /beratools/gui/{img → assets}/open.png +0 -0
- /beratools/gui/{img → assets}/tool.gif +0 -0
- /beratools/gui/{img → assets}/tool.png +0 -0
- {beratools-0.2.0.dist-info → beratools-0.2.2.dist-info}/entry_points.txt +0 -0
|
@@ -1,463 +1,513 @@
|
|
|
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
|
-
def
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return self._df.
|
|
48
|
-
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
self.
|
|
71
|
-
self._df.
|
|
72
|
-
self._df.
|
|
73
|
-
self.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
self.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
self.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
self.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
def
|
|
109
|
-
|
|
110
|
-
self.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
self.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
self.
|
|
124
|
-
self.
|
|
125
|
-
self.
|
|
126
|
-
|
|
127
|
-
self.
|
|
128
|
-
self.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
#
|
|
133
|
-
self.
|
|
134
|
-
|
|
135
|
-
self.
|
|
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
|
-
self.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
self.
|
|
184
|
-
self.
|
|
185
|
-
|
|
186
|
-
self.
|
|
187
|
-
|
|
188
|
-
self.
|
|
189
|
-
self.
|
|
190
|
-
self.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
self.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
self.
|
|
205
|
-
self.
|
|
206
|
-
self.
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
self.
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
self.
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
self.
|
|
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
|
-
def
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
self.
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
self.model.
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
def
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
self.
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
self.
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
def
|
|
301
|
-
|
|
302
|
-
self.
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
def
|
|
306
|
-
|
|
307
|
-
if self.model.
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
self.
|
|
349
|
-
self.
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
1
|
+
"""
|
|
2
|
+
Copyright (C) 2025 Applied Geospatial Research Group.
|
|
3
|
+
|
|
4
|
+
This script is licensed under the GNU General Public License v3.0.
|
|
5
|
+
See <https://gnu.org/licenses/gpl-3.0> for full license details.
|
|
6
|
+
|
|
7
|
+
Author: Richard Zeng
|
|
8
|
+
|
|
9
|
+
Description:
|
|
10
|
+
This script is part of the BERA Tools.
|
|
11
|
+
Webpage: https://github.com/appliedgrg/beratools
|
|
12
|
+
|
|
13
|
+
Batch processing dialog.
|
|
14
|
+
"""
|
|
15
|
+
import sys
|
|
16
|
+
import pandas as pd
|
|
17
|
+
from PyQt5 import QtCore
|
|
18
|
+
from PyQt5 import QtWidgets
|
|
19
|
+
from PyQt5 import QtGui, QtPrintSupport
|
|
20
|
+
|
|
21
|
+
from beratools.gui.tool_widgets import ToolWidgets
|
|
22
|
+
from beratools.gui.bt_data import BTData
|
|
23
|
+
bt = BTData()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class _PandasModel(QtCore.QAbstractTableModel):
|
|
27
|
+
def __init__(self, df=pd.DataFrame(), parent=None):
|
|
28
|
+
QtCore.QAbstractTableModel.__init__(self, parent=None)
|
|
29
|
+
self._df = df
|
|
30
|
+
self.setChanged = False
|
|
31
|
+
self.dataChanged.connect(self.setModified)
|
|
32
|
+
|
|
33
|
+
def setModified(self):
|
|
34
|
+
self.setChanged = True
|
|
35
|
+
print(self.setChanged)
|
|
36
|
+
|
|
37
|
+
def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole):
|
|
38
|
+
if role != QtCore.Qt.DisplayRole:
|
|
39
|
+
return QtCore.QVariant()
|
|
40
|
+
if orientation == QtCore.Qt.Horizontal:
|
|
41
|
+
try:
|
|
42
|
+
return self._df.columns.tolist()[section]
|
|
43
|
+
except (IndexError,):
|
|
44
|
+
return QtCore.QVariant()
|
|
45
|
+
elif orientation == QtCore.Qt.Vertical:
|
|
46
|
+
try:
|
|
47
|
+
return self._df.index.tolist()[section]
|
|
48
|
+
except (IndexError,):
|
|
49
|
+
return QtCore.QVariant()
|
|
50
|
+
|
|
51
|
+
def flags(self, index):
|
|
52
|
+
return (
|
|
53
|
+
QtCore.Qt.ItemIsEnabled
|
|
54
|
+
| QtCore.Qt.ItemIsSelectable
|
|
55
|
+
| QtCore.Qt.ItemIsEditable
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
def data(self, index, role=QtCore.Qt.DisplayRole):
|
|
59
|
+
if index.isValid():
|
|
60
|
+
if role == QtCore.Qt.EditRole:
|
|
61
|
+
return self._df.values[index.row()][index.column()]
|
|
62
|
+
elif role == QtCore.Qt.DisplayRole:
|
|
63
|
+
return self._df.values[index.row()][index.column()]
|
|
64
|
+
return None
|
|
65
|
+
|
|
66
|
+
def data_row_dict(self, row):
|
|
67
|
+
return self._df.iloc[row].to_dict()
|
|
68
|
+
|
|
69
|
+
def setData(self, index, value, role):
|
|
70
|
+
row = self._df.index[index.row()]
|
|
71
|
+
col = self._df.columns[index.column()]
|
|
72
|
+
self._df.values[row][col] = value
|
|
73
|
+
self.dataChanged.emit(index, index)
|
|
74
|
+
return True
|
|
75
|
+
|
|
76
|
+
def rowCount(self, parent=QtCore.QModelIndex()):
|
|
77
|
+
return len(self._df.index)
|
|
78
|
+
|
|
79
|
+
def columnCount(self, parent=QtCore.QModelIndex()):
|
|
80
|
+
return len(self._df.columns)
|
|
81
|
+
|
|
82
|
+
def sort(self, column, order):
|
|
83
|
+
col_name = self._df.columns.tolist()[column]
|
|
84
|
+
self.layoutAboutToBeChanged.emit()
|
|
85
|
+
self._df.sort_values(
|
|
86
|
+
col_name, ascending=order == QtCore.Qt.AscendingOrder, inplace=True
|
|
87
|
+
)
|
|
88
|
+
self._df.reset_index(inplace=True, drop=True)
|
|
89
|
+
self.layoutChanged.emit()
|
|
90
|
+
|
|
91
|
+
def insertRows(self, position, rows=1, index=QtCore.QModelIndex()):
|
|
92
|
+
self.beginInsertRows(QtCore.QModelIndex(), position, position + rows - 1)
|
|
93
|
+
for i in range(rows):
|
|
94
|
+
self._df.loc[len(self._df)] = self.default_record
|
|
95
|
+
|
|
96
|
+
self.endInsertRows()
|
|
97
|
+
return True
|
|
98
|
+
|
|
99
|
+
def removeRows(self, position, rows=1, index=QtCore.QModelIndex()):
|
|
100
|
+
self.beginRemoveRows(QtCore.QModelIndex(), position, position + rows - 1)
|
|
101
|
+
for i in range(rows):
|
|
102
|
+
self._df.drop(self._df.index[position + i], inplace=True)
|
|
103
|
+
print('removed: {}'.format(position + i))
|
|
104
|
+
|
|
105
|
+
self.endRemoveRows()
|
|
106
|
+
return True
|
|
107
|
+
|
|
108
|
+
def updateRow(self, row, row_data):
|
|
109
|
+
self._df.loc[row] = row_data
|
|
110
|
+
self.dataChanged(row, 0)
|
|
111
|
+
|
|
112
|
+
def save_csv(self, csv_file):
|
|
113
|
+
self._df.to_csv(csv_file, index=False)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class BPDialog(QtWidgets.QDialog):
|
|
117
|
+
"""Batch Processing Dialog."""
|
|
118
|
+
|
|
119
|
+
# signals
|
|
120
|
+
signal_update_tool_widgets = QtCore.pyqtSignal(int)
|
|
121
|
+
|
|
122
|
+
def __init__(self, tool_name, parent=None):
|
|
123
|
+
super(BPDialog, self).__init__(parent)
|
|
124
|
+
self.setWindowTitle('Batch Processing')
|
|
125
|
+
self.MaxRecentFiles = 5
|
|
126
|
+
self.window_list = []
|
|
127
|
+
self.recent_files = []
|
|
128
|
+
self.settings = QtCore.QSettings('Richard Zeng', 'Batch Processing')
|
|
129
|
+
self.filename = ""
|
|
130
|
+
self.setGeometry(0, 0, 800, 600)
|
|
131
|
+
|
|
132
|
+
# table view
|
|
133
|
+
self.table_view = QtWidgets.QTableView()
|
|
134
|
+
self.table_view.verticalHeader().setVisible(True)
|
|
135
|
+
self.model = _PandasModel()
|
|
136
|
+
self.table_view.setModel(self.model)
|
|
137
|
+
self.table_view.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
|
|
138
|
+
self.table_view.setSelectionBehavior(self.table_view.SelectRows)
|
|
139
|
+
self.table_view.setSelectionMode(self.table_view.ExtendedSelection)
|
|
140
|
+
|
|
141
|
+
self.table_view.clicked.connect(self.table_view_clicked)
|
|
142
|
+
self.table_view.verticalHeader().sectionClicked.connect(
|
|
143
|
+
self.table_view_vertical_header_clicked
|
|
144
|
+
)
|
|
145
|
+
QtWidgets.QShortcut(
|
|
146
|
+
QtCore.Qt.Key_Up, self.table_view, activated=self.table_view_key_up
|
|
147
|
+
)
|
|
148
|
+
QtWidgets.QShortcut(
|
|
149
|
+
QtCore.Qt.Key_Down, self.table_view, activated=self.table_view_key_down
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
# create form
|
|
153
|
+
self.tool_name = tool_name
|
|
154
|
+
tool_args = bt.get_bera_tool_args(self.tool_name)
|
|
155
|
+
self.tool_widgets = ToolWidgets(tool_name, tool_args, False)
|
|
156
|
+
|
|
157
|
+
# self.createToolBar()
|
|
158
|
+
hbox_widgets = QtWidgets.QHBoxLayout()
|
|
159
|
+
hbox_widgets.addWidget(self.table_view, 2)
|
|
160
|
+
hbox_widgets.addWidget(self.tool_widgets, 1)
|
|
161
|
+
|
|
162
|
+
# Add project, record related button box
|
|
163
|
+
self.project_btns = QtWidgets.QHBoxLayout()
|
|
164
|
+
open_button = QtWidgets.QPushButton('Open')
|
|
165
|
+
save_button = QtWidgets.QPushButton('Save')
|
|
166
|
+
save_as_button = QtWidgets.QPushButton('Save as')
|
|
167
|
+
delete_button = QtWidgets.QPushButton('Delete records')
|
|
168
|
+
add_button = QtWidgets.QPushButton('Add record')
|
|
169
|
+
print_button = QtWidgets.QPushButton('Print')
|
|
170
|
+
|
|
171
|
+
open_button.clicked.connect(self.load_csv)
|
|
172
|
+
save_button.setShortcut(QtGui.QKeySequence.Open)
|
|
173
|
+
save_button.clicked.connect(self.write_csv_update)
|
|
174
|
+
save_button.setShortcut(QtGui.QKeySequence.Save)
|
|
175
|
+
save_as_button.clicked.connect(self.write_csv)
|
|
176
|
+
save_as_button.setShortcut(QtGui.QKeySequence.SaveAs)
|
|
177
|
+
delete_button.clicked.connect(self.table_view_delete_records)
|
|
178
|
+
delete_button.setShortcut(QtGui.QKeySequence.Delete)
|
|
179
|
+
|
|
180
|
+
add_button.clicked.connect(self.table_view_add_records)
|
|
181
|
+
|
|
182
|
+
self.last_files = QtWidgets.QComboBox()
|
|
183
|
+
self.last_files.setFixedWidth(300)
|
|
184
|
+
self.last_files.currentIndexChanged.connect(self.load_recent)
|
|
185
|
+
|
|
186
|
+
self.line_find = QtWidgets.QLineEdit()
|
|
187
|
+
self.line_find.setPlaceholderText("find")
|
|
188
|
+
self.line_find.setClearButtonEnabled(True)
|
|
189
|
+
self.line_find.setFixedWidth(250)
|
|
190
|
+
self.line_find.returnPressed.connect(self.find_in_table)
|
|
191
|
+
|
|
192
|
+
print_button.clicked.connect(self.handle_preview)
|
|
193
|
+
|
|
194
|
+
self.project_btns.addWidget(open_button, QtWidgets.QDialogButtonBox.ActionRole)
|
|
195
|
+
self.project_btns.addWidget(save_button, QtWidgets.QDialogButtonBox.ActionRole)
|
|
196
|
+
self.project_btns.addWidget(save_as_button, QtWidgets.QDialogButtonBox.ActionRole)
|
|
197
|
+
self.project_btns.addWidget(delete_button, QtWidgets.QDialogButtonBox.ActionRole)
|
|
198
|
+
self.project_btns.addWidget(add_button, QtWidgets.QDialogButtonBox.ActionRole)
|
|
199
|
+
self.project_btns.addWidget(self.line_find, QtWidgets.QDialogButtonBox.ActionRole)
|
|
200
|
+
self.project_btns.addWidget(print_button, QtWidgets.QDialogButtonBox.ActionRole)
|
|
201
|
+
|
|
202
|
+
# Add OK/cancel buttons
|
|
203
|
+
self.ok_btn_box = QtWidgets.QDialogButtonBox()
|
|
204
|
+
self.ok_btn_box.addButton("Run", QtWidgets.QDialogButtonBox.AcceptRole)
|
|
205
|
+
self.ok_btn_box.addButton("Cancel", QtWidgets.QDialogButtonBox.RejectRole)
|
|
206
|
+
self.ok_btn_box.addButton("Help", QtWidgets.QDialogButtonBox.HelpRole)
|
|
207
|
+
|
|
208
|
+
self.ok_btn_box.accepted.connect(self.run)
|
|
209
|
+
self.ok_btn_box.rejected.connect(self.reject)
|
|
210
|
+
self.ok_btn_box.helpRequested.connect(self.help)
|
|
211
|
+
|
|
212
|
+
hbox_btns = QtWidgets.QHBoxLayout()
|
|
213
|
+
hbox_btns.addLayout(self.project_btns)
|
|
214
|
+
hbox_btns.addWidget(self.ok_btn_box)
|
|
215
|
+
|
|
216
|
+
vbox_main = QtWidgets.QVBoxLayout()
|
|
217
|
+
vbox_main.addLayout(hbox_widgets)
|
|
218
|
+
vbox_main.addLayout(hbox_btns)
|
|
219
|
+
self.setLayout(vbox_main)
|
|
220
|
+
|
|
221
|
+
# delete dialog when close
|
|
222
|
+
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
|
|
223
|
+
|
|
224
|
+
self.setContentsMargins(10, 10, 10, 10)
|
|
225
|
+
self.read_settings()
|
|
226
|
+
self.table_view.setFocus()
|
|
227
|
+
# self.statusBar().showMessage("Ready", 0)
|
|
228
|
+
|
|
229
|
+
# signals
|
|
230
|
+
self.tool_widgets.signal_save_tool_params.connect(self.table_view_update_record)
|
|
231
|
+
self.signal_update_tool_widgets.connect(self.update_tool_widgets)
|
|
232
|
+
|
|
233
|
+
def accept(self):
|
|
234
|
+
if self.line_find.hasFocus():
|
|
235
|
+
return
|
|
236
|
+
|
|
237
|
+
print("Run the batch processing.")
|
|
238
|
+
QtWidgets.QDialog.accept(self)
|
|
239
|
+
|
|
240
|
+
def run(self):
|
|
241
|
+
self.model.save_csv(self.filename)
|
|
242
|
+
self.accept()
|
|
243
|
+
|
|
244
|
+
def reject(self):
|
|
245
|
+
print("Batch processing canceled.")
|
|
246
|
+
self.close()
|
|
247
|
+
|
|
248
|
+
def help(self):
|
|
249
|
+
print("Help requested.")
|
|
250
|
+
|
|
251
|
+
def table_view_clicked(self, item):
|
|
252
|
+
print('Row, column:{}, {}'.format(item.row(), item.column()))
|
|
253
|
+
self.signal_update_tool_widgets.emit(item.row())
|
|
254
|
+
|
|
255
|
+
def table_view_vertical_header_clicked(self, item):
|
|
256
|
+
print('Horizontal header clicked: {}'.format(item))
|
|
257
|
+
self.signal_update_tool_widgets.emit(item)
|
|
258
|
+
|
|
259
|
+
def table_view_key_up(self):
|
|
260
|
+
current_row = self.table_view.selectionModel().selectedRows()[-1].row()
|
|
261
|
+
if current_row >= 1:
|
|
262
|
+
self.table_view.selectRow(current_row - 1)
|
|
263
|
+
self.signal_update_tool_widgets.emit(current_row - 1)
|
|
264
|
+
|
|
265
|
+
def table_view_delete_records(self):
|
|
266
|
+
selected_index = self.table_view.selectionModel().selectedRows()
|
|
267
|
+
rows = [item.row() for item in selected_index]
|
|
268
|
+
rows.sort(reverse=True)
|
|
269
|
+
|
|
270
|
+
for i in rows:
|
|
271
|
+
self.model.removeRows(i)
|
|
272
|
+
|
|
273
|
+
current_row = i
|
|
274
|
+
if self.model.rowCount() > 0:
|
|
275
|
+
if current_row > self.model.rowCount() - 1:
|
|
276
|
+
current_row = self.model.rowCount() - 1
|
|
277
|
+
|
|
278
|
+
self.table_view.selectRow(current_row)
|
|
279
|
+
self.signal_update_tool_widgets.emit(current_row)
|
|
280
|
+
|
|
281
|
+
print('remove row {}'.format(i))
|
|
282
|
+
|
|
283
|
+
self.model.submit()
|
|
284
|
+
|
|
285
|
+
def table_view_add_records(self):
|
|
286
|
+
self.model.default_record = bt.get_bera_tool_parameters_list(self.tool_name)
|
|
287
|
+
ret = self.model.insertRow(self.model.rowCount())
|
|
288
|
+
if ret:
|
|
289
|
+
count = self.model.rowCount() - 1
|
|
290
|
+
self.table_view.selectRow(count)
|
|
291
|
+
self.signal_update_tool_widgets.emit(count)
|
|
292
|
+
|
|
293
|
+
print('Insert row in position {}'.format(count))
|
|
294
|
+
self.model.submit()
|
|
295
|
+
|
|
296
|
+
def table_view_update_record(self, row_data):
|
|
297
|
+
current_row = self.table_view.selectionModel().selectedRows()[-1].row()
|
|
298
|
+
self.model.updateRow(current_row, row_data)
|
|
299
|
+
|
|
300
|
+
def update_tool_widgets(self, row):
|
|
301
|
+
tool_params = self.model.data_row_dict(row)
|
|
302
|
+
self.tool_widgets.update_widgets(tool_params)
|
|
303
|
+
print('Update tool parameters for record {}'.format(tool_params))
|
|
304
|
+
|
|
305
|
+
def table_view_key_down(self):
|
|
306
|
+
current_row = self.table_view.selectionModel().selectedRows()[-1].row()
|
|
307
|
+
if current_row < self.model.rowCount() - 1:
|
|
308
|
+
self.table_view.selectRow(current_row + 1)
|
|
309
|
+
self.signal_update_tool_widgets.emit(current_row + 1)
|
|
310
|
+
|
|
311
|
+
def read_settings(self):
|
|
312
|
+
print("reading settings")
|
|
313
|
+
if self.settings.contains("geometry"):
|
|
314
|
+
self.setGeometry(self.settings.value('geometry'))
|
|
315
|
+
if self.settings.contains("recentFiles"):
|
|
316
|
+
self.recent_files = self.settings.value('recentFiles')
|
|
317
|
+
self.last_files.addItem("last Files")
|
|
318
|
+
self.last_files.addItems(self.recent_files[:15])
|
|
319
|
+
|
|
320
|
+
def save_settings(self):
|
|
321
|
+
print("saving settings")
|
|
322
|
+
self.settings.setValue('geometry', self.geometry())
|
|
323
|
+
self.settings.setValue('recentFiles', self.recent_files)
|
|
324
|
+
|
|
325
|
+
def closeEvent(self, event):
|
|
326
|
+
print(self.model.setChanged)
|
|
327
|
+
if self.model.setChanged:
|
|
328
|
+
print("is changed, saving?")
|
|
329
|
+
quit_msg = "<b>The document was changed.<br>Do you want to save the changes?</ b>"
|
|
330
|
+
reply = QtWidgets.QMessageBox.question(
|
|
331
|
+
self,
|
|
332
|
+
"Save Confirmation",
|
|
333
|
+
quit_msg,
|
|
334
|
+
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
|
|
335
|
+
QtWidgets.QMessageBox.Yes,
|
|
336
|
+
)
|
|
337
|
+
if reply == QtWidgets.QMessageBox.Yes:
|
|
338
|
+
self.write_csv_update()
|
|
339
|
+
else:
|
|
340
|
+
print("Settings not saved.")
|
|
341
|
+
return
|
|
342
|
+
else:
|
|
343
|
+
print("nothing changed.")
|
|
344
|
+
self.save_settings()
|
|
345
|
+
|
|
346
|
+
def load_recent(self):
|
|
347
|
+
if self.last_files.currentIndex() > 0:
|
|
348
|
+
print(self.last_files.currentText())
|
|
349
|
+
print(self.model.setChanged)
|
|
350
|
+
if self.model.setChanged:
|
|
351
|
+
print("is changed, saving?")
|
|
352
|
+
quit_msg = "<b>The document was changed.<br>Save the changes?</ b>"
|
|
353
|
+
reply = QtWidgets.QMessageBox.question(
|
|
354
|
+
self,
|
|
355
|
+
"Save Confirmation",
|
|
356
|
+
quit_msg,
|
|
357
|
+
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
|
|
358
|
+
QtWidgets.QMessageBox.Yes,
|
|
359
|
+
)
|
|
360
|
+
if reply == QtWidgets.QMessageBox.Yes:
|
|
361
|
+
self.open_csv(self.last_files.currentText())
|
|
362
|
+
else:
|
|
363
|
+
self.open_csv(self.last_files.currentText())
|
|
364
|
+
else:
|
|
365
|
+
self.open_csv(self.last_files.currentText())
|
|
366
|
+
|
|
367
|
+
def open_csv(self, path):
|
|
368
|
+
f = open(path, 'r+b')
|
|
369
|
+
with f:
|
|
370
|
+
df = pd.read_csv(f, sep='\t|;|,|\s+', keep_default_na=False, engine='python',
|
|
371
|
+
skipinitialspace=True, skip_blank_lines=True)
|
|
372
|
+
f.close()
|
|
373
|
+
self.filename = path
|
|
374
|
+
|
|
375
|
+
self.model = _PandasModel(df)
|
|
376
|
+
self.table_view.setModel(self.model)
|
|
377
|
+
self.table_view.resizeColumnsToContents()
|
|
378
|
+
self.table_view.selectRow(0)
|
|
379
|
+
self.signal_update_tool_widgets.emit(0)
|
|
380
|
+
# self.statusBar().showMessage("%s %s" % (path, "loaded"), 0)
|
|
381
|
+
|
|
382
|
+
def find_in_table(self):
|
|
383
|
+
self.table_view.clearSelection()
|
|
384
|
+
text = self.line_find.text()
|
|
385
|
+
model = self.table_view.model()
|
|
386
|
+
for column in range(self.model.columnCount()):
|
|
387
|
+
start = model.index(0, column)
|
|
388
|
+
matches = model.match(
|
|
389
|
+
start, QtCore.Qt.DisplayRole, text, -1, QtCore.Qt.MatchContains
|
|
390
|
+
)
|
|
391
|
+
if matches:
|
|
392
|
+
for index in matches:
|
|
393
|
+
self.table_view.selectionModel().select(
|
|
394
|
+
index, QtCore.QItemSelectionModel.Select
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
def open_file(self, path=None):
|
|
398
|
+
print(self.model.setChanged)
|
|
399
|
+
if self.model.setChanged:
|
|
400
|
+
print("is changed, saving?")
|
|
401
|
+
quit_msg = "<b>The document was changed.<br>Save the changes?</ b>"
|
|
402
|
+
reply = QtWidgets.QMessageBox.question(
|
|
403
|
+
self,
|
|
404
|
+
"Save Confirmation",
|
|
405
|
+
quit_msg,
|
|
406
|
+
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
|
|
407
|
+
QtWidgets.QMessageBox.Yes,
|
|
408
|
+
)
|
|
409
|
+
if reply == QtWidgets.QMessageBox.Yes:
|
|
410
|
+
self.write_csv_update()
|
|
411
|
+
else:
|
|
412
|
+
print("not saved, loading ...")
|
|
413
|
+
return
|
|
414
|
+
path, _ = QtWidgets.QFileDialog.getOpenFileName(
|
|
415
|
+
self,
|
|
416
|
+
"Open File",
|
|
417
|
+
QtCore.QDir.homePath() + "/Document/CSV/",
|
|
418
|
+
"CSV Files (*.csv)",
|
|
419
|
+
)
|
|
420
|
+
if path:
|
|
421
|
+
return path
|
|
422
|
+
|
|
423
|
+
def load_csv(self):
|
|
424
|
+
file_name = self.open_file()
|
|
425
|
+
if file_name:
|
|
426
|
+
print(file_name + " loaded")
|
|
427
|
+
f = open(file_name, 'r+b')
|
|
428
|
+
with f:
|
|
429
|
+
df = pd.read_csv(
|
|
430
|
+
f,
|
|
431
|
+
sep="\t|;|,|\s+",
|
|
432
|
+
keep_default_na=False,
|
|
433
|
+
engine="python",
|
|
434
|
+
skipinitialspace=True,
|
|
435
|
+
skip_blank_lines=True,
|
|
436
|
+
)
|
|
437
|
+
f.close()
|
|
438
|
+
self.model = _PandasModel(df)
|
|
439
|
+
self.table_view.setModel(self.model)
|
|
440
|
+
self.table_view.resizeColumnsToContents()
|
|
441
|
+
self.table_view.selectRow(0)
|
|
442
|
+
# self.statusBar().showMessage("%s %s" % (fileName, "loaded"), 0)
|
|
443
|
+
self.recent_files.insert(0, file_name)
|
|
444
|
+
self.last_files.insertItem(1, file_name)
|
|
445
|
+
|
|
446
|
+
def write_csv(self):
|
|
447
|
+
file_name, _ = QtWidgets.QFileDialog.getSaveFileName(
|
|
448
|
+
self, "Open File", self.filename, "CSV Files (*.csv)"
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
if file_name:
|
|
452
|
+
print(file_name + " saved")
|
|
453
|
+
f = open(file_name, 'w')
|
|
454
|
+
new_model = self.model
|
|
455
|
+
data_frame = new_model._df.copy()
|
|
456
|
+
data_frame.to_csv(f, sep=',', index=False, header=True, lineterminator='\n')
|
|
457
|
+
|
|
458
|
+
def write_csv_update(self):
|
|
459
|
+
if self.filename:
|
|
460
|
+
f = open(self.filename, 'w')
|
|
461
|
+
new_model = self.model
|
|
462
|
+
data_frame = new_model._df.copy()
|
|
463
|
+
data_frame.to_csv(f, sep='\t', index=False, header=False)
|
|
464
|
+
self.model.setChanged = False
|
|
465
|
+
print("%s %s" % (self.filename, "saved"))
|
|
466
|
+
# self.statusBar().showMessage("%s %s" % (self.filename, "saved"), 0)
|
|
467
|
+
|
|
468
|
+
def handle_preview(self):
|
|
469
|
+
if self.model.rowCount() == 0:
|
|
470
|
+
self.msg("no rows")
|
|
471
|
+
else:
|
|
472
|
+
dialog = QtPrintSupport.QPrintPreviewDialog()
|
|
473
|
+
dialog.setFixedSize(1000, 700)
|
|
474
|
+
dialog.paintRequested.connect(self.handle_paint_request)
|
|
475
|
+
dialog.exec_()
|
|
476
|
+
print("Print Preview closed")
|
|
477
|
+
|
|
478
|
+
def handle_paint_request(self, printer):
|
|
479
|
+
printer.setDocName(self.filename)
|
|
480
|
+
document = QtGui.QTextDocument()
|
|
481
|
+
cursor = QtGui.QTextCursor(document)
|
|
482
|
+
model = self.table_view.model()
|
|
483
|
+
table_format = QtGui.QTextTableFormat()
|
|
484
|
+
table_format.setBorder(0.2)
|
|
485
|
+
table_format.setBorderStyle(3)
|
|
486
|
+
table_format.setCellSpacing(0)
|
|
487
|
+
table_format.setTopMargin(0)
|
|
488
|
+
table_format.setCellPadding(4)
|
|
489
|
+
model = self.table_view.model()
|
|
490
|
+
|
|
491
|
+
# get headers
|
|
492
|
+
my_header = []
|
|
493
|
+
for i in range(0, model.columnCount()):
|
|
494
|
+
my_header = model.headerData(i, QtCore.Qt.Horizontal)
|
|
495
|
+
cursor.insertText(str(my_header))
|
|
496
|
+
cursor.movePosition(QtGui.QTextCursor.NextCell)
|
|
497
|
+
# get cells
|
|
498
|
+
for row in range(0, model.rowCount()):
|
|
499
|
+
for col in range(0, model.columnCount()):
|
|
500
|
+
index = model.index(row, col)
|
|
501
|
+
cursor.insertText(str(index.data()))
|
|
502
|
+
cursor.movePosition(QtGui.QTextCursor.NextCell)
|
|
503
|
+
document.print_(printer)
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
if __name__ == "__main__":
|
|
507
|
+
app = QtCore.QApplication(sys.argv)
|
|
508
|
+
main = BPDialog('Raster Line Attributes')
|
|
509
|
+
main.show()
|
|
510
|
+
if len(sys.argv) > 1:
|
|
511
|
+
main.open_csv(sys.argv[1])
|
|
512
|
+
|
|
513
|
+
sys.exit(app.exec_())
|