Re: FileSelection package




If I understend you right, your program need to wait until user
press on 'Ok' or 'Cancel' button and after that call the set_file function.
In this case I recommend you run new Gtk->main cycle in your open_file function
and connect on file_dialog destroy Gtk->main_quit. 
Step in to Gtk->main program will wait for user action, and after destroing
window it quit from Gtk->main with Gtk->main_quit.

In any case I attach my variant of your program, and you may to check it.

Good Luck.


On Fri, 19 Apr 2002, D. Gregory wrote:

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
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Attachment: example.pl
Description: Text document



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