Re: Dialog for choosing directories



On Tue, 24 Oct 2006 16:15:54 +0200
Bernhard Auzinger <e0026053 stud3 tuwien ac at> wrote:

Hello,

my name is Bernhard and I'm new to gtk2-perl and have joined the list a 
few hours ago.

I read some documentation but didn't really find a gtk2-perl dialog for 
choosing a directory. I'm looking for something similar than the 
Gtk2::FileSelection dialog, but for choosing directories.

Btw, I tried the Gtk2::FileChooserDialog with action "select folder" 
option but got a segmentation fault when calling the constructor. I 
think I must have made a terrible mistake.

my $dir_dialog = Gtk2::FileChooserDialog ( 'Select a Directory', $main_window,
'select-folder');

Maybe somebody could give me a hint, how to get through this.

If you check out the maillist archive for September 2006 at
 http://mail.gnome.org/mailman/listinfo/gtk-perl-list

you will find a lengthy thread on 
Directory/file browser as TreeView,

where a few good examples were given on using a treeview as a directory
browser. Aristotle has a good one at the end of the thread.
But these are sort of "novelty scripts" useful for specific purposes.

But......
Here is an example using the normal FileChooserDialog

#!/usr/bin/perl
use strict;
use warnings;
use Gtk2 '-init';

my $window = Gtk2::Window->new;
$window->set_title("File Selector");
$window->signal_connect( destroy => sub { Gtk2->main_quit; } );

my $button = Gtk2::Button->new("Select");
$button->signal_connect( clicked => \&dir_selector );
$window->add($button);
$window->show_all();

Gtk2->main;

sub dir_selector {
    my $d = Gtk2::FileChooserDialog->new(
        'Choose a Directory',
         $window, 'select-folder',
        "Cancel" => "cancel",
        "OK"     => "accept",
    );

    my $response = $d->run();
    if ( "accept" eq $response ) {
        print $d->get_filename(), "\n";
    }
    $d->destroy;
}
__END__


-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]