# Gtk::FileFilter

**URL:** <https://www.ruby-forum.com/t/gtk-filefilter/74657>\
**Category:** Ruby\
**Created:** [November 7, 2006, 10:51am UTC](https://www.ruby-forum.com/t/gtk-filefilter/74657 "2006-11-07T10:51:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![WoodHacker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ac8455/32.png) [@WoodHacker](https://www.ruby-forum.com/u/WoodHacker)\
**Post date:** [November 7, 2006, 10:51am UTC](https://www.ruby-forum.com/t/gtk-filefilter/74657/1 "2006-11-07T10:51:46Z")

</div>

Can anyone explain to me how the Gtk::FileFilter work in a  
FileChooserDialog? If I do the following, it works:

```
 filter.add_pattern("*.rb")

```

However, if I try: filter.add\_pattern("\*.{rb, txt}") it does not  
work. (As does nothing else I try)

And in the cases where it works (i.e. “\*.rb”) it gets a dropdown on the  
FileChooser that’s labeled “Untitled filter”. Pressing it does nothing.  
Obviously, I should be able to set the filter to rows labeled “All  
Files, Ruby Files, Text Files”, etc., with a default of say Ruby files  
to start with.

Thanks in advanced…

Bill

---

<div class="post-metadata">

**Author:** ![WoodHacker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ac8455/32.png) [@WoodHacker](https://www.ruby-forum.com/u/WoodHacker)\
**Post date:** [November 7, 2006, 10:52am UTC](https://www.ruby-forum.com/t/gtk-filefilter/74657/2 "2006-11-07T10:52:05Z")

</div>

WoodHacker wrote:

> Obviously, I should be able to set the filter to rows labeled “All  
> Files, Ruby Files, Text Files”, etc., with a default of say Ruby files  
> to start with.
> 
> Thanks in advanced…
> 
> Bill

Haven’t use Ruby Gtk, but I have use pygtk. Because python is ruby  
cousin, maybe my example in pygtk is useful to you.  
# image filter  
images\_type = (‘rgb’, ‘gif’, ‘pbm’, ‘pgm’, ‘ppm’, ‘tiff’, ‘rast’,  
‘xbm’, ‘jpeg’, ‘jpg’, ‘bmp’, ‘png’)  
imagefilter = gtk.FileFilter()  
for image\_type in images\_type:  
imagefilter.add\_pattern(’\*.’ + image\_type)  
imagefilter.set\_name(\_(“Images”))  
filechooser\_dialog.add\_filter(imagefilter)

```
# all files filter
allfilter = gtk.FileFilter()
allfilter.add_pattern("*")
allfilter.set_name(_("All files"))
filechooser_dialog.add_filter(allfilter)

```

My guess is you have to do once for each pattern:  
filter.add\_pattern("_.rb")  
filter.add\_pattern("_.txt")

My understanding is you want a filter for ruby files and text files.  
The case will be different if you want to use ruby files filter and  
text files filter. Notice the different.

---

<div class="post-metadata">

**Author:** ![WoodHacker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ac8455/32.png) [@WoodHacker](https://www.ruby-forum.com/u/WoodHacker)\
**Post date:** [November 7, 2006, 10:53am UTC](https://www.ruby-forum.com/t/gtk-filefilter/74657/3 "2006-11-07T10:53:31Z")

</div>

akbarhome wrote:

> > FileChooser that’s labeled “Untitled filter”. Pressing it does nothing.  
> > # image filter  
> > allfilter.add\_pattern("\*")  
> > allfilter.set\_name(\_(“All files”))  
> > filechooser\_dialog.add\_filter(allfilter)
> 
> My guess is you have to do once for each pattern:  
> filter.add\_pattern("_.rb")  
> filter.add\_pattern("_.txt")
> 
> My understanding is you want a filter for ruby files and text files.  
> The case will be different if you want to use ruby files filter and  
> text files filter. Notice the different.

Multiple adds did the trick. Thanks…
