English 中文(简体)
Can you set the FileFilters for a Gtk Dialog in Glade?
原标题:

In my code, I have lines like this:

Builder builder = new Builder();
builder.AddFromFile(gladefile);
FileChooserDialog dialog =
    (FileChooserDialog) builder.GetObject("dialog");

FileFilter[] filters = new FileFilter[2];
filters[0] = new FileFilter();
filters[0].Name = "Some filter";
filters[0].AddPattern("*.someextension");
filters[1] = new FileFilter();
filters[1].Name = "All files";
filters[1].AddPattern("*");

foreach (FileFilter filter in filters)
    dialog.AddFilter(filter);
dialog.Filter = filters[0];
dialog.SetFilename(defaultFile);

Is there a way to set up these filters in Glade, rather than doing it manually?

最佳回答

No. You can create a file filter object in glade (version 3.6 and up) and add it to the dialog, but since you can t actually set the name or pattern of the file filter, it s fairly useless.

问题回答

It is possible now. The code snippet should probably look something like this:

    builder = Gtk.Builder()
    builder.add_objects_from_file("***name of glade file****.glade",
        ("filechooserdialog1", "filefilter1"))
    dialog = self.builder.get_object("filechooserdialog1")
    filefilter = self.builder.get_object("filefilter1")
    dialog.add_filter(filefilter)

enter image description here

enter image description here





相关问题
Pointers in Lisp?

I ve started learning Lisp recently and wanted to write a program which uses gtk interface. I ve installed lambda-gtk bindings (on CMUCL). I want to have putpixel/getpixel ability on a pixbuf. But I ...

In Gtk, how do I make a Button with just a stock icon?

I want to create a button with the stock "Remove" icon on it, but without the text "Remove". If I use Button button = new Button(Stock.Remove);, I get the opposite: just the text, and no icon. I will ...

Using GtkMenu in Gtk+-2.14.0

I am building an application which has GtkMenu widget. I am using Glade RAD tool to develop UI and while creating project in Glade I have specified version of GTK as 2.16 which supports GtkMenu and ...

Can you set the FileFilters for a Gtk Dialog in Glade?

In my code, I have lines like this: Builder builder = new Builder(); builder.AddFromFile(gladefile); FileChooserDialog dialog = (FileChooserDialog) builder.GetObject("dialog"); FileFilter[] ...

热门标签