[pygtk] (no subject)

PEYMAN ASKARI paskari007 at yahoo.ca
Wed Mar 3 20:28:34 WST 2010


Hello

Does anyone know how to limit the number of tabs in a notebook, much like gedit does?

Here is a minimal example. Run it, and keep hitting the '+' button, and the window just keeps growing to keep up with the number of tabs.

Cheers


Peyman Askari

#!/usr/bin/env python

import sys
try:
    import pygtk
    pygtk.require("2.0")
except:
    pass
try:
    import gtk
    import gtk.glade
except:
    sys.exit(1)
import gtksourceview

window=gtk.Window()
        
def make_notebook():
    global topology_blocked
    global window

    window.connect('destroy',on_main_window_destroy)
    window.connect('delete_event',on_main_window_delete_event)
    
    vBox=gtk.VBox()

    button=gtk.Button('+')

    notebook=gtk.Notebook()
    notebook.set_tab_pos(gtk.POS_TOP)

    button.connect('clicked',add_tab,notebook)

    vBox.pack_start(notebook,expand=True,fill=True,padding=5)
    vBox.pack_start(button,expand=False,fill=False,padding=0)
    
    window.add(vBox)

    window.show_all()

def add_tab(button,notebook):
    label=gtk.Label('Hola')
    vBox=gtk.VBox()
    notebook.append_page(vBox,label)

    label.show()
    vBox.show()
    
def on_main_window_delete_event(widget,data=None):
    """Return false so the window gets destroyed
    """
    return False

def on_main_window_destroy(widget,data=None):
    """Return false so the window gets destroyed
    """
    gtk.main_quit()

if __name__ == '__main__':

    try:
        make_notebook()


        gtk.main()
    except KeyboardInterrupt:
        sys.exit(1)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20100303/a2b1cd18/attachment.htm 


More information about the pygtk mailing list