FileSelection package



Hi, 
I'm a newbie too with gtk ;)
That's why a subscribe to the list, but for a long time :)

I have to build a little big programm, not a simple script, so i would create more globals class/objects. I 
start to make a class, to manage file's open/close via FileSelection:

package FileOp;

use strict;

sub new
{
        my ($self,@args) = @_ ;
        my $data;
        $data->{file} = "";
        return bless $data,$self;
}

sub set_file
{
        my ($self,$f) = @_ ;
        print "Set file $f \n";
        $self->{file}=$f;
}

sub get_file
{
        my ($self) = @_ ;
        return $self->{file};
}

# action for open button
sub open_file
{
        my ($self,$file) = @_ ;
        # Create a new file selection widget
        my $file_dialog = new Gtk::FileSelection( "Ouvrir un fichier XML" );
        my $filename;
        #$file_dialog->signal_connect( "destroy", sub { $file_dialog->destroy( ); } );

        # Connect the ok_button to file_ok_sel function
        $file_dialog->ok_button->signal_connect( "clicked", 
                                                                                        sub 
                                                                                        { 
                                                                                                
$filename=$file_dialog->get_filename();
                                                                                                
$file_dialog->destroy(); 
                                                                                                set_file 
($self,$filename);
                                                                                        }, $self );

        # Connect the cancel_button to destroy the widget
        $file_dialog->cancel_button->signal_connect( "clicked", 
                                                                                                sub 
                                                                                                { 
                                                                                                        
$filename=undef;
                                                                                                        
$file_dialog->destroy(); 
                                                                                                } );

        # Lets set the filename, as if this were a save dialog, and we are giving
        # a default filename
        $file_dialog->set_filename( $file );
        $file_dialog->set_modal(1);
        $file_dialog->set_position('center');
        $file_dialog->show();

}

1;


It works fine, but you know that i have a problem ! When i call this class, like it:
#create object
my $fileop=new XMLProject::FileOp();
#open fileselection
$fileop->open_file($logfile);
# get file
my $filename=$fileop->get_file();
# print output
print "Get $filename\n";

It prints:
$ Get
$ Set file /home/greg/toto.xml

"It's normal" we can say.
It print "Set file..." after i press the "valid" button, so my question is how to determine when a 
window/file selection is destroy, or how to wait for it to return a value.

Thanks for your help.
--
Greg



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