With this program:

  from gtk import *

  def button_press(widget, event):
    if event.button == 3:
      menu = GtkMenu()
      menu.append(GtkMenuItem('foo'))
      menu.append(GtkMenuItem('bar'))
      menu.popup(widget, None, None, event.button, event.time)

  window = GtkWindow(WINDOW_TOPLEVEL)
  window.connect('destroy', mainquit)

  button = GtkButton('foo')
  button.connect('button-press-event', button_press)
  window.add(button)

  button.show()
  window.show()

  mainloop()

I run the program, then right-click on the button, and I get this:

  [pbrannan@zaphod python]$ python test.py
  Segmentation fault (core dumped)

Looking at this in gdb, I see:

  Program received signal SIGSEGV, Segmentation fault.
  [Switching to Thread 1024 (LWP 23769)]
  0x4028e1d7 in gtk_menu_popup () from /usr/lib/libgtk-1.2.so.0
  (gdb) bt
  #0  0x4028e1d7 in gtk_menu_popup () from /usr/lib/libgtk-1.2.so.0
  #1  0x401be26a in _wrap_gtk_menu_popup (self=0x0, args=0x8123fec)
      at gtkmodule.c:5084
  #2  0x08059702 in call_cfunction (func=0x813e930, arg=0x8123fec, kw=0x0)
      at Python/ceval.c:2845
  ...

I have no idea what's causing self=0x0, but I suspect that's why the
program is segfaulting.

A couple of questions:

  1) Is there an easier way to get a popup menu?
  2) How can I rewrite the above code to not segfault?

Thanks,

Paul

_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk

Reply via email to