| 1 | package Tk::LoginDialog; | ||
| 2 | my $RCSRevKey = '$Revision: 1.2 $'; | ||
| 3 | $RCSRevKey =~ /Revision: (.*?) /; | ||
| 4 | $VERSION=0.61; | ||
| 5 | use vars qw($VERSION @EXPORT_OK); | ||
| 6 | |||
| 7 | use Tk qw(Ev); | ||
| 8 | use Tk::CmdLine; | ||
| 9 | use strict; | ||
| 10 | use Carp; | ||
| 11 | use base qw(Tk::Toplevel); | ||
| 12 | use Tk::widgets qw(LabEntry DialogBox); | ||
| 13 | |||
| 14 | Construct Tk::Widget 'LoginDialog'; | ||
| 15 | |||
| 16 | my $font="*-helvetica-medium-r-*-*-12-*"; | ||
| 17 | |||
| 18 | Tk::CmdLine::SetResources ('*font: ' . $font); | ||
| 19 | |||
| 20 | sub Populate { | ||
| 21 | my ($w, $args) = @_; | ||
| 22 | require Tk::Toplevel; | ||
| 23 | require Tk::DialogBox; | ||
| 24 | require Tk::LabEntry; | ||
| 25 | require Tk::Button; | ||
| 26 | require Tk::Frame; | ||
| 27 | $w->SUPER::Populate($args); | ||
| 28 | |||
| 29 | my $l = $w -> Component( Label => 'toplabel', | ||
| 30 | -text => 'Please enter your user name and password.' | ||
| 31 | ) -> pack( -expand => '1', -fill => 'x', | ||
| 32 | -ipady => 5, -ipadx => 5); | ||
| 33 | $l = $w -> Component( LabEntry => 'userid', | ||
| 34 | -labelVariable => \$w -> {'Configure'}{'-uidlabel'}, | ||
| 35 | -textvariable => \$w -> {'Configure'}{'-userid'} ) | ||
| 36 | -> pack( -anchor => 'w', -expand => '1', -fill => 'x', | ||
| 37 | -ipady => 5, -ipadx => 5); | ||
| 38 | $l = $w -> Component( LabEntry => 'password', | ||
| 39 | -labelVariable => \$w -> {'Configure'}{'-pwdlabel'}, | ||
| 40 | -textvariable => \$w -> {'Configure'}{'-password'}, | ||
| 41 | -show => '*' ) | ||
| 42 | -> pack( -anchor => 'w', -expand => '1', -fill => 'x' ); | ||
| 43 | my $f = $w -> Component( Frame => 'buttons', | ||
| 44 | -container => '0', | ||
| 45 | -relief => 'groove', | ||
| 46 | -borderwidth => '3' ); | ||
| 47 | my $ok = $f -> Button( -text => 'Login', -width => 6, | ||
| 48 | -default => 'active', | ||
| 49 | -command => sub{ $w->Accept}) | ||
| 50 | -> pack( -padx => 30, -pady => 5, -side => 'left', -anchor => 'w'); | ||
| 51 | my $cancel = $f -> Button( -text => 'Cancel', -width => 6, | ||
| 52 | -default => 'normal', | ||
| 53 | -command =>sub{$w->WmDeleteWindow}) | ||
| 54 | -> pack( -padx => 30, -pady => 5, -side => 'right', -anchor => 'e' ); | ||
| 55 | $f -> pack( -ipadx => 10, -expand => '1', -fill => 'x' ); | ||
| 56 | $w->ConfigSpecs( | ||
| 57 | -userid => ['PASSIVE', undef, undef, "" ], | ||
| 58 | -password => ['PASSIVE', undef, undef, "" ], | ||
| 59 | -accept => ['PASSIVE', undef, undef, "" ], | ||
| 60 | -uidlabel => ['PASSIVE', undef, undef, 'User ID'], | ||
| 61 | -pwdlabel => ['PASSIVE', undef, undef, 'Password'], | ||
| 62 | ); | ||
| 63 | $ok -> focus; | ||
| 64 | return $w; | ||
| 65 | } | ||
| 66 | |||
| 67 | sub Accept { | ||
| 68 | my $w = shift; | ||
| 69 | $w -> {Configure}{-accept} = '1'; | ||
| 70 | } | ||
| 71 | |||
| 72 | sub Show { | ||
| 73 | my( $w, @args) = @_; | ||
| 74 | $w -> waitVariable( \$w -> {'Configure'}{'-accept'} ); | ||
| 75 | $w -> withdraw; | ||
| 76 | return 'Login'; | ||
| 77 | } | ||
| 78 | |||
| 79 | |||
| 80 | 1; |