Using Gtk3 FileChooserDialog in Perl
====================================
For dealing with files in your project, choosing a good GUI module
is a good idea. In Perl, you canuse Tk, but In Tk, text is written
left to write no mattter what language they are written in is.
Gtk is better.
To see what packages are installed on my computer, I start with
the command:
perldoc perl
The output of the command "perldoc" is similar to that of "man".
A list of manuals can be found in the output, and under Reference Manual,
there is the line:
perlmodlib Perl modules: how to write and use
Manual can be read using "perldoc", so perlmodlib will be read by
typing from the shell:
perldoc perlmodlib
In the text, a way to find all modules installed on your system
is described; use the following command from the shell:
The command installs a wrapper for Gtk3 and also adds a Perl
manual on Gtk3, but not all widgets are documented there.
But you can learn how to create Gtk3 widgets in perl. For the
rest documentation on Gtk3 is recommended. And in my system they
can be found in path:
/usr/local/share/gtk-doc/html/gtk3/
The manual can be viewed using a web browser. A good place to start is:
/usr/local/share/gtk-doc/html/gtk3/index.html
It explains how to work with GTK in C, but the function can be
converted to Perl method. Just use:
Gtk3::<widget name in camel case-><method>
For example, insted of "gtk_file_chooser_dialog_new", use
Gtk3::FileChooserDialog->new
The way to instantiate the dialog differs Perl slightly from the
way to do it in C. In Perl, the syntax of the "new" method is:
Gtk3::FileChooserDialog->new (<window-title>,
<parent-window>,
<action>,
<list of button texts and their
corresponding responsed id's>);
<action> is the type of file dialog, for example:
"open" - if the dialog is used for opening files.
"save" - if the dialog is used for saving files.
Response id's are strings returned by calling the "new" method.
Examples for VALID ones are 'accept' and 'reject'
Following is an example code that will make understanding Perl Gtk3
easier:
use strict;
use Gtk3 -init;
my $dialog=Gtk3::FileChooserDialog->new ('Select a File',
undef,
'open',
'Open File'=>'accept',
'Close Dialog'=>'reject',
);
my $res=$dialog->run;
print $res . "\n";
if ($res eq 'accept'){
print ($dialog->get_filename . "\n");
}