[pygtk] GtkNotebook problem (with broken code)

Randolph Bentson bentson@grieg.holmsjoen.com
Mon, 11 Sep 2000 23:42:33 -0700

Content-Type: text/plain; charset=us-ascii

First: I apologize if this is more of a GTK problem than a PyGtk
problem.  I haven't used GTK other than by Python, so it seems
best to start here.

I've bumped up against problems using GtkNotebook, for which I'd
appreciate any help I can get.

I would like to update the contents of a page of a notebook just
before it is displayed.  'page_callback' does just that in a trivial
manner, at least when it's connected to a button callback as shown
by #X# lines.  When I try the code below, page_callback falls into
a recursion hole at the line marked #<<<<<<<<<<<<<<<<.

I see two possible solutions: somehow call off the callback when
the page is removed and inserted, or find an entirely different
way to change the contents of what's being displayed on a page.
The problem is that I've found no examples or descriptions of how
either of these might be accomplished.

(I've considered mucking around inside a frame inside the page,
but don't see a clean way to get a handle on the right frame
(or is this what .get_data and .set_data are all about?))

Can anyone give me a hand?

Randolph Bentson

Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="switch.py"

#!/usr/bin/env python

from gtk import *
import GtkExtra

def page_callback(notebook, crap, page, cnt=[0], *args):
#X#def page_callback(btn, notebook, crap, page, cnt=[0], *args):
    cnt[0] = cnt[0] + 1

    box = GtkVBox()
    label = GtkLabel("Tab " + str(page))
    notebook.insert_page(box, label, page) #<<<<<<<<<<<<<<<


win = GtkWindow()
win.connect("destroy", mainquit)
win.connect("delete_event", mainquit)
box1 = GtkVBox(FALSE, 0)

button = GtkButton("close")
button.connect("clicked", mainquit)
box1.pack_end(button, expand=FALSE)

notebook = GtkNotebook()

notebook.connect("switch-page", page_callback)
#X#btn = GtkButton("change page 0")
#X#btn.connect('clicked', page_callback, notebook, 'crap', 0)

for i in range(2):
    box = GtkVBox()
    label = GtkLabel("Tab " + str(i))
    notebook.append_page(box, label)