PyGTK notebook: get current page

Tracubik affdfsdfdsfsd at b.com
Sat May 7 11:04:22 EDT 2011


Hi all!
I've made a simple PyGTK program.
It's a window with a notebook, the notebook have 2 pages
When changing page, i'ld like to get the id of current page.

I've coded it, but i can get only the previously open page, not the 
current one. This is not a big deal if i have only 2 pages, but it could 
be with 3 or more pages.

Here's the code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# template di finestra in pyGTK

import pygtk
pygtk.require('2.0')
import gtk

class FinestraGTK:

    def pippo(self, widget, event, data=None):
        print "current page: " + str(self.nb.get_current_page() )

    def delete_event(self, widget, event, data=None):
        print "delete event occurred"
        return False

    def destroy(self, widget, data=None):
        print "destroy signal occurred"
        gtk.main_quit()

    def __init__(self):
        self.w = gtk.Window(gtk.WINDOW_TOPLEVEL)
    
        self.w.connect("delete_event", self.delete_event)
        self.w.connect("destroy", self.destroy)
    
        self.w.set_border_width(10)
        self.w.set_default_size(455,460)
        
        # NOTEBOOK + LABELS
        self.nb = gtk.Notebook()
        self.nb_label1 = gtk.Label("page 0")
        self.nb_label2 = gtk.Label("page 1")
        
        # PAGE 1
        self.b1 = gtk.Button("button tab 0")
        self.nb.insert_page(self.b1, self.nb_label1, 0)
        # PAGE 2
        self.b2 = gtk.Button("button tab 1")
        self.nb.insert_page(self.b2, self.nb_label2, 1)
        
        self.w.add(self.nb)
        self.nb.connect("switch-page", self.pippo)
        self.b1.connect("clicked", self.pippo, "")
        self.b2.connect("clicked", self.pippo, "")

        self.w.show_all()

    def main(self):
        gtk.main()

if __name__ == "__main__":
    hello = FinestraGTK()
    hello.main()


any hint? i know it's all about correctly temporize signals, but i don't 
know how to accompliesh this

many thanks
regards
sorry for my english
Nico



More information about the Python-list mailing list