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 already added the listeners and etc, but I can't get the actual open dialog code to work. I think it is something to do with the difference between gtk and Gtk but I literally just started python yesterday. Here is my code as of now:

dialog = Gtk.FileChooserDialog("Open..",
                           None,
                           GTK_FILE_CHOOSER_ACTION_OPEN,
                           (Gtk.STOCK_CANCEL, Gtk.RESPONSE_CANCEL,
                            Gtk.STOCK_OPEN, Gtk.RESPONSE_OK))
    dialog.set_default_response(Gtk.RESPONSE_OK)

When the button is pressed, the console output this:

Traceback (most recent call last):
File "/home/nja/notetaker/notetaker/NotetakerWindow.py", line 61, in on_btn_open_clicked
self.open_file()
File "/home/nja/notetaker/notetaker/NotetakerWindow.py", line 41, in open_file
GTK_FILE_CHOOSER_ACTION_OPEN,
NameError: global name 'GTK_FILE_CHOOSER_ACTION_OPEN' is not defined

Also when GTK_FILE_CHOOSER_ACTION_OPEN is substituted for "0" (Which I believe is the int that constant points to) it works fine but it flags up the same error on Gtk.RESPONSE_CANCEL and Gtk.RESPONSE_OK

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You must replace:

  • GTK_FILE_CHOOSER_ACTION_OPEN with Gtk.FileChooserAction.OPEN
  • Gtk.RESPONSE_CANCEL with Gtk.ResponseType.CANCEL
  • Gtk.RESPONSE_OK with Gtk.ResponseType.OK

etc.

This is not PyGTK, it's GObject Introspection. You must build names as follows: Gtk.EnumTypeNameHere.VALUE

See https://live.gnome.org/PyGObject/IntrospectionPorting

share|improve this answer
    
Thank you. This worked perfectly! –  njallam Jun 21 '12 at 13:29
    
I will vote your answer up as soon as I have the sufficient reputation :) –  njallam Jun 21 '12 at 13:32
    
done. Thanks again for the help. –  njallam Jun 21 '12 at 14:26
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.