For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > April 2006 > Newbie - using bind









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Newbie - using bind
Jerry Preston

2006-04-30, 4:00 am

Hi!

I am not sure what I am missing here, but I want to input a date to load
some data:
#!/perl

use Tk;
use strict;
use Tk::Frame;
use Tk::Dialog;
use Tk::NoteBook;
use Tk::Scrollbar;
..
..
..
my $Date = $Beer->Entry( -textvariable => \$date,
-font => $font,
-selectborderwidth => 10,
-takefocus => 0,
-width => 10,
-relief => 'ridge',
-background =>
'yellow',
-justify => 'left',
)->place( -x => 90,
-y => 5
);

This works find for the current date. When I input a new date it is ok, but
I want to execute a subroutine to load data from another file:

$Morning_Evening->bind('<Enter>', [ \&update_database, $BGroup_LST,
$BGroup_ID, $IDs{ $BGroup_ID }{ Group }, $IDs{ $BGroup_ID }{ Pack } ] );

where

sub update_database {

my( $id, $Group_ID, $id_names, $id_packages, $DEBUG ) = @_;
..
..
..
}

Nothing happens when I hit the "ENTER" key? I am sure this is simple, but I
am missing something here!

Thanks,

Jerry


Marc Dashevsky

2006-04-30, 4:00 am

Jerry Preston <jwp@ont.com> writes in article %:
>
> $Morning_Evening->bind('<Enter>', [ \&update_database, $BGroup_LST,
> $BGroup_ID, $IDs{ $BGroup_ID }{ Group }, $IDs{ $BGroup_ID }{ Pack } ] );
>
> Nothing happens when I hit the "ENTER" key? I am sure this is simple, but I
> am missing something here!


I did not look at your code carefully enough to say much more than:

Often when bind is unresponsive, it's because the wrong widget has focus.

Judicious use of $Morning_Evening->focus may be all you need.

--
Go to http://MarcDashevsky.com to send me e-mail.
Jerry Preston

2006-04-30, 7:03 pm

Marc,

I added

$Morning_Evening->focus;

and nothing.

Thanks,

Jerry


"Marc Dashevsky" <usenet@MarcDashevsky.com> wrote in message
news:MPG.1ebe1eec49959052989997@news.supernews.com...
> Jerry Preston <jwp@ont.com> writes in article %:
>
> I did not look at your code carefully enough to say much more than:
>
> Often when bind is unresponsive, it's because the wrong widget has
> focus.
>
> Judicious use of $Morning_Evening->focus may be all you need.
>
> --
> Go to http://MarcDashevsky.com to send me e-mail.



Ala Qumsieh

2006-04-30, 7:03 pm

Jerry Preston wrote:

> $Morning_Evening->bind('<Enter>', [ \&update_database, $BGroup_LST,
> $BGroup_ID, $IDs{ $BGroup_ID }{ Group }, $IDs{ $BGroup_ID }{ Pack } ] );


You don't show us what $Morning_Evening is, but the problem is that
<Enter> is triggered when the mouse enters the widget, not when the
Enter keys is pressed. You need to bind to <Return> for that.

--Ala

Jerry Preston

2006-04-30, 7:03 pm

Ala,

I tried "Return" and had no luck with it.

Thanks,

Jerry

"Ala Qumsieh" <notvalid@email.com> wrote in message
news:gM55g.21997$tN3.3395@newssvr27.news.prodigy.net...
> Jerry Preston wrote:
>
>
> You don't show us what $Morning_Evening is, but the problem is that
> <Enter> is triggered when the mouse enters the widget, not when the Enter
> keys is pressed. You need to bind to <Return> for that.
>
> --Ala
>



Ch Lamprecht

2006-04-30, 7:03 pm

Jerry Preston wrote:
> Ala,
>
> I tried "Return" and had no luck with it.
>
> Thanks,
>
> Jerry
>
> "Ala Qumsieh" <notvalid@email.com> wrote in message

[color=darkred]

Hi Jerry,

it would be much easier to help you, if you posted a short but runnable
script, demonstrating the problem.

Christoph

--

perl -e "print scalar reverse q/ed.enilno@ergn.l.hc/"
Jerry Preston

2006-04-30, 7:03 pm

Ch,

After finding a few major errors, it is now working.

My new question is once that I load my other data, how do I refresh the
sheets to display the information?

Sorry about the length.

#!/perl

use Tk;
use strict;
use warnings;
use Tk::Frame;
use Tk::Dialog;
use Tk::NoteBook;
use Tk::Scrollbar;

local( *FI, *FO );
my %list_files = ();
my %booz_data = ();
my $font = "Arial 12 bold";
my $col_break = 8;
my $Cash_Register_Count = 3;

my $mw = MainWindow->new();
# $mw->withdraw;
$mw->title('By Jerry Preston - Last Update 04-30-2006 Ver 1.0' );
CenterWindow( $mw, 890, 550 );

my $DEBUG = 10;

my $club = $mw->NoteBook()->pack( -fill => 'both', -expand => 1 );

my $Labor = $club->add( "Sheet 1", -label => "Labor" );

my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
localtime( time );

