4

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

v923z
  • 1,237
  • 5
  • 15
  • 25

1 Answers1

7

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!

another.anon.coward
  • 11,087
  • 1
  • 32
  • 38
  • 4
    Many thanks for the reply! It did solve the problem. But it just leaves me wondering where one could find these pieces of information. It seems to me that glade and gtk are developed at a faster pace than what the documentation can keep up with. – v923z Dec 03 '11 at 12:06