Tk::FileDialog - A highly configurable File Dialog widget for Perl/Tk. |
Tk::FileDialog - A highly configurable File Dialog widget for Perl/Tk.
The widget is composed of a number of sub-widgets, namely, a listbox for files and (optionally) directories, an entry for filename, an (optional) entry for pathname, an entry for a filter pattern, a 'ShowAll' checkbox (for enabling display of .* files and directories), and three buttons, namely OK, Rescan, and Cancel. Note that the labels for all subwidgets (including the text for the buttons and Checkbox) are configurable for foreign language support. The Listboxes will respond to characters typed over them with scrolling to the first line that starts with the given character (or next etc. if this character is not present).
To use FileDialog, simply create your FileDialog objects during initialization (or at least before a Show). When you wish to display the FileDialog, invoke the 'Show' method on the FileDialog object; The method will return either a file name, a path name, or undef. undef is returned only if the user pressed the Cancel button.
The following code creates a FileDialog and calls it. Note that perl5.002gamma is required.
#!/usr/local/bin/perl -w
use Tk; use Tk::FileDialog; use strict;
my($main) = MainWindow->new; my($Horiz) = 1; my($fname);
my($LoadDialog) = $main->FileDialog(-Title =>'This is my title', -Create => 0);
print "Using FileDialog Version ",$LoadDialog->Version,"\n";
$LoadDialog->configure(-FPat => '*pl', -ShowAll => 'NO');
$main->Entry(-textvariable => \$fname) ->pack(-expand => 1, -fill => 'x');
$main->Button(-text => 'Kick me!', -command => sub { $fname = $LoadDialog->Show(-Horiz => $Horiz); if (!defined($fname)) { $fname = "Fine,Cancel, but no Chdir anymore!!!"; $LoadDialog->configure(-Chdir =>'NO'); } }) ->pack(-expand => 1, -fill => 'x');
$main->Checkbutton(-text => 'Horizontal', -variable => \$Horiz) ->pack(-expand => 1, -fill => 'x');
$main->Button(-text => 'Exit', -command => sub { $main->destroy; }) ->pack(-expand => 1, -fill => 'x');
MainLoop;
print "Exit Stage right!\n";
exit;
Displays the file dialog box for the user to operate. Additional configuration items may be passed in at Show-time In other words, this code snippet:
$fd->Show(-Title => 'Ooooh, Preeeeeety!');
is the same as this code snippet:
$fd->configure(-Title => 'Ooooh, Preeeeeety!'); $fd->Show;
Returns the current Version of FileDialog
Any of the following configuration items may be set via the configure (or Show) method, or retrieved via the cget method.
Flags may be configured with either 1,'true', or 'yes' for 1, or 0, 'false', or 'no' for 0. Any portion of 'true', 'yes', 'false', or 'no' may be used, and case does not matter.
default: 1
SelHook routines return 0 to reject the selection and allow the user to reselect, and any other value to accept the selection. If a SelHook routine returns non-zero, the FileDialog will immediately be withdrawn, and the file will be returned to the caller.
There may be only one SelHook routine active at any time. Configuring the SelHook routine replaces any existing SelHook routine. Configuring the SelHook routine with 0 removes the SelHook routine. The default SelHook routine is undef.
The following two switches may be used to set default variables, and to get final values after the Show method has returned (but has not been explicitly destroyed by the caller)
-Path The path of the selected file, or the initial path. The default is $ENV{'HOME'}.
For support of internationalization, the text on any of the subwidgets may be changed.
-DirLBCaption The Caption above the Directory List Box. The default is 'Directories'.
-FileLBCaption The Caption above the File List Box. The default is 'Files'.
-FileEntryLabel The label to the left of the File Entry. The Default is 'Filename:'.
-PathEntryLabel The label to the left of the Path Entry. The default is 'Pathname:'.
-FltEntryLabel The label to the left of the Filter entry. The default is 'Filter:'.
-ShowAllLabel The text of the Show All Checkbutton. The default is 'Show All'.
For support of internationalization, the text on the three buttons may be changed.
-RescanButtonLabel The text for the Rescan button. The default is 'Rescan'.
-CancelButtonLabel The text for the Cancel button. The default is 'Cancel'.
If the Create switch is set to 0, and the user specifies a file that does not exist, a dialog box will be displayed informing the user of the error. These switches allow some configuration of that dialog box.
Brent B. Powers, Merrill Lynch (B2Pi)
This code may be distributed under the same conditions as Perl itself.
Tk::FileDialog - A highly configurable File Dialog widget for Perl/Tk. |