my $windowtitle="Debugger"; my @items; #use vars qw($sys); my (%sys); my ($x, $h, $i, $enableAlarm, $file, $itemsrun, $item, $We, $x2h, %debugging, ); my ($W, $TB, @tbcode, $Timer, $ItemList, $LinkList, $AlarmList, $RichEdit, $wTV, $stop, $Act, $tick); my (%GUI, $GUI, $sys, @items); my $BS_GROUPBOX = 7; use strict; use Win32::GUI; use Cwd; unshift @INC,"."; use SnatchUtil; use SnatchGUI; my $Fixedsys = new Win32::GUI::Font( #-name => "Terminal", -name => "Fixedsys", -height => 8, -weight => 400, ); my $Courier = new Win32::GUI::Font( -name => "Courier New", -height => 14, -weight => 550, ); my $Announce = new Win32::GUI::Font( -name => "Arial", -height => 14, -weight => 550, ); # -bold => 1, # -underline => 1, $W = new Win32::GUI::Window( -title => $windowtitle, -left => 100, -top => 10, -width => 600, -height => 160, -name => "Debugger", -font => $Announce, ); my $row1=5; my $row2=50; my %Bands =( topBar => { top => 0, left => 0, height => 55, width => $W->ScaleWidth-10, # width => 410, }, listboxes => { top => 55, left => 0, height => 90, width => 100, spacing => 20, nextbox => 0, nextvbox => 0, vheight => 16, vspacing => 2, }, ); ##&####### begin band topBar ########## $TB = $W->AddToolbar( -left => $Bands{topBar}{left}, -top => $Bands{topBar}{top}, -width => $Bands{topBar}{width}, -height => $Bands{topBar}{height}, -name => "Toolbar", -font => $Announce, -style => 1022, -nodivider => 0, #donesn't do anything -flat => 0, #donesn't do anything ); my $B = new Win32::GUI::Bitmap("tools3.bmp"); $TB->SetBitmapSize(32, 32); $TB->AddBitmap($B, 3); @tbcode; my $i=1; $tbcode[$i]{name} = "getFile"; $tbcode[$i]{code} = '$_=&getFile;'; $TB->AddString("getFile"); $i++; $tbcode[$i]{name} = "File"; $tbcode[$i]{code} = '$_=File();'; $TB->AddString("File"); $i++; $tbcode[$i]{name} = "Next"; $tbcode[$i]{code} = '$_=&Next'; $TB->AddString("Next"); $i++; $tbcode[$i]{name} = "TreeV"; $tbcode[$i]{code} = '$_=&wTV_Activate;'; $TB->AddString("TreeV"); $i++; $tbcode[$i]{name} = "runAlarms"; $tbcode[$i]{code} = '$stop=0; $enableAlarm=1'; $TB->AddString("Alarms"); $i++; $tbcode[$i]{name} = "Run"; $tbcode[$i]{code} = '$_=Run();'; $TB->AddString("Run"); $i++; $tbcode[$i]{name} = "Stop"; $tbcode[$i]{code} = '$_=Stop();'; $TB->AddString("Stop"); $i++; $tbcode[$i]{name} = "Reset"; $tbcode[$i]{code} = '$_=Reset();'; $TB->AddString("Reset"); $i++; $TB->AddButtons( 8, 0, 1, 4, 0, 0, 1, 2, 4, 0, 1, 2, 3, 4, 0, 2, 3, 4, 4, 0, 3, 4, 5, 4, 0, 4, 5, 6, 4, 0, 5, 6, 7, 4, 0, 6, 7, 8, 4, 0, 7, ); $TB->Show(); ########################## my $row2=$TB->Height(); $LinkList = $W->AddListbox( -name => "LinkList", -style => WS_VSCROLL |WS_CHILD | WS_VISIBLE | 1, -left => $Bands{listboxes}{left}, -top => $Bands{listboxes}{top}, -width => $Bands{listboxes}{width}, -height => $Bands{listboxes}{height}, -checkboxes => 1, -foreground => [5, 5, 5], -background => 16316640, ); $Bands{listboxes}{nextbox}= $Bands{listboxes}{left} +$Bands{listboxes}{width} +$Bands{listboxes}{spacing}; sub LinkList_Click { $file=$LinkList->GetString($LinkList->SelectedItem()); print STDERR $file," FILE\n"; &parseit; } $ItemList = $W->AddListbox( -name => "ItemList", -style => WS_VSCROLL |WS_CHILD | WS_VISIBLE | 1, -font => $Courier, -left => $Bands{listboxes}{nextbox}, -top => $Bands{listboxes}{top}, -background => 16316640, -width => $Bands{listboxes}{width}, -height => $Bands{listboxes}{height}, ) or die("new Listbox"); $Bands{listboxes}{nextbox}= $Bands{listboxes}{nextbox} +$Bands{listboxes}{width} +$Bands{listboxes}{spacing}; sub ItemList_DblClick { my $item=$LinkList->GetString($LinkList->SelectedItem()); &Next; print STDERR "ITEM>$item Double Click\n" if $debugging{'gui'}; } sub ItemList_Click { $item=$ItemList->GetString($ItemList->SelectedItem()); foreach (@items) { my %h=%$_ if ref($_) eq 'HASH'; if ($h{'name'} eq $item) { $W->Action->Text($h{'name'}); $W->RichEdit->Text($h{'sub'}); $RichEdit->Text($h{'sub'}); guiTitle "$sys{'file'} $item"; print STDERR $h{'name'}," $item FOUND\n"; last; } } print STDERR "ITEM>$item Click\n" if $debugging{'gui'}; print STDERR "ITEM>$item Click\n"; } sub ItemList_Changed { $item=$ItemList->GetString($ItemList->SelectedItem()); $W->RichEdit->Text($item); } $W->AddButton( -name => "butClose", -left => $W->ScaleWidth-5, -top => $W->ScaleHeight-30, -width => 50, -text => "Close", -font => $Announce, ); sub MakeVButton { my ($W, $band, %h)= @_; return if not $band; my $top=$Bands{$band}{nextvbox}?$Bands{$band}{nextvbox}:$Bands{$band}{top}; $h{'-height'}=$Bands{listboxes}{vheight} unless $h{'-vheight'}; $h{'-left'}= $Bands{listboxes}{nextbox}; $h{'-width'}= $Bands{listboxes}{with} unless $h{'-width'}; $h{'-top'}=$top; for my $var ( keys %h ) { # print "$var $h{$var}\n "; } my $b=$W->AddButton(%h); die "PROBLEM with $h\n;" if not $b; return if not $band; my $name=$b->{'name'}; $Bands{$band}{nextvbox}= $top +$Bands{$band}{vheight} +$Bands{$band}{vspacing}; $b; } $Bands{listboxes}{width}=50; my $butClear=MakeVButton($W,'listboxes',( -name => "butClear", -text => "Clear", ) ); sub butClear_Click { $W->RichEdit->Text(''); } my $butStop=MakeVButton($W,'listboxes',( -name => "butStop", -text => "Stop", ) ); sub butStop_Click { &Stop; } sub Stop { $stop="STOP"; $W->Action->Text($stop); print STDERR "$stop\n"; } my $butEval=MakeVButton($W,'listboxes',( -name => "butEval", -text => "eval", -font => $Announce, ) ); sub butEval_Click { my $s=$W->RichEdit->Text(); print STDERR eval $s; } sub wTV_Activate { my $s; if ($wTV) { $wTV->Show(); print STDERR "TV>$wTV Show\n"; } else { print STDERR "TV>Start\n"; { local $/; if (not open CONFIG,"wTV.pl") { print STDERR "Cannot open $file $!\n"; return 0; } $s= ; close CONFIG; } my $r=eval $s; } GUI::Update($GUI{'guiW'}); } my $butTest=MakeVButton($W,'listboxes',( -name => "butTest", -text => "Test", -font => $Announce, ) ); sub butTest_Click { my $t=$W->RichEdit->Text(); $t=sxml2html($t); $W->RichEdit->Text($t) } ##&##################### buttons 1 #### sub showbands { my $band; my $var; print STDERR "BANDS\n"; foreach $band ( keys %Bands ) { print STDERR "$band: { "; for $var ( keys %{ $Bands{$band} } ) { print STDERR "$var=$Bands{$band}{$var} "; } print STDERR "}\n"; } } $Bands{listboxes}{spacing}=10; $Bands{listboxes}{nextbox}= $Bands{listboxes}{nextbox} +$Bands{listboxes}{width} +$Bands{listboxes}{spacing}; $RichEdit=$W->AddRichEdit( # -style => WS_VSCROLL |WS_CHILD | WS_VISIBLE | 1, -name => "RichEdit", -left => $Bands{listboxes}{nextbox}, -top => $Bands{listboxes}{top}+2, -width => 200, -height => $Bands{listboxes}{height}-4, -text => "", ); $W->{RichEdit}->{-background} = $B->{-handle}; sub RichEdit_Change { my $t; # my $t=$W->RichEdit->Select(0,100); $t=$W->RichEdit->Text if not $t; print STDERR "$t RichEdit\n"; $W->Action->Text($t); $W->Action->Show(); } $Bands{listboxes}{width}=$W->RichEdit->Width; $Bands{listboxes}{nextbox}= $Bands{listboxes}{nextbox} +$Bands{listboxes}{width} +$Bands{listboxes}{spacing}; $AlarmList = $W->AddListbox( -name => "AlarmList", -style => WS_VSCROLL |WS_CHILD | WS_VISIBLE | 1, -left => 8*(32+10), -top => 1, -width => 160, -height => 65, -menu => 2, -bold => 1, -foreground => [255,0,0], -background => 16316640, -font => $Courier, ); $Bands{listboxes}{nextbox}= $Bands{listboxes}{nextbox} +$Bands{listboxes}{width} +$Bands{listboxes}{spacing}; sub updateAlarms { my @l=&GetAlarms; $AlarmList->Reset(); foreach (reverse @l) { /(.+)\s+(.+)/; my $t="$1 ".$2-time; $t=$_; $AlarmList->AddString( $t ) } $AlarmList->Select(-1); } sub AlarmList_DblClick222222 { print STDERR $file," FILE\n"; Remove_Click(); } sub AlarmList_DblClick { $item=$AlarmList->GetString($AlarmList->SelectedItem()); print STDERR "ITEM>$item Double Click\n" if $debugging{'gui'}; } sub AlarmList_Click { $item=$AlarmList->GetString($AlarmList->SelectedItem()); print STDERR "ITEM>$item Click\n" if $debugging{'gui'}; } sub AlarmList_Changed { $item=$AlarmList->GetString($AlarmList->SelectedItem()); } $Timer = $W->AddTimer("baseTimer", 0); $W->AddLabel( -name => "labTimer", -left => $W->ScaleWidth-15, -top => 1, -width => 80, -height => 16, -bold => 1, -notify => 1, -foreground => [00,255,00], -background => [00,00,00], -font => $Fixedsys, -align => 'left', ); sub labTimer_Click { print STDERR $GUI{'clock'},"\n"; if ($GUI{'clock'} eq 'time') { $GUI{'clock'}='tick'; } else { $GUI{'clock'}='time' } } $W->AddLabel( -name => "Action", -left => $W->ScaleWidth-5, -top => 20, -width => 60, -height => 30, -bold => 1, -align => 'left', -foreground => [00,255,00], -background => [00,00,00], ); $W->AddButton( -name => "butContinue", -left => $W->ScaleWidth-5, -top => $W->ScaleHeight-55, -width => 50, -text => "Continue", -font => $Announce, ); sub butContinue_Click { Window_Terminate(); } sub butClose_Click { &closeSys; Window_Terminate(); } my $active; my $StatOnbmp = new Win32::GUI::Bitmap("redlround.bmp"); my $StatInactivebmp = new Win32::GUI::Bitmap("reddround.bmp"); my $StatOffbmp = new Win32::GUI::Bitmap("grayround.bmp"); sub EvalActivated { my $set=shift; $active = 0 if ($set); $W->evalStatus->SetImage($StatOffbmp) if $active; $W->evalStatus->SetImage($StatOnbmp) if not $active; $active=!$active; # print "\$active $active\n"; # $W->InvalidateRect(1); GUI::Update($GUI{'guiW'}); $W->{'evalStatus'}->Show(); $W->Show(); $W->Refresh(); } sub enableAlarmActivated { my $set=shift; $W->evalStatus->SetImage($StatOffbmp) if $active; $W->evalStatus->SetImage($StatOnbmp) if not $active; $active=!$active; # print "\$active $active\n"; # $W->InvalidateRect(1); GUI::Update($GUI{'guiW'}); $W->{'evalStatus'}->Show(); $W->Show(); $W->Refresh(); } $W->AddLabel( -name => "evalStatus", -left => 102, -top => $W->ScaleHeight-16, # -top => $row2+5, -width => 16, -text => "Close", -font => $Announce, -bitmap => 1, ); $W->AddLabel( -name => "enableAlarm", -left => 102, -top => $W->ScaleHeight-42, -width => 16, -bitmap => 1, ); $enableAlarm= not $enableAlarm; $W->AddButton( -name => "butSwitch", -left => $W->ScaleWidth-5, -top => $W->ScaleHeight-80, -width => 50, -text => "Switch", -font => $Announce, ); $W->Show; $GUI{'name'} = $windowtitle; $GUI=synch(\%GUI); %GUI=%$GUI; $GUI{'guiW'}; print STDERR "$GUI{'perlW'} \$GUI{'perlW'} missing from GT1!\n" if not $GUI{'perlW'}; print STDERR "$GUI{'guiW'} \$GUI{'guiW'} missing from GT1!\n" if not $GUI{'guiW'}; GUI::Text($GUI{'perlW'},$windowtitle); GUI::BringWindowToTop($GUI{'guiW'}); $sys{'GUI'}=$GUI; Reset(); GUI::Update($GUI{'guiW'}); Win32::GUI::Dialog(); sub format_time { my ($sec, $min, $hour); if ($GUI{'clock'} eq 'time') { ($sec, $min, $hour)= localtime(time); } else { ($sec, $min, $hour)= gmtime($tick); } my $td=sprintf("%02d:%02d:%02d", $hour, $min, $sec); } ######################### Events ####################### sub baseTimer_Timer { $tick++; $W->labTimer->Text(&format_time); $W->labTimer->Show(); $Timer->Interval(1000); &runAlarms if $enableAlarm; $Act=0; } sub butSwitch_Click { # &EvalActivated $W->Action->Text(getTime($tick)); print STDERR getTime($tick),"\n"; } sub Debugger_Deactivate { } sub Debugger_Activate { if (defined $GUI{'guiW'} and not $Act) { $Act=1; GUI::BringWindowToTop($GUI{'perlW'}); GUI::BringWindowToTop($GUI{'guiW'}); GUI::Update($GUI{'guiW'}); $Act=1; } } sub butClose_Click { &closeSys; Window_Terminate(); } sub Window_Terminate { GUI::BringWindowToTop($GUI{'perlW'}); GUI::PostQuitMessage($sys{'child'}); return -1; } sub changetext { $W->Action->Text($_[0]); } ######################### toolbar stuff ####################### sub Toolbar_ButtonClick { my($button) = @_; my $n=$tbcode[$button]{'name'}; $W->Action->Text($n); my $c=$tbcode[$button]{'code'}; # print STDERR $n," ",$c," CODE\n"; print STDERR "GUIToolbar>$n\n"; $n= eval $c; if (not $n) { } print $n; GUI::Update($GUI{'guiW'}); } sub butCancel { $We->Hide(); } # Use the same GetOpenFileName to get or save a file. sub getFile { my $file_spec = "*.xml\0" . " " x 256; my $dir = cwd; my $file = GUI::GetOpenFileName( -owner => $W, -directory => "$dir", -title => "Load/Save File", -file => $file_spec, ); addLink($file) if $file; &LinkListReset; &checkPage; #check for page setup &parseit; guiTitle "$sys{'file'}"; } sub parseit { my @l; @items=parseFile($file); return if scalar @items ==0; push @l,$_->{'name'} foreach (@items); print STDERR "PARSER>",scalar @l,"\n" if $sys{'debug'} >2;; $ItemList->Reset(); $ItemList->AddString($_) foreach (@l); $ItemList->Select(0); return scalar @l; } sub LinkListReset { my @l=&getLinks; $LinkList->Reset(); $LinkList->AddString($_) foreach (@l); undef $file; &NextLink; } sub NextLink { return $file if $file and (not $itemsrun); $file=nextLink(); return undef if not $file; $sys{'file'}=$file if not $sys{'file'}; $W->Title => $windowtitle . $file; $LinkList->Select($LinkList->FindString($file)); my $i=$LinkList->FindString($file); print STDERR "NextLink>$file $i\n"; GUI::Update($GUI{'guiW'}); $file; } sub Reset { Init(); $sys=primeSys(); %sys=%$sys; $itemsrun=0; $enableAlarm=0; $ItemList->Reset(); $AlarmList->Reset(); &clearAlarms; &LinkListReset; &checkPage; #check for page setup &parseit; guiTitle "$sys{'file'} Reset"; $file; } my @lastitem; sub nextItem { my $i=$ItemList->SelectedItem(); $item=$ItemList->GetString($i); if ($item ne $lastitem[0]) { guiTitle "$sys{'file'} $item"; $ItemList->Select($i); $W->Action->Text($item); # print STDERR "\$lastitem[0]>$lastitem[0]\n"; print STDERR "Next-$item> $i\n" if $debugging{'next'}; unshift @lastitem, $item; &EvalActivated; # GUI::Update($GUI{'guiW'}); runItem($i); updateAlarms(); &EvalActivated; # print STDERR "$item> DONE\n"; $i++; $item=$ItemList->Select($i); } else { $itemsrun=1; print STDERR "Next-$item> $i LAST\n"; if (&NextLink) { &checkEvents; &checkPage; #check for page setup &parseit; runItem($i); $item; } else { checkAlarm(); updateAlarms(); return undef; } } } sub Next { &nextItem; } sub File { &runItems; #loop through the list &checkFooter; #did we finish a page? $itemsrun=1; if (&NextLink) { &checkEvents; &checkPage; &parseit; } } my $delay=0; sub runItems { my @items=&getItems; my $i; foreach (@items) { my $n=$_->{'name'}; my $i=$ItemList->SelectedItem(); $i++; GUI::BringWindowToTop($GUI{'guiW'}); print STDERR "GUIrun> number $i $n\n" if $sys{'debug'} >2; &EvalActivated(1); my $hIE=$sys{'hIE'}; my $doc=$hIE->{'Document'}->{'all'} if $hIE; GUI::Update($GUI{'guiW'}); my $r= checkItem($_); &updateAlarms; &EvalActivated(0); $ItemList->Select($i); # $ItemList->Show(); GUI::Update($GUI{'guiW'}); # last if not $r; sleep($delay) if $delay; } } sub Run { print STDERR "RUN> $sys{'file'}\n"; undef $stop; &runItems; #loop through the list &checkFooter; #did we finish a page? $itemsrun=1; return if $stop; while (&NextLink) { my $sys=primeSys(); %sys=%$sys; last if $stop; # last if not defined $sys{'page'}; &checkEvents; &checkPage; &parseit; $itemsrun=0; print STDERR "RUN> $sys{'file'}\n"; &runItems; #loop through the list &checkFooter; #did we finish a page? GUI::Update($GUI{'guiW'}); $itemsrun=1; } print STDERR "FINISHED> $sys{'file'}\n"; # $stop=1; $enableAlarm=1; }; sub runAlarms { $enableAlarm=1; my %h=%$sys; while (&AlarmTime and $enableAlarm) { checkAlarm(); updateAlarms(); $enableAlarm=0 if $stop; if (&NextLink) { &checkEvents; &checkPage; &parseit; &File; } } $enableAlarm; }