Gtk::FileFilter

W

WoodHacker

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
 
A

akbarhome

WoodHacker said:
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

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.
 
W

WoodHacker

akbarhome said:
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.

Multiple adds did the trick. Thanks...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top