Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have added a GtkFileChooserButton to my app via Glade. It is set to folder selection mode. When the widget is clicked it shows a dropdown list of Nautilus bookmarks with an 'other' option in the end. A new file chooser dialog is launched when 'other' is clicked. The button is not connected to any other custom file chooser dialog.

The connecting signal I am using is 'file-set' and I am retrieving the fullpath of user selected folder using Gtk.FileChooser.get_current_folder ().

This setup works fine if user selects a folder from 'other' option. But if a user selects a bookmark from dropdown list, no path is returned. How to solve this?

Is there a way to disable this dropdown list and directly go to the filechooser dialog? I want to use GtkFileChooserButton only so that the user can get a preview of his selected folder.

share|improve this question
add comment

3 Answers

Because the file-set signal is only sent when the user changes the file, you will need to actually do the get_current_folder() call when you need to know the path, and not when the file-set signal is called. From the documentation, I see no way to get a notification when the user selects a path from the bookmarks, in folder selection mode.

As an alternative, though, you could use the FileChooserButton in normal mode, and simply use get_current_folder when the file-set signal is sent. This should give you the directory which the user is in, when a file is selected. Unfortunately, the UI will also look weird in this case, as the button will show the filename, while you're actually using the directory.

Also, you should probably file a bug against upstream GTK+ about this use case and how it isn't usable. The file-set signal really should be deprecated and renamed to path-set, and used in both modes.

share|improve this answer
    
Thanks for your suggestion. Unfortunately, a custom dialog attached to filechooserbutton also shows dropdown bookmarks. I wonder why dropdown bookmarks are always turned on when there is no signal for them. How are we supposed to capture user input? –  user8592 Jul 7 '12 at 5:46
    
Sorry. After re-reading the docs, it does appear that suggestion wouldn't work, so I've updated my answer with an alternate alternative solution, which should definitely work, but will have seemingly broken UI due to the behavior. –  dobey Jul 8 '12 at 14:22
    
Thanks again for your suggestion. I have solved the problem by using two widgets, a GtkEntry and a GtkButton. GtkButton is set on FileChooser 'folder select' mode. I retrieve user choice by using get_current_folder() and then set text to GtkEntry widget using set_text(). Not as elegant as FileChooserButton but it works. Here --> imgur.com/FMRIL –  user8592 Jul 8 '12 at 14:35
    
Ah, yes, that is also doable. Also, you could make a custom button widget that looks like a FileChooserButton, and does what you need. It would be very easy to do. –  dobey Jul 8 '12 at 15:39
add comment

I used the current_folder_changed signal inherited from GtkFileChooser and it seems to work even with the bookmarks.

share|improve this answer
    
This signal is also emitted when folders are changed while navigating the dialog, and before the chosen folder is accepted. Not desirable. –  Matt Joiner Oct 6 '12 at 15:40
    
I think at the moment it's the best solution / workaround. –  jP_wanN Jan 9 '13 at 20:50
add comment

This setup works fine if user selects a folder from 'other' option. But if a user selects a bookmark from dropdown list, no path is returned. How to solve this?

With GtkFileChooserButton, 'folder selection' mode. The following code is good enough:

def on_mybutton_selection_changed(self, w):
   print "selected folder: ", w.get_file().get_path()

We get directory path on every selection of the dropdown menu, even bookmarks.

I used the current_folder_changed signal inherited from GtkFileChooser and it seems to work even with the bookmarks.

Caution with w.get_current_folder(). It returns the LAST selected folder when user chose a folder from 'other' option, not the selected folder in the dropdown menu.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.