GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Nov 24, 2014 8:16 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Questions about filters on filechoosers
PostPosted: Mon Jun 16, 2008 2:27 pm 
Offline
GTK+ Guru

Joined: Sun Apr 06, 2008 6:43 pm
Posts: 286
Location: Fortress of solitude
I know how to add a single filter, like this:
Code:
fc = gtk.FileChooserDialog(title="Abrir...", action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
filter = gtk.FileFilter()
filter.set_name("Archivos python")
filter.add_pattern("*.py")
fc.add_filter(filter)

But how to add more patterns? For perls file for example? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 16, 2008 2:53 pm 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
you should be able to repeat your filter code, but 'filter' is a built-in python function, so you should use something like 'fil' instead
Code:
# your posted code
fil = gtk.FileFilter()
fil.set_name("Perl files (*.pl)")
fil.add_pattern("*.pl")
fc.add_filter(fil)
# repeat this for all your filters
or do:
Code:
patterns = [ ["Archivos python", "*.py"],
             ["Perl files", "*.pl"],
             ["Shell scripts", "*.sh"] ]
for p in patterns:
    fil = gtk.FileFilter()
    fil.set_name(p[0])
    fil.add_pattern(p[1])
    fc.add_filter(fil)
The second example will save you a lot of work


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 16, 2008 7:30 pm 
Offline
GTK+ Guru

Joined: Sun Apr 06, 2008 6:43 pm
Posts: 286
Location: Fortress of solitude
Thanks :)
That helped.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 8:22 pm 
Offline
GTK+ Guru

Joined: Sun Apr 06, 2008 6:43 pm
Posts: 286
Location: Fortress of solitude
Hi, in the same File dialog context, this is my way to get multiple files and place them in a textview wifget
Code:
sub OnButton1Clicked {
   my $fs = Gtk2::FileSelection->new("Abrir...");
   $fs->set_parent($Window); ## TODO: remove $fs from the taskbar
   $fs->set_select_multiple($TRUE); // my $TRUE = 1;
   my $response = $fs->run;
   if ($response eq "ok") {
      my $buffer = Gtk2::TextBuffer->new;
      foreach ($fs->get_selections) {
         $buffer->insert($buffer->get_end_iter, "$_");
         $buffer->insert($buffer->get_end_iter, "\n"); ## I want to remove this line
      }
      $text->set_buffer($buffer);
   }
   $fs->destroy;
}

Is there a way to use a single line of $buffer->insert to insert the filenames? Because if I remove the 2nd buffer->insert..all the path are padded in a single line, making a big textview :?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 18, 2008 6:15 pm 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
could you do:
Code:
foreach($fs->get_selections)
{
    $buffer->insert($buffer->get_end_iter, "$_" . "\n");
}

I don't use perl too often, but I think that this would work


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group