From 20319892a2a3de37f9e53b08ef32fc7e988cdd4c Mon Sep 17 00:00:00 2001 From: etienne Date: Fri, 19 Aug 2005 13:18:21 +0000 Subject: Possibilité d'explorer une arborescence. --- ivybanner | 274 ++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 168 insertions(+), 106 deletions(-) diff --git a/ivybanner b/ivybanner index 2254db5..47115f8 100644 --- a/ivybanner +++ b/ivybanner @@ -14,6 +14,7 @@ use strict; use Tk; use Getopt::Long; +use File::Basename; use vars qw(%opt); # where you may find image files use lib "/usr/share/ivybanner"; @@ -47,6 +48,7 @@ my @fontspec17 = (-font => my $darkbg = '#1E161B'; my $bg = '#5C5655'; my $hlbg = '#7CC452'; +my $hlbg2 = 'green'; my $fg = '#FCFAFC'; my $selcolor = 'yellow'; @@ -59,6 +61,8 @@ my $view_button; my $launch_button; my %apps; my $currentlogfile; +my @subdirbtn; +my $level = 1; # parse options #------------------------ @@ -109,6 +113,7 @@ if ($opt{smallsize}) '-adobe-helvetica-medium-r-normal--11-80-100-100-p-60-iso10646-1'); } + # test directories #---------------------------- @@ -188,6 +193,8 @@ my @buttonattr = (-width => 8*$coef, -height => 3, -background => $bg, -foreground => $fg); + + $fm1->Label(-image => $logo_bg)->place(-x => 0, -y => 0); if ($opt{smallsize}){ @@ -225,7 +232,9 @@ MainLoop; sub execute { - my ($path, $demo, $port, $domain) = @_; + + my ($demo, $port, $domain) = @_; + my $bdemo = basename($demo); unless (defined $demo) { $mw->bell; return; @@ -241,10 +250,10 @@ sub execute { print "===========================================================\n"; print "Ivy demos launched at ".localtime()."\n"; - print "Selected config is $demo on bus $domain:$port\n"; + print "Selected config is $bdemo on bus $domain:$port\n"; print "Traces are in $tmp_file_prefix$now_string\n"; - print "Run $command $path/$demo\n"; - system ("$command $path/$demo 2>&1 | tee $tmp_file_prefix$now_string"); + print "Run $command $demo\n"; + system ("$command $demo 2>&1 | tee $tmp_file_prefix$now_string"); $mw->deiconify; $mw->raise; @@ -252,7 +261,10 @@ sub execute { sub demosframe { - my ($title, $path) = @_; + + my $title = shift; + my $path = shift; + my @packinfo = $fm1->packInfo; $fm1->packForget(); $fm2 = $mw->Frame(-background => $darkbg)->pack(-expand => 1, -fill => 'both'); @@ -374,6 +386,89 @@ sub demosframe { -background => $fg)}, -text => "other\nport")->place(@placeattr); + &subdirframe($fm2, $path, $x, $y, $dx, $dy); + + # control buttons bottom frame + #-------------------------------------------------- + $y = 680*$coef; + my @labelattr = (-width => 6, -height => 2, + -borderwidth => 1, + @fontspec24, + -relief => 'flat', + -background => $darkbg, + -foreground => $fg); + + my @buttonattr = (-width => 6, -height => 2, + -borderwidth => 1, + @fontspec24, + -relief => 'flat', + -highlightthickness => 3*$coef*$coef, + -highlightbackground => $hlbg, + -activebackground => $bg, + -activeforeground => $fg, + -background => $bg, + -foreground => $fg); + $fm2->Frame(-background => $darkbg, -relief => 'groove', + -borderwidth => 5*$coef, + -width => $width+20*$coef, + -height => $height)->place(-x => -10*$coef, -y => $y - 30*$coef); + $fm2->Button(@buttonattr, + -text => "top", + -command => sub { + $level = 1; + &off(); + $fm2->destroy; + $fm1->pack(@packinfo); + })->place(-x => 70*$coef, -y => $y); +# $fm2->Button(@buttonattr, +# -command => sub {}, +# -text => "kill")->place(-x => 290, -y => $y); + $fm2->Label(@labelattr, + -text => $title)->place(-x => 290*$coef, -y => $y); + $fm2->Button(@buttonattr, + -command => \&viewLog, + -text => "view\nlog")->place(-x => 510*$coef, -y => $y); + $view_button = + $fm2->Button(@buttonattr, + -state => 'disabled', + -command => sub {&viewConfig($selected_demo)}, + -text => "view\nconfig")->place(-x => 670*$coef, -y => $y); + $launch_button = + $fm2->Button(@buttonattr, + -state => 'disabled', + -command => sub { + my $p = $port; + my $d; + if ($port eq 'own') { + $p = $en_ownport->get(); + } + $d .= "127, " if $dom_local; + $d .= $default_domain."," if $dom_default; + $d .= $en_ownnet->get() if $dom_own; + $d =~ s/,\s*$// if $d; + $d =~ s/\s+// if $d; + #print "port=$p domain=$d\n"; + &execute($selected_demo, $p, $d); + }, + -text => "launch")->place(-x => 830*$coef, -y => $y); + +} # end demosframe + + +sub subdirframe { + + my $fm2 = shift; + my $path = shift; + my $x = shift; + my $y = shift; + my $dx = shift; + my $dy = shift; + + for (@subdirbtn) { + $_->destroy if Tk::Exists($_); + } + @subdirbtn = (); + # demos frame #-------------------------------------------------- my @bbox = (40*$coef, 160*$coef, $width-40*$coef, 640*$coef); @@ -383,8 +478,8 @@ sub demosframe { my $max_columns = int(($bbox[2]-$bbox[0])/$fmw); my $max_rows = int(($bbox[3]-$bbox[1])/$fmh); my $maxnb = $max_columns*$max_rows; - @placeattr = (-x => 10*$coef, -y => 5*$coef); - @frameattr = (-relief => 'flat', + my @placeattr = (-x => 10*$coef, -y => 5*$coef); + my @frameattr = (-relief => 'flat', -highlightthickness => 3*$coef*$coef, -highlightbackground => $hlbg, -height => $fmh, @@ -415,18 +510,31 @@ sub demosframe { my $c = 1; my $r = 1; opendir PREFIX, $path; - my @file_liste = grep /:/, readdir PREFIX; + #my @file_liste = grep /:/, readdir PREFIX; + my @file_liste = readdir PREFIX; closedir PREFIX; my @cleanfilelist = (); + push(@cleanfilelist, ['..', 'd']) if $level > 1; @file_liste = sort { (stat("$path/$a"))[10] <=> (stat("$path/$b"))[10] } @file_liste; foreach my $file (@file_liste) { - print "file=$file mtime=", (stat("$path/$file"))[10] ,"\n"; - next unless (-f $path."/".$file); - next if ($file =~ /\~$/); - next if ($file =~ /^\./); - next if ($file =~ /\%$/); - push(@cleanfilelist, $file); + my $type; + if (-f $path."/".$file) { + print "$file is a file\n"; + $type = 'f'; + } elsif (-d $path."/".$file) { + print "$file is a directory\n"; + $type = 'd'; + } + #print "file=$file mtime=", (stat("$path/$file"))[10] ,"\n"; + next unless defined $type; + next if ($type eq 'f' and $file !~ /:/); + next if ($type eq 'f' and $file =~ /\~$/); + next if ($type eq 'f' and $file =~ /^\./); + next if ($type eq 'f' and $file =~ /\%$/); + next if ($type eq 'd' and $file =~ /^\./); + push(@cleanfilelist, [$file, $type]); } + print "\n"; my $demosnb = @cleanfilelist; if ($demosnb > $maxnb) { splice(@cleanfilelist, $maxnb-1); @@ -444,7 +552,8 @@ sub demosframe { $y = $bbox[1] + $dy; #print "maxc=$maxc x=$x y=$y dx=$dx dy=$dy\n"; my ($xi, $yi); - for my $file (@cleanfilelist) { + for my $fileref (@cleanfilelist) { + my ($file, $type) = @$fileref; my @fields = split(/:/, $file); my ($category, $extinfo); if (@fields == 1) { @@ -461,16 +570,27 @@ sub demosframe { $extinfo = substr($extinfo, 0, $butw)."\n".substr($extinfo, $butw); } ($xi, $yi) = ($x + ($c-1)*($dx+$fmw), $y + ($r-1)*($dy+$fmh)); - my $b = $fm2->Button(@buttonattr, - -text => "$category\n$extinfo")->place(-x => $xi, -y => $yi); - $b->configure(-command => sub { - if (&ison($b)) { - &off($b); - } else { - &on($b, $file); - } - }); - + my $b = $fm2->Button(@buttonattr)->place(-x => $xi, -y => $yi); + if ($type eq 'f') { + $b->configure(-text => "$category\n$extinfo", + -command => sub { + &off(); + &on($b, $path."/".$file); + }); + } else { + $b->configure(-bg => 'gray20', + -text => ($file eq '..') ? "Up" : $file, + -command => sub { + &off; + if ($file eq '..') { + $level--; + } else { + $level++; + } + &subdirframe($fm2, $path."/".$file, $x, $y, $dx, $dy); + }); + } + push(@subdirbtn, $b); if ($c >= $maxc) { $c=1; $r++; @@ -485,78 +605,18 @@ sub demosframe { -state => "disabled", -value => 0, -text => "and many\nmore...")->place(@placeattr); + push(@subdirbtn, $fm_demo); } - - # control buttons bottom frame - #-------------------------------------------------- - $y = 680*$coef; - my @labelattr = (-width => 6, -height => 2, - -borderwidth => 1, - @fontspec24, - -relief => 'flat', - -background => $darkbg, - -foreground => $fg); - - my @buttonattr = (-width => 6, -height => 2, - -borderwidth => 1, - @fontspec24, - -relief => 'flat', - -highlightthickness => 3*$coef*$coef, - -highlightbackground => $hlbg, - -activebackground => $bg, - -activeforeground => $fg, - -background => $bg, - -foreground => $fg); - $fm2->Frame(-background => $darkbg, -relief => 'groove', - -borderwidth => 5*$coef, - -width => $width+20*$coef, - -height => $height)->place(-x => -10*$coef, -y => $y - 30*$coef); - $fm2->Button(@buttonattr, - -text => "back", - -command => sub { - $selected_demo = undef; - $selected_button = undef; - $fm2->destroy; - $fm1->pack(@packinfo); - })->place(-x => 70*$coef, -y => $y); -# $fm2->Button(@buttonattr, -# -command => sub {}, -# -text => "kill")->place(-x => 290, -y => $y); - $fm2->Label(@labelattr, - -text => $title)->place(-x => 290*$coef, -y => $y); - $fm2->Button(@buttonattr, - -command => \&viewLog, - -text => "view\nlog")->place(-x => 510*$coef, -y => $y); - $view_button = - $fm2->Button(@buttonattr, - -state => 'disabled', - -command => sub {&viewConfig($path, $selected_demo)}, - -text => "view\nconfig")->place(-x => 670*$coef, -y => $y); - $launch_button = - $fm2->Button(@buttonattr, - -state => 'disabled', - -command => sub { - my $p = $port; - my $d; - if ($port eq 'own') { - $p = $en_ownport->get(); - } - $d .= "127, " if $dom_local; - $d .= $default_domain."," if $dom_default; - $d .= $en_ownnet->get() if $dom_own; - $d =~ s/,\s*$// if $d; - $d =~ s/\s+// if $d; - #print "port=$p domain=$d\n"; - &execute($path, $selected_demo, $p, $d); - }, - -text => "launch")->place(-x => 830*$coef, -y => $y); - -} # end demosframe + +} # end subdirframe sub viewConfig { - my ($dir, $file) = @_; + + my ($file) = @_; + my $dir = dirname($file); + my $bfile = basename($file); unless ($file) { $mw->bell; return; @@ -586,7 +646,7 @@ sub viewConfig { $t->place(-x => 50*$coef*$coef*$coef, -y => 120*$coef); $t->tagConfigure('comment', -foreground => 'gray70'); - open(C_FILE, "cpp -traditional $dir/$file|"); + open(C_FILE, "cpp -traditional $file|"); while () { next if /^\s*$/; if (/^\s*\#/) { @@ -610,7 +670,7 @@ sub viewConfig { -width => 8, -activebackground => $bg, -activeforeground => $fg); - my $text1 = "content of $file"; + my $text1 = "content of $bfile"; my $text2 = "in $dir"; my $len1 = length($text1); my $len2 = length($text2); @@ -626,10 +686,12 @@ sub viewConfig { $fm2->pack(@packinfo); })->place(-x => 70*$coef, -y => 680*$coef); + } # end viewConfig sub viewLog { + my $file; my $dir; my @packinfo = $fm2->packInfo; @@ -715,6 +777,7 @@ sub viewLog { sub selectappname { + my $w = shift; my $tl = $mw->Toplevel(-background => $darkbg); $tl->title('messages selection'); @@ -784,6 +847,7 @@ sub selectappname { sub readlog { + # il est plus rapide de recréer un widget Text que de le vider de son # contenu et le remettre à jour !! my ($file, $date, $l) = @_; @@ -844,7 +908,9 @@ sub readlog { } # end readlog + sub readpartiallog { + my ($selapp) = @_; $tlog2->destroy if Tk::Exists($tlog2); $fm3->update; @@ -897,16 +963,10 @@ sub readpartiallog { } # end readpartiallog -sub ison { - my $b = shift; - return 1 if $selected_button eq $b; - -} # end ison - - sub on { + my ($b, $file) = @_; - &off($selected_button) if defined $selected_button; + &off(); $selected_button = $b; $selected_demo = $file; $b->configure(-foreground => $selcolor, -highlightbackground => $selcolor, @@ -918,9 +978,10 @@ sub on { sub off { - my $b = shift; - $b->configure(-foreground => $fg, -highlightbackground => $hlbg, - -activeforeground => $fg); + + return unless defined $selected_button and Tk::Exists($selected_button); + $selected_button->configure(-foreground => $fg, -highlightbackground => $hlbg, + -activeforeground => $fg); $view_button->configure(-state => 'disabled'); $launch_button->configure(-state => 'disabled'); $selected_demo = undef; @@ -930,6 +991,7 @@ sub off { sub usage { + print "Usage : ivybanner [-help] [-nocursor] [-override] [-conf configfile]\n"; print " [-dir fugueconfdir] [-testdir testsdir]\n"; print "\n"; @@ -1000,7 +1062,7 @@ To be detected by ivybanner, the files placed in the demos or tests directory m [string0:]string1:string2 -The label of ivybanner demos buttons will be contained string1 and string2. +The label of ivybanner demos buttons will contain string1 and string2. =head1 FILE FORMAT -- cgit v1.1