5

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

2

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

| improve this answer | |
  • I will vote your answer up as soon as I have the sufficient reputation :) – njallam Jun 21 '12 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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