Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing GtkFileChooser

Tags:

gtk

GTK+ noob question here:

Would it be possible to customize the GtkFileChooserButton or GtkFileChooserDialog to remove the 'Places' section (on the left) and the 'Location' entry box on the top?

What I'm essentially trying to do is to allow the user to select files only from a particular folder (which I set using gtk_file_chooser_set_current_folder ) and disable navigating to other locations on the file system.

This is the standard file chooser dialog : The standard GtkFilechooser Dialog

This is what I need: enter image description here

like image 698
itisravi Avatar asked Jul 08 '11 14:07

itisravi


2 Answers

It doesn't look like that is possible with the standard file chooser dialog. For example, here is a document discussing why such a thing would be useful and how it could be implemented, but the idea never made it to fruition.

What you can do, perhaps, is write your own dialog that implements the GtkFileChooser interface, based on the GtkFileChooserDialog code, but hides the location bar and bookmarks list.

like image 166
ptomato Avatar answered Oct 20 '22 06:10

ptomato


You can get a handle on the individual children by finding out where there are with gtkparasite and then accessing them with get_children.

Make sure to use .show() instead of .run() for inspecting the dialog with gtkparasite. If you use .run() the dialog is shown in modal mode so you can't inspect it.

For example I hide the Path and Places widgets with the statements below:

dialog = gtk.FileChooserDialog("Open***", None, gtk.FILE_CHOOSER_ACTION_OPEN,
            (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN, gtk.RESPONSE_OK))
dialog.set_show_hidden(True)
dialog.set_default_response(gtk.RESPONSE_OK)       
vbox = dialog.get_children()[0].get_children()[0].get_children( [0].get_children()[0]
vbox.get_children()[0].hide()
vbox.get_children()[2].get_children()[0].hide()

Of course this is not an exposed API so it can always break from underlying changes.

Hope it makes sense ...

Tried to post an image but I am a new user ....

like image 33
dkor Avatar answered Oct 20 '22 05:10

dkor