-
Notifications
You must be signed in to change notification settings - Fork 4
/
veraview.py
executable file
·3947 lines (3377 loc) · 124 KB
/
veraview.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
295
296
297
298
299
300
301
302
303
304
305
306
307
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
349
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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# $Id$
#------------------------------------------------------------------------
# NAME: veraview.py -
# HISTORY: -
# 2019-01-19 leerw@ornl.gov -
# Transitioned to Murray's new Volume3DView.
# 2018-12-21 leerw@ornl.gov -
# Implemented VeraViewApp.DoBusyEventOp().
# Added DataAnalysisView widget for testing.
# 2018-10-27 leerw@ornl.gov -
# Added DataAnalysisView widget for testing.
# 2018-10-22 leerw@ornl.gov -
# Added IntraPinEditsAssembly2DView.
# 2018-10-16 leerw@ornl.gov -
# Adding TableView if there is an available grid slot in
# VeraViewFrame.UpdateFrame().
# 2018-10-16 purvesmh@ornl.gov -
# Fix to frame positioning in VeraViewFrame._LoadWidgetConfig().
# 2018-10-01 leerw@ornl.gov -
# Adding AnimateOptionsDialog.
# 2018-09-13 leerw@ornl.gov -
# Adding TableView.
# 2018-08-18 leerw@ornl.gov -
# Experimenting with Core2DPlot.
# 2018-07-26 leerw@ornl.gov -
# Renaming non-derived dataset category/type from 'axial' to
# 'axials' to disambiguate from ':axial' displayed name.
# 2018-06-01 leerw@ornl.gov -
# Updated VeraViewFrame._OnLoadSession() to call
# DataModelMgr.Close() and OpenFile() before _LoadWidgetConfig().
# 2018-05-25 leerw@ornl.gov -
# Initializing weights mode menu in UpdateFrame().
# 2018-03-02 leerw@ornl.gov -
# Fixed bug for Mac in VeraViewApp.OnEventLoopEnter() when
# searching for the frame id/key 1, now increments ids.
# 2017-12-01 leerw@ornl.gov -
# Enabled SubPin2DView.
# 2017-09-11 leerw@ornl.gov -
# Added VesselCoreAxial2DView.
# 2017-08-18 leerw@ornl.gov -
# Using AxialValue class.
# 2017-07-21 leerw@ornl.gov -
# Fixing _OnCharHook for Linux.
# 2017-07-20 leerw@ornl.gov -
# Added Data->Manage Dataset Thresholds menu item.
# Added display of file open warning messages.
# 2017-07-15 leerw@ornl.gov -
# Added VeraViewFrameAnimatorWidget and support for axial level
# and state point animation.
# 2017-07-07 leerw@ornl.gov -
# Hooked ExcoreOutputDialog.
# 2017-05-31 leerw@ornl.gov -
# Renamed SubPin2DView to SubPinRadial2DView.
# 2017-05-26 leerw@ornl.gov -
# Added SubPin2DView but commenting for now.
# 2017-05-14 leerw@ornl.gov -
# Fixed bug to call UpdateFrame() and UpdateAllFrames() in
# _OnOpenFileMgr().
# 2017-05-06 leerw@ornl.gov -
# New Data menu.
# 2017-05-05 leerw@ornl.gov -
# Added no_init param to Create{2D,3D,}Widget(), CreateWindow(),
# and UpdateFrame().
# 2017-04-22 leerw@ornl.gov -
# Using FileManagerDialog.
# 2017-04-21 leerw@ornl.gov -
# Checking HtmlException in _OpenFileBegin(), using
# HtmlMessageDialog in _OpenFileEnd().
# 2017-02-25 leerw@ornl.gov -
# Developing with VesselCore2DView.
# 2017-01-25 leerw@ornl.gov -
# Disabling auto-enable of Detector Detector2DMultiView when
# a detector dataset is present.
# 2017-01-17 leerw@ornl.gov -
# Adding DataSetDiffCreatorDialog.
# 2017-01-14 leerw@ornl.gov -
# Removing channel widgets since others support channel datasets.
# 2016-12-16 leerw@ornl.gov -
# Trying to clean up Mac stuff with Anaconda. Giving up!!.
# 2016-12-12 leerw@ornl.gov -
# 2016-11-26 leerw@ornl.gov -
# Using Config.CanDragNDrop() as a gate for the "Window" menubar
# item.
# 2016-11-19 leerw@ornl.gov -
# Added CreateWindow() and modified LoadDataModel() to have a
# widget_props param in support of widgets-to-window and dragging
# widgets to a different window.
# 2016-10-25 leerw@ornl.gov -
# Using logging.
# 2016-10-02 leerw@ornl.gov -
# Fixed bug where toolbar item event handlers were not removed
# in VeraViewFrame._UpdateToolBar(), resulting in double widgets
# after opening a new file.
# 2016-09-20 leerw@ornl.gov -
# Added weights mode to the edit menu.
# 2016-09-03 leerw@ornl.gov -
# Added TOOLBAR_ITEMS functions to enable core widgets only if
# core.nass gt 1, axial widgets if core.nax gt 1, and Time Plots
# only if data.GetStatesCount() gt 1.
# Only enable axial widgets if core.nax gt 1.
# 2016-08-20 leerw@ornl.gov -
# Changing initial widgets to pin and plots only.
# Assigning last frame position and size on load.
# 2016-08-19 leerw@ornl.gov -
# More messing with widget sizing in grids.
# 2016-08-19 leerw@ornl.gov -
# New DataModelMgr.
# 2016-08-16 leerw@ornl.gov -
# Messing with widget sizing in grids.
# 2016-08-10 leerw@ornl.gov -
# Added --skip-startup-session-check command-line arg.
# Turning off 3D widgets on config load.
# Using Environment3D.IsAvailable() as a test for enabling the
# 3D widgets.
# 2016-07-07 leerw@ornl.gov -
# Renaming "vanadium" to "fixed_detector".
# 2016-07-01 leerw@ornl.gov -
# Adding load/save session menu items.
# 2016-06-27 leerw@ornl.gov -
# Moved prompt for widget config.
# 2016-06-20 leerw@ornl.gov -
# Putting in hooks for reading/writing widget configurations.
# 2016-06-04 leerw@ornl.gov -
# Using new "ScalarPlot" replacement for TimePlot. -
# 2016-05-25 leerw@ornl.gov -
# Special "vanadium" dataset. Calling
# DataModel.CreateEmptyAxialValue()
# 2016-04-16 leerw@ornl.gov -
# Added "Select Scale Mode" pullright on the Edit menu.
# 2016-03-16 leerw@ornl.gov -
# Playing with grid sizing when adding widgets, might finally
# have a workable solution.
# Removed status bar since we're not using it and it eats
# vertical screen real estate.
# 2016-03-08 leerw@ornl.gov -
# Added Volume3DView, separators in the toolbar, and the CASL
# logo.
# 2016-03-07 leerw@ornl.gov -
# Added Slicer3DView.
# 2016-03-05 leerw@ornl.gov -
# 2016-03-05 leerw@ornl.gov -
# Replaced Core[XY]ZView with CoreAxial2DView.
# 2016-03-01 leerw@ornl.gov -
# Added Core[XY]ZView widget.
# 2016-02-20 leerw@ornl.gov -
# Added EVT_CHAR_HOOK to VeraViewFrame.
# 2016-01-22 leerw@ornl.gov -
# Added Edit->Copy menu item.
# 2015-12-29 leerw@ornl.gov -
# Added View menu with creation of Slicer3DFrame.
# 2015-12-07 leerw@ornl.gov -
# Back to original icons.
# 2015-11-24 leerw@ornl.gov -
# After change to GridSizerBean, checking for more than 16
# widget cells and prompting the user to confirm.
# 2015-11-12 leerw@ornl.gov -
# Adding menu to create a pseudo dataset.
# 2015-09-17 leerw@ornl.gov -
# Remove erroneous 'func' from the Time Plot toolbar item definition.
# Began addition of the "plot everything" function.
# 2015-08-25 leerw@ornl.gov -
# Replacing various axial plots with AllAxialPlot and specific
# "selected" datasets enabled.
# 2015-07-27 leerw@ornl.gov -
# Build 15 with fixes to dataset reference order.
# 2015-07-15 leerw@ornl.gov -
# Build 14.
# 2015-07-11 leerw@ornl.gov -
# New ChannelAssembly2DView.
# 2015-05-25 leerw@ornl.gov -
# New menu for the global time dataset.
# 2015-05-11 leerw@ornl.gov -
# New State.axialValue attribute.
# 2015-04-27 leerw@ornl.gov -
# New detector view and plot.
# Added type to TOOLBAR_ITEMS with enable/disable of toolbar
# buttons based on available datasets by type/category.
# 2015-04-13 leerw@ornl.gov -
# Added DataModel.Check() call in OpenFile(). Added call to
# frame _OnOpenFile() in OnEventLoopEnter().
# Doing OpenFile() as background task with _OpenFile{Begin,End}().
# 2015-04-11 leerw@ornl.gov -
# 2015-04-10 leerw@ornl.gov -
# Putting sliders on the frame.
# 2015-04-02 leerw@ornl.gov -
# No longer enforcing aspect ratio on resize.
# 2015-02-14 leerw@ornl.gov -
# Trying a grid editor.
# 2015-01-10 leerw@ornl.gov -
# 2015-01-08 leerw@ornl.gov -
# 2015-01-07 leerw@ornl.gov -
# 2015-01-05 leerw@ornl.gov -
# 2014-12-18 leerw@ornl.gov -
# 2014-12-08 leerw@ornl.gov -
# 2014-11-15 leerw@ornl.gov -
#------------------------------------------------------------------------
import argparse, logging, os, six, sys, threading, time, traceback
import pdb # set_trace()
try:
import wx
import wx.lib.agw.genericmessagedialog as GMD
import wx.lib.delayedresult as wxlibdr
#except ImportException:
except Exception:
raise ImportError( 'The wxPython module is required to run this program' )
try:
import matplotlib
matplotlib.use( 'WXAgg' )
except Exception:
raise ImportError( 'The matplotlib module is required for this component' )
#from bean.dataset_menu_item import *
#from bean.dataset_mgr import *
from bean.dataset_creator import *
from bean.dataset_diff_creator import *
from bean.excore_output_bean import *
from bean.filemgr_bean import *
from bean.grid_sizer_dialog import *
from bean.html_message_dialog import *
from bean.range_bean import *
from data.config import Config
from data.datamodel import *
from data.datamodel_mgr import *
from event.state import *
from view3d.env3d import *
from widget.animators import *
from widget.image_ops import *
from widget.widget_config import *
from widget.widgetcontainer import *
from widget.bean.animate_options_bean import *
from widget.bean.axial_slider import *
from widget.bean.dataset_menu import *
from widget.bean.exposure_slider import *
ID_REFIT_WINDOW = 1000
SCALE_MODES = \
{
'All State Points': 'all',
'Current State Point': 'state'
}
#TITLE = 'VERAView Version 1.1 Build 85'
TITLE = 'VERAView Version 2.4.0'
TOOLBAR_ITEMS = \
[
# {
# 'widget': 'Core 2D Plot',
# 'icon': 'Core2DView.1.32.png',
# 'iconDisabled': 'Core2DView.disabled.1.32.png',
# #'type': 'pin',
# 'type': '',
# #'func': lambda d: d.GetCore() is not None and d.GetCore().nass > 1
# 'func': lambda d: d.core is not None and \
# d.core.coreMap is not None and \
# d.core.coreMap.shape[ 0 ] > 1 and \
# d.core.coreMap.shape[ 1 ] > 1
# },
{
'widget': 'Core 2D View',
'icon': 'Core2DView.1.32.png',
'iconDisabled': 'Core2DView.disabled.1.32.png',
#'type': 'pin',
'type': '',
#'func': lambda d: d.GetCore() is not None and d.GetCore().nass > 1
'func': lambda d: d.core is not None and
d.core.coreMap is not None and
d.core.coreMap.shape[ 0 ] > 1 and
d.core.coreMap.shape[ 1 ] > 1 and
(d.HasDataSetType( 'channel' ) or d.HasDataSetType( 'pin' ) or
d.HasDataSetType( ':assembly' ) or
d.HasDataSetType( ':chan_radial' ) or
d.HasDataSetType( ':node' ) or
d.HasDataSetType( ':radial' ) or
d.HasDataSetType( ':radial_assembly' ) or
d.HasDataSetType( ':radial_node' ))
},
{
'widget': 'Core Axial 2D View',
'icon': 'CoreAxial2DView.1.32.png',
'iconDisabled': 'CoreAxial2DView.disabled.1.32.png',
#'type': 'pin',
'type': '',
#'func': lambda d: d.GetCore() is not None and d.GetCore().nax > 1
'func': lambda d: d.core is not None and
d.core.nax > 1 and
d.core.coreMap is not None and
d.core.coreMap.shape[ 0 ] > 0 and
d.core.coreMap.shape[ 1 ] > 0 and
(d.HasDataSetType( 'channel' ) or
d.HasDataSetType( 'pin' ) or
d.HasDataSetType( ':assembly' ) or
d.HasDataSetType( ':node' ))
},
{
'widget': 'Vessel Core 2D View',
'icon': 'VesselCore2DView.1.32.png',
'iconDisabled': 'VesselCore2DView.disabled.1.32.png',
'type': 'fluence',
'func': lambda d: d.core and d.core.fluenceMesh.IsValid()
},
{
'widget': 'Vessel Core Axial 2D View',
'icon': 'VesselCoreAxial2DView.1.32.png',
'iconDisabled': 'VesselCoreAxial2DView.disabled.1.32.png',
'type': 'fluence',
'func': lambda d:
d.core and d.core.fluenceMesh.IsValid() and d.core.fluenceMesh.nz > 1
},
{
'widget': 'Assembly 2D View',
'icon': 'Assembly2DView.1.32.png',
'iconDisabled': 'Assembly2DView.disabled.1.32.png',
#'type': 'pin'
'type': '',
'func': lambda d: d.core is not None and
d.core.npinx > 1 and d.core.npiny > 1 and
(d.HasDataSetType( 'channel' ) or
d.HasDataSetType( 'pin' ) or
d.HasDataSetType( ':chan_radial' ) or
d.HasDataSetType( ':radial' ))
},
{
'widget': 'Intrapin Edits Assembly 2D View',
'icon': 'IntraPinEditsAssembly2DView.1.32.png',
'iconDisabled': 'IntraPinEditsAssembly2DView.disabled.1.32.png',
'type': 'intrapin_edits',
'func': lambda d: d.HasDataSetType( 'intrapin_edits' )
},
{
'widget': 'Intrapin Edits Plot',
'icon': 'SubPin2DView.1.32.png',
'iconDisabled': 'SubPin2DView.disabled.1.32.png',
'type': 'intrapin_edits',
'func': lambda d: d.HasDataSetType( 'intrapin_edits' )
},
# {
# 'widget': 'Subpin 2D View',
# 'icon': 'SubPin2DView.1.32.png',
# 'iconDisabled': 'SubPin2DView.disabled.1.32.png',
# 'type': '',
# 'func': lambda d: d.HasDataSetType( 'subpin_r' ) or d.HasDataSetType( 'subpin_theta' )
# },
#x {
#x 'widget': 'Subpin Plot',
#x 'icon': 'SubPinPlot.32.png',
#x 'iconDisabled': 'SubPinPlot.disabled.32.png',
#x 'type': '',
#x 'func': lambda d: d.HasDataSetType( 'subpin_r' ) or d.HasDataSetType( 'subpin_theta' )
#x },
{
'widget': 'Subpin Length Plot',
'icon': 'SubPinLengthPlot.32.png',
'iconDisabled': 'SubPinLengthPlot.disabled.32.png',
'type': 'subpin_cc'
#'func': lambda d: d.HasDataSetType( 'subpin_cc' )
},
{ 'widget': 'separator' },
{
'widget': 'Detector 2D Multi View',
'icon': 'Detector2DView.1.32.png',
'iconDisabled': 'Detector2DView.disabled.1.32.png',
# 'type': 'detector'
'type': '',
'func': lambda d:
d.HasDataSetType( 'detector' ) or
d.HasDataSetType( 'fixed_detector' ) or
d.HasDataSetType( 'radial_detector' )
},
{ 'widget': 'separator' },
{
'widget': 'Volume Slicer 3D View',
'icon': 'Slicer3DView.1.32.png',
'iconDisabled': 'Slicer3DView.disabled.1.32.png',
'type': 'pin',
'func': lambda d: Environment3D.IsAvailable() and d.Is3DReady()
},
# {
# 'widget': 'Deprecated Volume 3D View',
# 'icon': 'Volume3DView-deprecated.1.32.png',
# 'iconDisabled': 'Volume3DView.disabled.1.32.png',
# 'type': 'pin',
# 'func': lambda d: Environment3D.IsAvailable() and d.Is3DReady()
# },
# { 'widget': 'separator' },
{
'widget': 'Volume 3D View',
'icon': 'Volume3DView.1.32.png',
'iconDisabled': 'Volume3DView.disabled.1.32.png',
'type': 'pin',
'func': lambda d: Environment3D.IsAvailable() and d.Is3DReady()
},
{ 'widget': 'separator' },
{
'widget': 'Axial Plots',
'icon': 'AllAxialPlot.32.png',
'iconDisabled': 'AllAxialPlot.disabled.32.png',
'type': '',
'func': lambda d: d.HasDataSetType( 'axials' )
#'func': lambda d: d.GetCore() is not None and d.GetCore().nax > 1
},
{
'widget': 'Time Plots',
'icon': 'TimePlot.32.png',
'iconDisabled': 'TimePlot.disabled.32.png',
'type': '',
'func': lambda d: len( d.GetTimeValues() ) > 1
},
{
'widget': 'Table View',
'icon': 'TableView.32.png',
'iconDisabled': 'TableView.disabled.32.png',
'type': '',
'func': lambda d: d.core is not None and d.core.coreMap is not None
},
{
'widget': 'Data Analysis View',
'icon': 'DataAnalysisView.1.32.png',
'iconDisabled': 'DataAnalysisView.1.disabled.32.png',
'type': '',
'func': lambda d: d.core is not None and d.core.coreMap is not None
}
]
WEIGHTS_MODES = \
{
'Use Weights to Show/Hide Pins/Channels': 'on',
'Show All Pins/Channels': 'off'
}
WIDGET_MAP = \
{
'Assembly 2D View': 'widget.assembly_view.Assembly2DView',
'Axial Plots': 'widget.axial_plot.AxialPlot',
'Core 2D Plot': 'widget.core_view_plot.Core2DPlot',
'Core 2D View': 'widget.core_view.Core2DView',
'Core Axial 2D View': 'widget.core_axial_view.CoreAxial2DView',
'Data Analysis View': 'widget.data_analysis_view.DataAnalysisView',
'Detector 2D Multi View': 'widget.detector_multi_view.Detector2DMultiView',
'Intrapin Edits Assembly 2D View': 'widget.intrapin_edits_assembly_view.IntraPinEditsAssembly2DView',
'Intrapin Edits Plot': 'widget.intrapin_edits_plot.IntraPinEditsPlot',
# 'Subpin 2D View': 'widget.subpin_view.SubPin2DView',
#x 'Subpin Plot': 'widget.subpin_plot.SubPinPlot',
'Subpin Length Plot': 'widget.subpin_len_plot.SubPinLengthPlot',
'Table View': 'widget.table_view.TableView',
'Time Plots': 'widget.time_plots.TimePlots',
'Vessel Core 2D View': 'widget.vessel_core_view.VesselCore2DView',
'Vessel Core Axial 2D View': 'widget.vessel_core_axial_view.VesselCoreAxial2DView',
# 'Deprecated Volume 3D View': 'view3d.volume_view_deprecated.Volume3DView',
'Volume 3D View': 'view3d.volume_view.Volume3DView',
'Volume Slicer 3D View': 'view3d.slicer_view.Slicer3DView'
}
#------------------------------------------------------------------------
# CLASS: VeraViewApp -
#------------------------------------------------------------------------
class VeraViewApp( wx.App ):
"""This will be the controller for now.
"""
# -- Object Methods
# --
#----------------------------------------------------------------------
# METHOD: VeraViewApp.__init__() -
#----------------------------------------------------------------------
def __init__( self, *args, **kwargs ):
#super( VeraViewApp, self ).__init__( *args, **kwargs )
super( VeraViewApp, self ).__init__( redirect = False )
#super( VeraViewApp, self ).__init__( redirect = True, filename = 'run.log' )
self.SetAppName( 'VERAView' )
self.busyCount = 0
self.busyLock = threading.RLock()
#self.data = None
#self.dataSetDefault = 'pin_powers'
self.filePaths = None
self.firstLoop = True
#self.frame = None
# -- Dict by index of { 'frame', 'n', 'title' }
self.frameRecs = {}
self.loadSession = False
self.logger = logging.getLogger( 'root' )
self.sessionPath = None
#self.skipSession = False
self.state = None
wx.ToolTip.Enable( True )
wx.ToolTip.SetAutoPop( 10000 )
wx.ToolTip.SetDelay( 500 )
wx.ToolTip.SetReshow( 100 )
#end __init__
#----------------------------------------------------------------------
# METHOD: VeraViewApp.AddFrame() -
#----------------------------------------------------------------------
def AddFrame( self, frame, update_menus_flag = True ):
"""Adds a new VeraViewFrame.
"""
if frame is not None:
# -- Resolve Title
# --
n = 1
while True:
if n not in self.frameRecs:
break
n += 1
#cur_title = frame.GetTitle()
#if not cur_title:
#cur_title = TITLE
#title = '%d: %s' % ( n, cur_title )
frame.SetFrameId( n )
frame.UpdateTitle()
self.frameRecs[ n ] = \
{ 'frame': frame, 'n': n, 'title': frame.GetTitle() }
if update_menus_flag and Config.CanDragNDrop():
self.UpdateWindowMenus( add_frame = frame )
#end if frame
#end AddFrame
#----------------------------------------------------------------------
# METHOD: VeraViewApp.DoBusyEventOp() -
#----------------------------------------------------------------------
def DoBusyEventOp( self, func, *args, **kwargs ):
"""Must be called on the UI thread. Note the arguments cannot contain
references to transient wxwidgets C++ objects, such as events, b/c they
cannot be copied and are invalid in a ``wx.CallLater()`` invocation.
Args:
func (callable): function to call
*args (list): positional arguments
**kwargs (dict): keyword arguments
"""
def do_later( func, *args, **kwargs ):
func( *args, **kwargs )
#for rec in six.itervalues( self.frameRecs ):
# rec.get( 'frame' ).ShowBusyIcon( False )
self.busyLock.acquire()
if self.busyCount == 1:
for rec in six.itervalues( self.frameRecs ):
rec.get( 'frame' ).ShowBusyIcon( False )
self.busyCount -= 1
self.busyLock.release()
#end do_later
#for rec in six.itervalues( self.frameRecs ):
# rec.get( 'frame' ).ShowBusyIcon( True )
self.busyLock.acquire()
if self.busyCount == 0:
for rec in six.itervalues( self.frameRecs ):
rec.get( 'frame' ).ShowBusyIcon( True )
self.busyCount += 1
self.busyLock.release()
wx.CallLater( 100, do_later, func, *args, **kwargs )
#end DoBusyEventOp
#----------------------------------------------------------------------
# METHOD: VeraViewApp._DoFirstLoop() -
#----------------------------------------------------------------------
def _DoFirstLoop( self, frame ):
"""Must be called on the UI thread.
"""
opened = False
session = WidgetConfig.ReadUserSession()
frame.SetConfig( session )
#wx.CallAfter( frame.SetConfig, session )
if self.sessionPath and os.path.exists( self.sessionPath ):
data_paths, session = frame._ResolveFile( self.sessionPath )
if not data_paths:
wx.MessageBox(
'Error reading session file: ' + self.sessionPath,
'Open File', wx.OK, None
)
else:
opened = True
frame.OpenFile( data_paths, session )
#wx.CallAfter( frame.OpenFile, data_paths, session )
elif self.filePaths:
paths = []
for f in self.filePaths:
if os.path.exists( f ):
paths.append( f )
if paths:
opened = True
frame.OpenFile( paths )
#wx.CallAfter( frame.OpenFile, paths )
elif session is not None and self.loadSession:
data_paths = session.GetDataModelPaths()
if data_paths and len( data_paths ) > 0:
found = True
for f in data_paths:
found |= os.path.exists( f )
if not found:
break
else:
found = False
if found:
# For some reason modal dialog don't work at this stage with Anaconda
opened = True
wx.CallAfter( frame.OpenFile, data_paths, session )
#end if-else
#end _DoFirstLoop
#----------------------------------------------------------------------
# METHOD: VeraViewApp.FindFrameByTitle() -
#----------------------------------------------------------------------
def FindFrameByTitle( self, title ):
"""Finds the specified frame
@return frame rec or None if not found
"""
match = None
title_n = 0
if title:
ndx = title.find( ':' )
if ndx > 0:
title_n = int( title[ 0 : ndx ] )
if title_n > 0:
for n, rec in self.frameRecs.iteritems():
#if rec[ 'title' ] == title:
if n == title_n:
match = rec
break
#end for n, rec
#end if frame
return match
#end FindFrameByTitle
#----------------------------------------------------------------------
# METHOD: VeraViewApp.GetFrameRecs() -
#----------------------------------------------------------------------
def GetFrameRecs( self ):
"""Removes a new VeraViewFrame.
@return frames dict
"""
return self.frameRecs
#end GetFrameRecs
#----------------------------------------------------------------------
# METHOD: VeraViewApp.MacHideApp() -
# These noworky
#----------------------------------------------------------------------
def MacHideApp( self ):
print >> sys.stderr, 'XXX MacHideHap'
if self.logger.isEnabledFor( logging.DEBUG ):
self.logger.debug( 'entered' )
pass
#end MacHideApp
#----------------------------------------------------------------------
# METHOD: VeraViewApp.MacReopenApp() -
# These noworky
#----------------------------------------------------------------------
def MacReopenApp( self ):
print >> sys.stderr, 'XXX MacReopenApp'
if self.logger.isEnabledFor( logging.DEBUG ):
self.logger.debug( 'entered' )
#self.BringWindowToFront()
if len( self.frameRecs ) > 0:
rec = six.next( six.itervalues( self.frameRecs ) )
rec[ 'frame' ].Raise()
#end MacReopenApp
#----------------------------------------------------------------------
# METHOD: VeraViewApp.OnEventLoopEnter() -
#----------------------------------------------------------------------
def OnEventLoopEnter( self, *args, **kwargs ):
"""It looks like this is called only once, so the firstLoop flag is
unnecessary.
"""
#DEBUG,INFO,WARNING,ERROR,CRITICAL
if self.logger.isEnabledFor( logging.DEBUG ):
self.logger.debug( 'entered' )
#original frame_rec = self.frameRecs.get( 1 )
n = 1
frame_rec = None
while frame_rec is None and n < 32768:
frame_rec = self.frameRecs.get( n )
n += 1
frame = frame_rec.get( 'frame' ) if frame_rec else None
#if self.frame is None:
if frame is None:
self.logger.critical( '* No frame to show *' )
self.ExitMainLoop()
elif self.firstLoop:
self.firstLoop = False
wx.CallAfter( self._DoFirstLoop, frame )
#end elif self.firstLoop:
#end OnEventLoopEnter
#----------------------------------------------------------------------
# METHOD: VeraViewApp.OnInit() -
#----------------------------------------------------------------------
# def OnInit( self ):
# pdb.set_trace()
# super( VeraViewApp, self ).OnInit()
# #DEBUG,INFO,WARNING,ERROR,CRITICAL
# if self.logger.isEnabledFor( logging.DEBUG ):
# self.logger.debug( 'entered' )
#
# frame_rec = self.frameRecs.get( 1 )
# frame = frame_rec.get( 'frame' ) if frame_rec else None
# #if self.frame is None:
# if frame is None:
# self.logger.critical( '* No frame to show *' )
# status = False
# else:
# status = True
# wx.CallAfter( self._DoFirstLoop, frame )
#
# return status
# #end OnInit
#----------------------------------------------------------------------
# METHOD: VeraViewApp.RemoveFrame() -
#----------------------------------------------------------------------
def RemoveFrame( self, frame, update_menus_flag = True ):
"""Removes a new VeraViewFrame.
@param frame wx.Frame instance
"""
rec = self.FindFrameByTitle( frame.GetTitle() )
if rec:
n = rec.get( 'n' )
if n in self.frameRecs:
frame = rec.get( 'frame' )
del self.frameRecs[ n ]
if update_menus_flag and Config.CanDragNDrop():
self.UpdateWindowMenus( remove_frame = frame )
#end if n in self.frameRecs
#end if rec
#end RemoveFrame
#----------------------------------------------------------------------
# METHOD: VeraViewApp.UpdateAllFrames() -
#----------------------------------------------------------------------
def UpdateAllFrames( self, *skip_frames ):
"""Must be called on the UI thread.
@param skip_frames frames to skip
"""
model_names = self.state.dataModelMgr.GetDataModelNames()
file_path = sorted( model_names )[ 0 ] if model_names else ''
for rec in six.itervalues( self.frameRecs ):
frame = rec.get( 'frame' )
if frame and (skip_frames is None or frame not in skip_frames):
frame.UpdateFrame( file_path = file_path )
#end for rec
#end UpdateAllFrames
#----------------------------------------------------------------------
# METHOD: VeraViewApp.UpdateWindowMenus() -
#----------------------------------------------------------------------
def UpdateWindowMenus( self, **kwargs ):
"""Assume this will only be called if the 'Window' menubar item has
been created.
"""
titles = []
frames = []
for frame_rec in self.frameRecs.values():
frame = frame_rec.get( 'frame' )
if frame is not None:
frames.append( frame )
titles.append( frame.GetTitle() )
#end for frame_rec
# -- Process menu for each frame
# --
for frame in frames:
# -- Find items to remove
# --
removes = []
for i in xrange( frame.windowMenu.GetMenuItemCount() ):
item = frame.windowMenu.FindItemByPosition( i )
if item:
label = item.GetItemLabelText()
if label and label != 'Tile Windows':
removes.append( item )
#end for i
# -- Remove items
# --
for item in removes:
frame.windowMenu.DestroyItem( item )
# -- Add new items
# --
for title in titles:
item = wx.MenuItem( frame.windowMenu, wx.ID_ANY, title )
frame.Bind( wx.EVT_MENU, frame._OnWindowMenuItem, item )
frame.windowMenu.AppendItem( item )
#frame.windowMenu.UpdateUI()
#end for title
#end for frame
#end UpdateWindowMenus
#----------------------------------------------------------------------
# METHOD: VeraViewApp.main() -
#----------------------------------------------------------------------
@staticmethod
def main():
try:
parser = argparse.ArgumentParser()
# parser.add_argument(
# '--assembly',
# default = 0,
# type = int,
# help = 'optional 1-based index of assembly to display'
# )
# parser.add_argument(
# '-a', '--axial',
# default = 0,
# type = int,
# help = 'optional 1-based index of core axial to display'
# )
# parser.add_argument(
# '-d', '--dataset',
# help = 'default dataset name, defaulting to "pin_powers"'
# )
parser.add_argument(
#'-f', '--file-paths',
'file_path',
help = 'path to HDF5 data file',
nargs = '*'
)
parser.add_argument(
'--debug',
action = 'store_true',
help = 'run in debug mode'
)
parser.add_argument(
'--load-session',
action = 'store_true',
help = 'load the session on startup, overriding any file paths'
)
parser.add_argument(
'--session',
help = 'path to session file to load'
)
parser.add_argument(
'--trace',
action = 'store_true',
help = 'trace call calls to stderr'
)
# parser.add_argument(
# '--skip-startup-session-check',
# action = 'store_true',
# help = 'skip the check for a session on startup when no file path is specified'
# )
args = parser.parse_args()
if args.trace:
sys.settrace( VeraViewApp.trace )
#Config.SetRootDir( os.path.dirname( os.path.abspath( __file__ ) ) )
root_dir = os.path.dirname( os.path.abspath( __file__ ) )
if not os.path.isdir( os.path.join( root_dir, 'res' ) ):
root_dir = os.path.dirname( root_dir )
Config.SetRootDir( root_dir )
# -- Check existence of files
# --
files_not_found = [ f for f in args.file_path if not os.path.exists( f ) ]
for f in files_not_found:
print >> sys.stderr, '[VERAView] File not found:', f
files_found = [ f for f in args.file_path if f not in files_not_found ]
# -- Create State
# --
state = State()
# -- Create App
# --
#app = VeraViewApp( redirect = False ) # redirect = False
app = VeraViewApp()
app.debug = args.debug
app.filePaths = files_found
app.loadSession = args.load_session
app.sessionPath = args.session
#app.skipSession = args.skip_startup_session_check
app.state = state
#app.frame = VeraViewFrame( app, state )
frame = VeraViewFrame( app, state )
app.AddFrame( frame )
# -- If MDI on Mac, don't show
#app.frame.Show()
frame.Show()
app.MainLoop()
except Exception, ex:
msg = str( ex )
print >> sys.stderr, msg
et, ev, tb = sys.exc_info()
while tb:
msg += \
os.linesep + 'File=' + str( tb.tb_frame.f_code ) + \
', Line=' + str( traceback.tb_lineno( tb ) )
print >> sys.stderr, \
'File=' + str( tb.tb_frame.f_code ) + \
', Line=' + str( traceback.tb_lineno( tb ) )
tb = tb.tb_next
#end while
logging.error( msg )
#end main
#----------------------------------------------------------------------
# METHOD: VeraViewApp.trace() -
#----------------------------------------------------------------------
@staticmethod
def trace( frame, event, arg ):
six.print_(
'{0}, {1}:{2:d}'.
format( event, frame.f_code.co_filename, frame.f_lineno ),
file = sys.stderr
)
#end trace
#end VeraViewApp
#------------------------------------------------------------------------
# CLASS: VeraViewFrame -
#------------------------------------------------------------------------
#class VeraViewFrame( wx.MDIParentFrame ):
class VeraViewFrame( wx.Frame ):
"""Top level viewer window.
"""
# -- Object Methods
# --
#----------------------------------------------------------------------
# METHOD: VeraViewFrame.__init__() -
#----------------------------------------------------------------------
def __init__( self, app, state, file_path = '' ):
super( VeraViewFrame, self ).__init__( None, -1 )
self.app = app
# self.axialPlotTypes = set()
self.config = None
# self.dataSetDefault = ds_default
self.eventLocks = State.CreateLocks()
self.filepath = file_path