#!/usr/bin/perl use strict; use Tk; use Tk::TFrame; my $con_but_txt = "Connect"; my $online = 0; my $rd_b2; # Set the software version and display it! my $statusmsg = 'Version 0.1'; #------------ my $mw = MainWindow->new; #------------ my $seg2_f = $mw->TFrame(-label => 'Segment 2', -relief => 'groove', -borderwidth => 2); $rd_b2 = $seg2_f->Button(-text => "Read", -state => 'disabled', -command => [\&read_seg, 2]); $rd_b2->grid(-row => 3, -column => 1, -sticky => "e", -padx => 4); my $ts_e2 = $seg2_f->Text(-wrap => 'word', -width => 50, -height => 6)->grid( -padx => 4, -pady => 4, -row => 0, -column => 3, -sticky => "nsew", -rowspan => 4); $seg2_f->grid(-row => 1, -column => 0, -sticky => "nsew",-padx => 2); #------------- my $base_f = $mw->Frame( -relief => 'groove', -borderwidth => 2); my $status = $base_f->Label(-textvariable => \$statusmsg, -borderwidth => 2, -width => 20, -relief => 'groove')->grid(-row => 1, -column => 0, -sticky => "w",-padx => 2,-pady => 3); my $conn_b = $base_f->Button(-textvariable => \$con_but_txt, -command => \&connect)->grid(-row => 1, -column => 3, -sticky => "e"); $base_f->Button(-text => "Exit", -command => sub {exit})->grid(-row => 1, -column => 4, -sticky => "e"); $base_f->grid(-row => 2, -column => 0, -sticky => "w",-padx => 2); #------------- #----------------------------------------- sub read_seg { my $cnt; my $inpstr; my ($segnum) = @_; $statusmsg = sprintf("Reading Segment %d", $segnum); $mw->update(); $mw->after(500); $statusmsg = "Online"; $mw->update(); } sub connect { my $cnt; my $inpstr; # Connect / Disconnect # if ($online == 0) { $online = 1; $con_but_txt = "Disconect"; $statusmsg = 'Online'; } else { $online = 0; $con_but_txt = "Connect"; $statusmsg = 'Offline'; } update_buttons(); } # Enable/Disable various buttons # sub update_buttons { if ($online == 0) { # We are Offline # $rd_b2->cofigure(-state => 'disabled'); $mw->$seg2_f->$rd_b2->cofigure(-state => 'disabled'); } else { # We are Online # $rd_b2->cofigure(-state => 'normal'); $mw->$seg2_f->$rd_b2->cofigure(-state => 'normal'); } }