[pygtk] Problem with notebook page switching in Windows thread

Jamie Norrish jamie at artefact.org.nz
Mon Nov 8 12:14:51 WST 2004


On a Win2K box using the latest PyGTK and gladewin32 GTK+ runtime, I
get a complete application freeze when running
notebook.set_current_page() inside a thread, if the notebook is not
currently on the page that's set in the call. Since I don't have my
own Windows box I didn't have the chance to test whether any other
forms of page switching caused the same problem. The behaviour does
not occur when the call is made outside a thread, or at all using
Debian GNU/Linux's unstable packages.

Here's a minimal test case:

#!/usr/bin/env python

import gtk
from threading import Thread

class Test (Thread):
    def __init__ (self, notebook):
        Thread.__init__(self)
        self.notebook = notebook

    def run (self):
        gtk.threads_enter()
        self.notebook.set_current_page(1)
        gtk.threads_leave()

def start_new_thread (data=None):
    a = Test(notebook)
    a.start()

def destroy(*args):
    window.hide()
    gtk.main_quit()

# Initialize threads
gtk.threads_init()

window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect("destroy", destroy)
window.set_border_width(10)

vbox = gtk.VBox()

notebook = gtk.Notebook()
notebook.set_tab_pos(gtk.POS_TOP)
notebook.set_border_width(2)
page1 = gtk.ScrolledWindow()
page2 = gtk.ScrolledWindow()
notebook.append_page(page1)
notebook.append_page(page2)

button = gtk.Button("  Switch Tab  ")
button.connect("clicked", start_new_thread)
vbox.add(button)
vbox.add(notebook)
window.add(vbox)
window.show_all()

gtk.threads_enter()
gtk.main()
gtk.threads_leave()


Jamie
-- 
Artefact Publishing: http://www.artefact.org.nz/
GnuPG Public Key: http://www.artefact.org.nz/people/jamie.html


More information about the pygtk mailing list