$mon = ++$mon < 10 ? "0$mon" : $mon;
$mday = $mday < 10 ? "0$mday" : $mday;
$year += 1900;
my $date = "$mon$mday$year";
my $ME = "E";

my @list;
my $lastSearch;
my $lastIndex;

my ( $col, $row );
my ( %Name, %Packages, %Quanity, %Amount, %Tax, %Total, %names, %packages,
%NB_Totals );
my @booz_ids = qw( beer liquor wine );
my %DATA = ();

my @file_names = ();

&get_list;

&get_todays_data;

########################################
#######################################
# Labor
########################################
#######################################
# $LABOR->Labor_inputs( \$Labor, \$mw );
$col = $row = 0;
my $Group_ID = "labor";
my @Labor;
my @Labor_label;
my $Date_label = $Labor->Label( -text => 'Date',
-font => $font,
)->place( -x => 48,
-y => 5
);
my $ME_label = $Labor->Label( -text => 'M/E',
-font => $font,
)->place( -x => 48,
-y => 35
);
my $Date = $Labor->Entry( -textvariable => \$date,
-font => $font,
-selectborderwidth => 10,
-takefocus => 0,
-width => 10,
-relief => 'ridge',
-background => 'yellow',
-justify => 'right',
)->place( -x => 90,
-y => 5
);

$Date->focus;
$Date->bind('<Return>', sub{ &get_todays_data } );
my $Morning_Evening = $Labor->Entry( -textvariable => \$ME,
-font => $font,
-selectborderwidth => 1,
-takefocus => 1,
-width => 1,
-relief => 'ridge',
-background => 'yellow',
-justify => 'right',
) ->place( -x => 90,
-y => 35
);


foreach my $j ( 0..$#{ $list_files{ labor }} ) {

$row = $j * -1 if !( $j % $col_break );
$col += 2 if !( $j % $col_break );
$Labor_label[ $j ] = $Labor->Label( -text => ${
$list_files{ $Group_ID }}[ $j ],
-font => $font,
) ->grid( -row => $row + $j
+ 1,
-column => $col + 1,
-sticky => 'e'
);
$Labor[ $j ] = $Labor->Entry( -state => 'normal',
-font => $font,
-textvariable => \${
$DATA{ $Group_ID }{ ${ $list_files{ $Group_ID } }[ $j ] }}[ 0 ],
-width => 8,
-background => 'yellow',
-justify => 'right',
) ->grid( -row => $row + $j
+ 1,
-column => $col + 2,
-sticky => 'w',
-padx => 10,
-pady => 10
);
}
$Labor->Button( -text => 'Save Data',
-font => $font,
-command => sub { &update_database( ) },
-relief => 'ridge',
)->place( -x => 10,
-y => 440
);
$Labor->Button( -text => 'Quit',
-font => $font,
-width => 10,
-underline => 0,
-relief => 'ridge',
-command => sub { exit }
)->place( -x => 480,
-y => 440
);
#
# MainLoop
#
MainLoop;
########################################
#######################################
# CenterWindow
########################################
#######################################
sub CenterWindow {

my( $window, $width, $height ) = @_;

$window->idletasks;
$width = $window->reqwidth unless $width;
$height = $window->reqheight unless $height;
my $x = int(( $window->screenwidth / 2 ) - ( $width / 2 ));
my $y = int(( $window->screenheight / 2 ) - ( $height / 2 ));
$window->geometry( "=${width}x${height}+${x}+${y}" );
}1;
########################################
#######################################
# get_list
########################################
#######################################
sub get_list {

open ( FI, "List.lst" ) or die "Couldn't open List.lst";
while(<FI> ) {
chomp;
s/\s+//g;
push @file_names, $_ if length( $_ ) > 3;
}
close FI;
foreach my $files ( @file_names ) {
my @list = ();
open ( FI, "$files.lst" ) or die "Couldn't open $files.lst";
while(<FI> ) {
chomp $_;
push @list, $_ if $_;
}
close FI;
if( $files =~ /beer_names|wine_names|liquor_names/ ) {
@{ $list_files{ $files }} = sort { $a cmp $b } @list;
}else{
@{ $list_files{ $files }} = @list;
}
}
close FI;
}
########################################
#######################################
# get_todays_data
########################################
#######################################
sub get_todays_data {

print "**club.pl**get_todays_data**\n"; # if $DEBUG;
return if ! -e $date;
open( FI, $date ) || die "Unable to open $$date: $!\n";
while(<FI> ) {

chomp;
my @dat = split/,/;

push @{ $DATA{ $dat[ 0 ] }{ $dat[ 3 ] }}, $dat[ 4 ];
}
}1;
########################################
#######################################
# update_database
########################################
#######################################
sub update_database {

}

Thanks,

Jerry

"Ch Lamprecht" <christoph.lamprecht.no.spam@web.de> wrote in message
news:e33duv$bqb$1@online.de...
> Jerry Preston wrote:
>
>
> Hi Jerry,
>
> it would be much easier to help you, if you posted a short but runnable
> script, demonstrating the problem.
>
> Christoph
>
> --
>
> perl -e "print scalar reverse q/ed.enilno@ergn.l.hc/"



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com