v923z
v923z

Reputation: 1247

using the filechooser dialog with glade

I would like to ask if anyone knows how to use the filechooser dialog in glade and pygtk. (It should be very similar in any of the language bindings, and that is why I didn't specify the language.) Basically, the filechooser now looks like this: there are two columns, one for the folders (left), and one for the files (right). Then at the bottom of the dialog, there are two empty slots for two buttons, so I just dropped a cancel and an OK button there. But then my question is what does the dialog return? My code looks like this:

    filename = None
    response = self.widget('filechooserdialog').run()
    print response
    #if response == Gtk.RESPONSE_OK: 
    filename = self.widget('filechooserdialog').get_filename()
    self.widget('filechooserdialog').hide()

and at the moment, the callback to 'Cancel' and 'OK' just hides the dialog. But I can't find out what the dialog is supposed to return. In other words, how can I specify in the response whether the 'Cancel', or the 'OK' button was pressed?

Thanks,

v923z

PS: Here is an image to illustrate the situation:

enter image description here

Upvotes: 4

Views: 5483

Answers (1)

another.anon.coward
another.anon.coward

Reputation: 11395

Dialog with buttons returns the response id which is associated with the button pressed. In your case, when you create your "Cancel" & "Ok" buttons in glade & drop them into empty slot available in the file chooser dialog, in the edit box (right bottom of the screen which will have heading like "Button Properties ...") you can see Response ID: option (its a spin button with default value as 0) under General tab. Just set that to a value you want to receive when that button is pressed. Set this as different values for your different buttons. Now when you run the dialog and the button is pressed you will get the response id value which you had set. Based on this you can take your actions.
Hope this helps!

Upvotes: 7

Related Questions