Gtk::FileFilter

Discussion in 'Ruby' started by WoodHacker, Nov 1, 2006.

  1. WoodHacker

    WoodHacker Guest

    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
    WoodHacker, Nov 1, 2006
    #1
    1. Advertising

  2. WoodHacker

    akbarhome Guest

    WoodHacker wrote:
    > 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.
    akbarhome, Nov 1, 2006
    #2
    1. Advertising

  3. WoodHacker

    WoodHacker Guest

    akbarhome wrote:
    > WoodHacker wrote:
    > > 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.


    Multiple adds did the trick. Thanks...
    WoodHacker, Nov 2, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sebastian Hoehn

    Re: FileFilter

    Sebastian Hoehn, Jun 29, 2003, in forum: Java
    Replies:
    1
    Views:
    2,311
  2. P.Hill
    Replies:
    6
    Views:
    6,319
    P.Hill
    Nov 18, 2003
  3. Frank
    Replies:
    5
    Views:
    507
    Andrew Thompson
    Jan 14, 2005
  4. Replies:
    0
    Views:
    407
  5. Replies:
    2
    Views:
    520
Loading...

Share This Page