Debian Codegraph @

tkviewtest

raw
1 #!/usr/bin/perl
2
3 # Demo script using PDL::IO::HDF5 and Tk to show an HDF5 file structure
4 #
5
6
7
8 use Tk;
9 use PDL::IO::HDF5::tkview;
10 use PDL::IO::HDF5;
11 use Tk::Balloon;
12
13
14 my $maxElements = 50; # Largest Array (in number of elements) that we
15 # will try to show in a popup balloon
16
17 my $filename = shift @ARGV || 'varlen.hdf5';
18
19 my $mw = MainWindow->new;
20
21
22 my $b = $mw->Balloon;
23
24 my $h5 = new PDL::IO::HDF5($filename); # open HDF5 file object
25
26 my $tkview = new PDL::IO::HDF5::tkview( $mw, $h5);
27
28
29 my $tree = $tkview->{hl};
30 my $lastItem = '';
31 my $mouseItem;
32 my ($pointerX,$pointerY);
33 my @BBox = (0,0,0,0);
34 $b->attach($tree,
35 -balloonposition => 'mouse',
36 -postcommand => sub {
37
38 #print "Box for $item is ".join(", ",@BBox)."\n";
39 #print "Box for $mouseItem is ".join(", ",@BBox)."\n";
40 #print "y = $pointerY\n";
41 if( ($pointerY >= $BBox[1] ) && ($pointerY <= $BBox[3]) && # Popup balloon if withing bounding box
42 $mouseItem =~ /$;_Dset(.+)$/ ){ # and a dataset item
43 my $datasetName = $1;
44 my $text = $tree->entrycget($mouseItem,'-text');
45 my $elements = 1;
46 if( $text =~ /\: Dims (.+)$/ ){
47 my @dims = split(',',$1);
48 my $message;
49 foreach (@dims){
50 $elements *= $_;
51 }
52 }
53 if( $elements > $maxElements){
54 $message = "$elements Elements: Too Big To Display";
55 }
56 else{
57 my $group = $tree->entrycget($mouseItem,'-data');
58 my $PDL = $group->dataset($datasetName)->get;
59 $message = "$PDL";
60 }
61 $b->{"clients"}{$tree}{-balloonmsg} = $message;
62 return 1;
63 }
64
65 0;
66 },
67 -motioncommand => sub {
68 # my $e = $tree->XEvent;
69 # print "xevent is a ".ref($e)."\n";
70
71 ($pointerX,$pointerY) = $tree->pointerxy;
72 $pointerX -= $tree->rootx;
73 $pointerY -= $tree->rooty;
74 $mouseItem = $tree->nearest($pointerY);
75 # print "MouseItem = '$mouseItem'\n";
76 my $infoBBox = $tree->infoBbox($mouseItem);
77 # print "infoBBox = '$infoBBox'\n";
78 return 1 unless defined($infoBBox);
79
80 if( ref($infoBBox)){ # Handle the different ways that
81 # tk does the bounding box for 800.015 and 800.018, etc
82 @BBox = @$infoBBox;
83 }
84 else{
85 @BBox = split(' ', $infoBBox);
86 }
87 # print "Bbox = ".join(", ",@BBox)."\n";
88 # print "lastItem = '$lastItem', mouseItem = '$mouseItem'\n";
89 if( ( $lastItem eq $mouseItem ) &&
90 ($pointerY >= $BBox[1] ) && ($pointerY <= $BBox[3]) ){
91 # Same item, and withing it's bounding box don't cancel the Balloon
92 0;
93 }
94 else{
95 # New item - cancel it so a new balloon will
96 # be posted
97 $lastItem = $mouseItem;
98 1;
99
100 }
101
102 }
103
104 );
105
106
107 MainLoop;
108