[Tutor] Dialogs
kreglet
kreglet at gmail.com
Tue Oct 13 22:10:39 CEST 2009
I am having a problem with GtkDialogs.
Ref: http://faq.pygtk.org/index.py?req=show&file=faq10.011.htp
http://faq.pygtk.org/index.py?req=show&file=faq10.011.htp
I want to add a treeview to the dialog.
The first time btnDialog is pressed the dialog shows with the treeview in
it.
If I press btnDialog a second time the app closes and I get a "Segmentation
fault" error.
Without adding the treeview, the dialog works as expected.
Do you have to destroy the widgets added to a dialog when you destroy the
dialog?
If so how?
#!/usr/bin/env python
import pygtk
import gtk
btnDialog = gtk.Button("Dialog")
# list of items to display
plist = gtk.ListStore(int, str)
plist.append( (0, "Item 1",) )
plist.append( (1, "Item 2",) )
plist.append( (2, "Item 3",) )
# the Treeview
treeview = gtk.TreeView()
model = treeview.get_selection()
model.set_mode(gtk.SELECTION_SINGLE)
r = gtk.CellRendererText()
treeview.insert_column_with_attributes(-1, "Items", r, text=1)
treeview.set_model(plist)
class NewWindow(gtk.Window):
def btnDialogClick(self, widget):
dialog = gtk.Dialog('Choose Item',
self, # the window that spawned this dialog
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
("Play Now", 77, gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))
dialog.vbox.pack_start(gtk.Label('Do you want to play a game?'))
dialog.vbox.pack_start(treeview)
dialog.show_all()
result = dialog.run()
if result == 77:
print "Play Button Clicked"
elif result == gtk.RESPONSE_CLOSE:
print "Close Button Clicked"
dialog.destroy()
#----------------------------------------------------------------
def __init__(self):
super(NewWindow, self).__init__()
self.set_title("test")
self.set_size_request(1024, 768)
self.set_keep_above(True)
self.set_position(gtk.WIN_POS_CENTER)
self.set_modal(True)
fixed = gtk.Layout()
fixed.put(btnDialog, 400, 5)
btnDialog.connect("clicked", self.btnDialogClick)
self.add(fixed)
self.connect("destroy", gtk.main_quit)
self.show_all()
NewWindow()
gtk.main()
--
View this message in context: http://www.nabble.com/Dialogs-tp25879937p25879937.html
Sent from the Python - tutor mailing list archive at Nabble.com.
More information about the Tutor
mailing list