#=============================================== # TkDeviceCommon2 #=============================================== package TkDeviceCommon2; use MyTk::TkCommon; @ISA = qw(TkCommon); #公開したいサブルーチン #@EXPORT = qw(DelSpace Reduce01 MakePath RegExpQuote); use strict; use MyTk::MyFrame; use MyTk::MyButton; use MyTk::Dialog; #============================================================ # 変数等取得関数 #============================================================ #============================================================ # コンストラクタ、デストラクタ #============================================================ #呼び出されることはない sub new { my ($module, $app) = @_; my $this = {}; bless $this; return $this; } sub DESTROY { my $this = shift; $this->SUPER::DESTROY(@_); } #============================================================ # 継承クラスで定義しなおす関数 #============================================================ sub ChooseASaveFile { my ($this, $filepath, $defpath, $fmask) = @_; if(!defined $filepath or $filepath eq '') { $filepath = $this->ChooseSaveFile($defpath, $fmask); } if(!$filepath or $filepath eq '') { return undef; } return $filepath; } sub ChooseSaveFile { my ($this, $path, $fmask, $widget) = @_; $path = 'save.csv' if(!defined $path); $fmask = '*.csv' if(!defined $fmask); $path = $widget->GetText() if($widget); $path = 'out.csv' if(!$path); my $App = $this->App(); my $mw = $this->mw(); my $dir = $this->App()->{WorkDir}; chdir($dir) if($dir); my $defstr = $path; my $message = 'Choose file'; my $filepath = Dialog::OpenFileDialog($mw, 'save', $fmask, $defstr, $message, $dir); if($filepath) { my $DirPath = $this->SetWorkDir($filepath); if($widget) { $widget->SetText($filepath); } } return $filepath; } sub ChooseAFile { my ($this, $mode, $fmask, $defstr, $message, $type, $widget, $Option) = @_; my $dir = ''; unless($widget) { $dir = $this->App()->{WorkDir}; chdir($dir); } my $filepath = Dialog::OpenFileDialog($this->mw(), 'open', $fmask, $defstr, $message, $dir); return undef if(!defined $filepath or $filepath eq ''); my $DirPath = $this->SetWorkDir($filepath); $widget->SetText($filepath) if($widget); return $filepath; } sub ChooseFile { #action = 'open'; #'save' my ($this, $action, $fmask, $Option, $name, $Frame) = @_; #print "this=$this, a=$action, f=$fmask, n=$name, F=$Frame, o=$Option\n"; my $App = $this->App(); # my $mw = $this->mw(); my $Entry = $Frame->{PathEntry}; my $filepath = $this->ChooseAFile($name, $action, $fmask, '', "Choose file", $Entry, $Option); return undef if(!defined $filepath or $filepath eq ''); my $ret; if($Option eq 'ChooseParameterFile') { $ret = $this->ReadParameterFile($filepath, 1, $Frame); } elsif($Option =~ /ChooseSample.*File/i) { $ret = $this->ReadSampleDataFile($filepath, 1, $Frame); } return undef unless($ret); return $ret; } sub EditFile { my ($this, $Option, $name, $Frame) = @_; #print "O=$Option n=$name, F=$Frame, pe=$Frame->{PathEntry}\n"; my $Editor = $this->App()->{Editor}; $Editor = 'notepad.exe' if(!-e $Editor); my $File = $Frame->{PathEntry}->GetText(); my $command = "$Editor $File"; print "cmd: [$command]\n"; # system($command); Deps::ExecBackground($command); } sub ReadParameterFile { my ($this, $filepath) = @_; my $ini = $this->{ini}; # $this->Initialize(1, 1); $this->App()->print("\nRead paramter from [$filepath].\n"); $this->{ini}->ReadAll($filepath); $this->{ini}->{ParameterFile} = $filepath; # $this->{ChooseXListBox}->SetText($this->{ini}->{X}) if($this->{ChooseXListBox}); # if($this->{ini}->{DataCSVFile}) { # my $ret = $this->ReadSampleDataFile($this->{ini}->{SampleCSVFile}, 1, 0); # return undef unless($ret); # } return 1; } sub SaveSampleFile { my ($this, $Option, $filepath, $name, $Frame, $DoConfirm) = @_; $filepath = $Frame->{PathEntry}->GetText() if($filepath eq ''); $DoConfirm = 1 if(!defined $DoConfirm); if(!defined $filepath or $filepath eq '') { $filepath = 'data.csv' if(!defined $filepath or $filepath eq ''); $filepath = Deps::ExtractFileName($filepath); $DoConfirm = 0; $filepath = $this->ChooseSaveFile($filepath, '*.csv'); if($filepath) { my $ext = Deps::ExtractExtention($filepath); if(!defined $ext or $ext eq '') { $filepath = Deps::ReplaceExtension($filepath, ".csv"); } $Frame->{PathEntry}->SetText($filepath); } else { return; } } if($DoConfirm) { my $button = $this->mw()->messageBox( -icon => 'warning', -type => 'YesNo', -default => 'No', -title => 'Confirm', -message => "[$filepath] exists.\r\nOverwrite?"); return undef if($button eq 'No'); } my $OperatorName = $this->{ini}->{OperatorName}; my $RecordedTime = $this->{ini}->{RecordedTime}; $RecordedTime = $this->{ini}->{StartTime} if($RecordedTime =~ /{StartTime}/i); $RecordedTime = $this->{ini}->{EndTime } if($RecordedTime =~ /{EndTime}/i); my $out = new JFile($filepath, "w"); if(!$out) { $this->App()->print("\nError: Can not write to [$filepath].\n"); return undef; } my $pX = $this->{DataCSV}->pX(); my $pY = $this->{DataCSV}->pY(); $out->print("V(V),I(A),,$OperatorName,$RecordedTime\n"); for(my $i = 0 ; $i < @$pX ; $i++) { $out->print("$pX->[$i],$pY->[$i]\n"); } $out->Close(); $this->App()->print("\nSave Data File to [$filepath]\n"); return 1; } sub SaveParameterFile { my ($this, $Option, $filepath, $name, $Frame, $DoConfirm) = @_; $DoConfirm = 1 if(!defined $DoConfirm); $filepath = $Frame->{PathEntry}->GetText() if($filepath eq ''); if(!defined $filepath or $filepath eq '') { $filepath = $this->{ini}->{Sample1CSVFile}; $filepath = 'save.prm' if(!defined $filepath or $filepath eq ''); $filepath =~ s/\.csv$/\.prm/i; $filepath = Deps::ExtractFileName($filepath); $DoConfirm = 0; $filepath = $this->ChooseSaveFile($filepath, '*.prm'); if($filepath) { my $ext = Deps::ExtractExtention($filepath); if(!defined $ext or $ext eq '') { $filepath = Deps::ReplaceExtension($filepath, ".prm"); } $this->{ini}->{ParameterFile} = $filepath; } else { return; } } if($DoConfirm) { my $button = $this->mw()->messageBox( -icon => 'warning', -type => 'YesNo', -default => 'No', -title => 'Confirm', -message => "[$filepath] exists.\r\nOverwrite?"); return undef if($button eq 'No'); } $this->{ini}->SetIniFile($filepath, undef, 1); $this->App()->print("\nSave ParameterFile to [$filepath]\n"); $this->{ini}->WriteAll(); } sub MakeChooseFileEntry { # $pDataLabelList: ['X', 'Y1', 'Y2'] my ($this, $Frame, $name, $Label, $pVariable, $ButtonLabel, $UseChooseButton, $ChooseCommand, $UseSaveButton, $SaveCommand, $UseEditButton, $EditCommand, $pDataLabelList) = @_; $pDataLabelList = [] if(!defined $pDataLabelList); my $ChildFrame = $Frame->MyFrame(); my $ChildFrame1 = $ChildFrame->MyFrame()->pack(-side => 'top', -expand => 'yes', -fill => 'x'); $ChildFrame->{TopLabel} = $ChildFrame1->MyLabel(-text => $Label)->pack(-side => 'left'); $ChildFrame->{PathEntry} = $ChildFrame1->MyEntry( -takefocus => 1, -textvariable => $pVariable )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); $ChildFrame->{PathEntry}->focus(); if($UseChooseButton) { $ChildFrame->{PathButton} = $ChildFrame1->MyButton( -text => $ButtonLabel, -takefocus => 1, -command => sub { &$ChooseCommand($name, $ChildFrame); }, )->pack(-side => 'left', -fill => 'x'); } if($UseSaveButton) { $ChildFrame->{SaveButton} = $ChildFrame1->MyButton( -text => '&Save', -takefocus => 1, -command => sub { &$SaveCommand($name, $ChildFrame); }, )->pack(-side => 'left', -fill => 'x'); } if($UseEditButton) { $ChildFrame->{EditButton} = $ChildFrame1->MyButton( -text => 'ed', -takefocus => 1, -command => sub { &$EditCommand($name, $ChildFrame); }, )->pack(-side => 'left', -fill => 'x'); } my $ChildFrame2 = $ChildFrame->MyFrame()->pack(-side => 'top', -expand => 'yes', -fill => 'x'); for(my $i = 0 ; $i < @$pDataLabelList ; $i++) { my $key = $pDataLabelList->[$i]; $ChildFrame->{"${key}ListBox"} = $ChildFrame2->MyBrowseEntry( -variable => $this->{ini}->pVariable("$name$key", ''), -label => "$key:", -state => "readonly", -takefocus => 1, -width => 5, -Selections => [], -SelIndex => 0, )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); $ChildFrame->{"${key}ListBox"}->configure(-browsecmd => [\&SelChangeListBox, $this, $key, $this->{"${key}ListBox"}]); } return $ChildFrame; } sub MakeChooseFilePane { my ($this, $Frame, $pChooseFileArray) = @_; my $ChildFrame = $Frame->MyFrame(); for(my $i = 0 ; $i < @$pChooseFileArray ; $i++) { my $pArray = $pChooseFileArray->[$i]; my ($VarName, $Label, $FileName, $FrameName, $FileMask, $pButtons, $pAxes, $pDataLabels) = @$pArray; #print "$VarName: $Label: $FrameName\n"; my %ButtonHash; for(my $j = 0 ; $j < @$pButtons ; $j++) { $ButtonHash{$pButtons->[$j]} = 1; } if($VarName eq 'Param') { my $Frame = $ChildFrame->MyFrame()->pack(-anchor => 'nw', -fill => 'x'); $ChildFrame->{$FrameName} = $this->MakeChooseFileEntry( $Frame, $VarName, $Label, $this->{ini}->pVariable($FileName, ""), '&Choose', $ButtonHash{choose}, sub { $this->ChooseFile("save", $FileMask, "ChooseParameterFile", @_); }, $ButtonHash{save}, sub { $this->SaveParameterFile("SaveParam", '', @_); }, $ButtonHash{edit}, sub { $this->EditFile('EditParam', @_); }, $pAxes, ); $ChildFrame->{$FrameName}->pack(-anchor => 'nw', -expand => 'yes', -fill => 'x'); } else { my $Frame = $ChildFrame->MyFrame()->pack(-anchor => 'nw', -fill => 'x'); $ChildFrame->{$FrameName} = $this->MakeChooseFileEntry( $Frame, $VarName, $Label, $this->{ini}->pVariable($FileName, ""), '&Choose', $ButtonHash{choose}, sub { $this->ChooseFile("open", $FileMask, "ChooseSample1File", @_); }, $ButtonHash{save}, sub { $this->SaveSampleFile($VarName, '', @_); }, $ButtonHash{edit}, sub { $this->EditFile("Edit$VarName", @_); }, $pAxes, ); $ChildFrame->{$FrameName}->pack(-anchor => 'nw', -expand => 'yes', -fill => 'x'); for(my $j = 0 ; $j < @$pDataLabels ; $j++) { my $key = $pAxes->[$j]; my $Label = $pDataLabels->[$j]; $this->{$FrameName}->{"p${key}DataLabel"} = $Label; } } } return $ChildFrame; } sub LoadPorts { my ($this, $lb) = @_; $lb->DeleteAllItem(); $lb->AddItem("DUMMY"); for(my $i = 1 ; $i <= 32 ; $i++) { $lb->AddItem("GPIB$i"); } for(my $i = 1 ; $i <= 6 ; $i++) { $lb->AddItem("COM$i"); } return $lb; } sub LoadDevices { my ($this, $lb, $Function, $IsPrint) = @_; $IsPrint = 0 if(!defined $IsPrint); my $App = $this->App(); my $IniFile = $App->IniFile(); if(!$this->{FileInfo}) { $this->{FileInfo} = {}; } $lb->DeleteAllItem(); $lb->AddItem("General"); if($IsPrint) { print "\n"; print "Read modules\n"; } my $pDirArray = $App->{ModuleDirArray}; foreach my $dir (@$pDirArray) { next if(!-e $dir); my $fmask = Deps::MakePath($dir, "*.pm", 0); my @files = glob($fmask); foreach my $path (@files) { my %info; my $fname = Deps::ExtractFileName($path); my $ModuleName = $fname; $ModuleName =~ s/\.pm//i; next if(!$IniFile->GetString($ModuleName, 'Visible', 1)); next if($ModuleName =~ /Comm$/i or $ModuleName =~ /Comm-/i or $ModuleName =~ /^TkDeviceCommon/i or $ModuleName =~ /Object$/i or $ModuleName =~ /Device$/i or $ModuleName =~ /^General$/i); no strict; eval("use Device::$ModuleName;"); # next if(!defined(&{"$ModuleName::new"})); # next if(!defined &{"$ModuleName::GetFunctions"}); #print "New: $ModuleName: $functions\n"; my $dev = $ModuleName->new(); if(defined $dev) { my $functions = $dev->GetFunctions(); undef $dev; eval("no Device::$ModuleName;"); use strict; next if($functions =~ /\|BaseObject\|/i); if($Function eq '' or $functions =~ /\|all\|/i or $functions =~ /\|$Function\|/i) { print " $ModuleName: $functions\n" if($IsPrint); $lb->AddItem($ModuleName); } $info{Dir} = $dir; $info{Path} = $path; $info{FileName} = $fname; $info{ModuleName} = $ModuleName; my $title = $info{Title} = $IniFile->GetString($ModuleName, 'Title', ''); $title = $ModuleName if($title eq ''); $info{Command} = $IniFile->GetString($ModuleName, 'Command', ''); $info{Args} = $IniFile->GetString($ModuleName, 'Args', ''); my $Explanation = $IniFile->GetString($ModuleName, 'Explanation', ''); if($Explanation eq '') { $Explanation = $title; $Explanation =~ s/^.*?:\s*//; } $info{Explanation} = $Explanation; #print "Add: $title [$ModuleName]\n"; $this->{FileInfo}->{$title} = \%info; } else { # print "$ModuleName: new not defined\n"; next; } } } print "\n" if($IsPrint); return $lb; } sub MakeDelimiterListBox { my ($this, $Name, $Frame, $Label, $Width, $pFunction) = @_; $Label = 'Delimiter:' if(!defined $Label); $Width = 4 if(!defined $Width); my $ini = $this->{ini}; $ini = $this->{ini} = new IniFile(undef, 0, 0) if(!defined $ini); my $ChildFrame = $Frame->MyFrame(); $ChildFrame->{DelimiterListBox} = $ChildFrame->MyBrowseEntry( -variable => $ini->pVariable("${Name}Delimiter", "\\r\\n(CRLF)"), -label => $Label, -state => "readonly", -takefocus => 1, -width => $Width, -Selections => ['\r\n(CRLF)', '\r(CR)', '\n(LF)'], # -SelIndex => 0, )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); if($pFunction) { $ChildFrame->{DelimiterListBox}->configure( -browsecmd => $pFunction, ); } return $ChildFrame; } sub MakePortListBox { my ($this, $Name, $Frame, $Label, $Width, $pFunction) = @_; $Label = 'Port:' if(!defined $Label); $Width = 8 if(!defined $Width); my $ini = $this->{ini}; $ini = $this->{ini} = new IniFile(undef, 0, 0) if(!defined $ini); my $ChildFrame = $Frame->MyFrame(); $ChildFrame->{PortListBox} = $ChildFrame->MyBrowseEntry( -variable => $ini->pVariable("${Name}Port", "DUMMY"), -label => $Label, -state => "readonly", -takefocus => 1, -width => $Width, -Selections => ['DUMMY', 'GPIB01', 'COM1'], # -SelIndex => 0, )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); if($pFunction) { $ChildFrame->{PortListBox}->configure( -browsecmd => $pFunction, ); } $this->LoadPorts($ChildFrame->{PortListBox}); return $ChildFrame; } sub MakeDeviceListBox { my ($this, $Name, $Frame, $Label, $Width, $Function, $pFunction) = @_; $Label = 'Device:' if(!defined $Label); $Width = 8 if(!defined $Width); $Function = 'all' if(!defined $Function); my $App = $this->App(); my $IniFile = $App->IniFile(); my $ini = $this->{ini}; $ini = $this->{ini} = new IniFile(undef, 0, 0) if(!defined $ini); my $ChildFrame = $Frame->MyFrame(); $ChildFrame->{DeviceListBox} = $ChildFrame->MyBrowseEntry( -variable => $ini->pVariable("${Name}Device", "General"), -label => $Label, -state => "readonly", -takefocus => 1, -width => $Width, -Selections => ['Keithley2000', 'Keithley6157'], # -SelIndex => 0, )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); if($pFunction) { $ChildFrame->{DeviceListBox}->configure( -browsecmd => $pFunction, ); } $this->LoadDevices($ChildFrame->{DeviceListBox}, $Function, 0); return $ChildFrame; } sub MakeButtons { my ($this, $MainFrame, $pButtonArray) = @_; my $ChildFrame = $MainFrame->MyFrame(); for(my $i = 0 ; $i < @$pButtonArray ; $i ++) { my $text = $pButtonArray->[$i]; my $funchead = $text; $funchead =~ s/&//g; $funchead =~ s/\s//g; $ChildFrame->{"${funchead}Button"} = $ChildFrame->MyButton( -text => $text, -takefocus => 1, )->pack(-side => 'left'); no strict; $ChildFrame->{"${funchead}Button"}->configure( -command => sub { $this->$funchead($ChildFrame->{"${funchead}Button"}, 'RButtonDown', $funchead); }, ); use strict; } return $ChildFrame; } sub MakRangeFrame { my ($this, $MainFrame, $MinVarName, $MinLabel, $pMinVar, $MinFormat, $MinUnit, $MaxVarName, $MaxLabel, $pMaxVar, $MaxFormat, $MaxUnit, $SkipVarName, $SkipLabel, $pSkipVar, $SkipFormat, $SkipUnit, $EntryWidth, $pComponentArray) = @_; $EntryWidth = 12 if(!defined $EntryWidth); my %ComponentHash; for(my $i = 0 ; $i < @$pComponentArray ; $i++) { $ComponentHash{$pComponentArray->[$i]} = 1; } my $ChildFrame = $MainFrame->MyFrame(); if($ComponentHash{Min}) { $this->MakeLabelEntry($ChildFrame, $MinVarName, $MinLabel, $pMinVar, $MinFormat, $EntryWidth, $MinUnit, 0, 0); } if($ComponentHash{Max}) { $this->MakeLabelEntry($ChildFrame, $MaxVarName, $MaxLabel, $pMaxVar, $MaxFormat, $EntryWidth, $MaxUnit, 0, 1); } if($ComponentHash{Step}) { $this->MakeLabelEntry($ChildFrame, $SkipVarName, $SkipLabel, $pSkipVar, $SkipFormat, 5, $SkipUnit, 0, 2); } if($ComponentHash{ViewRangeButton}) { $ChildFrame->MyButton( -text => 'viewrange', -takefocus => 1, -command => sub { $this->GetViewRange(0, 'X', $MinVarName, $MaxVarName); }, )->grid(-row => 0, -column => 11, -stick => 'e'); } return $ChildFrame; } sub MakeCheckbutton { my ($this, $Frame, $name, $Label, $pVariable, $OnValue, $OffValue) = @_; $OnValue = 1 if(!defined $OnValue); $OffValue = 0 if(!defined $OffValue); $this->{"${name}Checkbutton"} = $Frame->MyCheckbutton( -text => $Label, -variable => $pVariable, -onvalue => $OnValue, -offvalue => $OffValue, )->pack(-side => 'left'); return $this->{"${name}Checkbutton"}; } sub MakeLabelEntry { my ($this, $Frame, $name, $label1, $pVariable, $format, $EntryWidth, $label2, $row, $column, $state) = @_; #print "name=$name, pVariable=$pVariable, v=$$pVariable, format=$format\n"; $state = 'normal' if(!defined $state); if(!$pVariable) { $this->{$name} = ''; $pVariable = \{$this->{$name}}; } $$pVariable = Utils::DelSpace(sprintf($format, $$pVariable)) if($pVariable and $$pVariable); my $ChildFrame = $Frame; $ChildFrame->{Label1} = $ChildFrame->MyLabel(-text => $label1)->grid(-row => $row, -column => 3*$column+0, -columnspan => 1, -sticky => 'e' ); my @a = ( -name => $name, -textvariable => $pVariable, -state => $state, -format => $format, -takefocus => 1, ); if(defined $EntryWidth) { @a = ( @a, -width => $EntryWidth, ); } $ChildFrame->{Entry} = $Frame->MyEntry( @a )->grid(-row => $row, -column => 3*$column+1, -columnspan => 1, -sticky => 'e' ); $ChildFrame->{Label2} = $ChildFrame->MyLabel(-text => $label2)->grid(-row => $row, -column => 3*$column+2, -columnspan => 1, -sticky => 'w' ); $ChildFrame->{Label2}->bind('', [ sub { $this->EntryFocusedIn(@_); }, 'FocusIn', $name]); $ChildFrame->{Label2}->bind('', [ sub { $this->EntryFocusedOut(@_); }, 'FocusOut', $name]); $this->{pEntryArray} = [] if(!$this->{pEntryArray}); push(@{$this->{pEntryArray}}, $ChildFrame->{Entry}); return $ChildFrame; } sub MakeCheckEntry { my ($this, $Frame, $name, $label1, $pCheckVariable, $pVariable, $format, $EntryWidth, $label2, $row, $column, $state) = @_; my $Synchronize; $state = 'normal' if(!defined $state); if($state =~ /sync.*\s+norm/i) { $state = 'normal'; $Synchronize = 1; } elsif($state =~ /sync.*\s+rev/i) { $state = 'normal'; $Synchronize = -1; } #print "name=$name p=$pVariable,$$pVariable form=$format check: $pCheckVariable, $$pCheckVariable f=$format\n"; $$pVariable = Utils::DelSpace(sprintf($format, $$pVariable)); # my $ChildFrame = $Frame->MyFrame()->grid(-row => 0, -column => 0, -sticky => 'e'); #pack(-anchor => 'nw', -expand => 'yes', -fill => 'x'); my $ChildFrame = $Frame; my $ButtonLabel = "${name}Button"; my $EntryLabel = "${name}Entry"; $this->{$ButtonLabel} = $ChildFrame->{Button} = $ChildFrame->MyCheckbutton( -text => $label1, -variable => $pCheckVariable, -onvalue => 1, -offvalue => 0, -indicatoron => 'no', -takefocus => 1, )->grid(-row => $row, -column => 3*$column+0, -columnspan => 1, -sticky => 'e' ); $this->{$ButtonLabel}->{status} = $$pCheckVariable; # $button->configure(-command => sub { print "$label1 is pressed [", $button->GetText(), "]\n"; }); $this->{$EntryLabel} = $ChildFrame->{Entry} = $ChildFrame->MyEntry( -name => $name, -width => $EntryWidth, # -text => $val, -textvariable => $pVariable, -state => $state, -format => $format, -takefocus => 1, )->grid(-row => $row, -column => 3*$column+1, -columnspan => 1, -sticky => 'e' ); $ChildFrame->MyLabel(-text => $label2)->grid(-row => $row, -column => 3*$column+2, -columnspan => 1, -sticky => 'w' ); # $ChildFrame->{Entry}->bind('', [\&EntryFocusedIn, $this, 'FocusIn', $name]); # $ChildFrame->{Entry}->bind('', [\&EntryFocusedOut, $this, 'FocusOut', $name]); $ChildFrame->{Entry}->bind('', [ sub { $this->EntryFocusedIn(@_); }, 'FocusIn', $name]); $ChildFrame->{Entry}->bind('', [ sub { $this->EntryFocusedOut(@_); }, 'FocusOut', $name]); #print "Labels: $ButtonLabel, $EntryLabel\n"; if(defined $Synchronize) { my $onstr = 'disabled'; my $offstr = 'normal'; if($Synchronize < 0) { $onstr = 'normal'; $offstr = 'disabled'; if(!$this->{$ButtonLabel}->{status}) { $this->{$EntryLabel}->configure(-state => 'disabled'); } } else { if($this->{$ButtonLabel}->{status}) { $this->{$EntryLabel}->configure(-state => 'disabled'); } } $this->{$ButtonLabel}->configure( -command => sub { if($$pCheckVariable) { # if($this->{$ButtonLabel}->{status}) { #print "button: $ButtonLabel: stat=", $this->{$ButtonLabel}->{status}, ",$$pCheckVariable str=$offstr\n"; $this->{$ButtonLabel}->{status} = 1; $this->{$EntryLabel}->configure(-state => $onstr); } else { #print "button2: $ButtonLabel: stat=", $this->{$ButtonLabel}->{status}, ",$$pCheckVariable str=$onstr\n"; $this->{$ButtonLabel}->{status} = 0; $this->{$EntryLabel}->configure(-state => $offstr); } } ); } $this->{pEntryArray} = [] if(!$this->{pEntryArray}); push(@{$this->{pEntryArray}}, $ChildFrame->{Entry}); # return $this->{"${name}Button"} = $button; # return $ChildFrame->{Entry}; #$this->{"${name}Entry"} = $ent; return $ChildFrame; } sub ConvertDelimiterString { my ($this, $delim) = @_; print "d1=[$delim]\n"; $delim =~ s/\([^\)]+\)\s*$//; $delim =~ s/\\r/\r/g; $delim =~ s/\\n/\n/g; $delim =~ s/\\t/\t/g; # $delim =~ s/\\0/0/eg; $delim =~ s/CR/\n/g; $delim =~ s/LF/\r/g; $delim =~ s/TAB/\t/g; print "d2=[$delim]\n"; return $delim; } sub Disconnect { my ($this, $pDevice) = @_; $pDevice = undef; } sub Connect { my ($this, $Device, $Port, $IsPrint) = @_; $IsPrint = 1 if(!defined $IsPrint); my $App = $this->App(); my $pDevice = Device::OpenDevice($Device, $Port); my $s; if($pDevice) { $s = "Succeeded to connect to [$Device:$Port]\n" if($IsPrint); } else { $s = "Failed to connect to [$Device:$Port]\n" if($IsPrint); } $this->print($s); return $pDevice; } sub CSVView { my ($this, $widget, $event, $name) = @_; my $App = $this->App(); my $IniFile = $App->IniFile(); my $MyDir = $IniFile->MyDir(); my $PerlDir = $MyDir; $PerlDir =~ s/[\/\\][^\/\\]+?$//; my $ini = $this->{ini}; my $path = Deps::MakePath($PerlDir, "TkPlot"); $path = Deps::MakePath($path, "CSVView.bat", 0); my $cmd = "$path $ini->{DataCSVFile}"; print "cmd: [$cmd]\n"; Deps::ExecBackground($cmd); } sub Start { my ($this, $widget, $event, $name) = @_; my $ini = $this->{ini}; #print "Start: ($this, $widget, $event, $name)\n"; my $s = $widget->GetText(); if($s eq 'Start') { $this->StartMeasurement0($widget); } else { $this->StopMeasurement0($widget); } } sub StartMeasurement0 { my ($this, $widget) = @_; $widget = $this->{StartButton} if(!defined $widget); $widget->SetText('Stop') if($widget); return $this->Measure($this->{ini}); } sub StopMeasurement0 { my ($this, $widget) = @_; $widget = $this->{StartButton} if(!defined $widget); $this->StopMeasurement($this->{ini}); $widget->SetText('Start') if($widget); } sub Measure { my ($this, $ini) = @_; $this->{IsMeasuring} = 1; } sub StopMeasurement { my ($this, $ini) = @_; $this->{IsMeasuring} = 0; } sub Close { my ($this, $DoConfirm) = @_; $DoConfirm = 0 if(!defined $DoConfirm); my $geometry = $this->mw()->geometry(); $this->App()->IniFile()->WriteString("Window", "geometry", $geometry); $this->App()->SaveSetting(); if($DoConfirm) { my $button = $this->mw()->messageBox( -icon => 'warning', -type => 'YesNo', -default => 'No', -title => 'Confirm', -message => 'Really quit?'); return if($button eq 'No'); } $this->mw()->destroy(); } 1;