dpitch40
dpitch40

Reputation: 2691

PyGTK Notebook get_current_page() not working

I am using a gtk.Notebook widget for the first time and trying to get my application to "remember" the page it was turned to when I quit. However, the get_current_page method doesn't appear to be working. This code:

self.notebook = gtk.Notebook()
self.singleFilePane = gtk.Label("Single File")
self.notebook.append_page(self.singleFilePane, gtk.Label("Single File"))
self.multiFilePane = gtk.Label("Multiple Files")
self.notebook.append_page(self.multiFilePane, gtk.Label("Multiple Files"))
print self.notebook.get_n_pages(), self.notebook.get_current_page()

Prints the following output:

2 -1

The -1 result from notebook.get_current_page is supposed to mean the Notebook has no pages, but obviously it does because I just added them, and get_n_pages agrees. I can't see what, if anything, I could be doing wrong here; is this a bug?

Upvotes: 1

Views: 493

Answers (1)

desowin
desowin

Reputation: 188

The gtk.Notebook has not been shown so the current page has not been set yet. Following code shows the notebook by adding it to toplevel window.

self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.notebook = gtk.Notebook()
self.singleFilePane = gtk.Label("Single File")
self.notebook.append_page(self.singleFilePane, gtk.Label("Single File"))
self.multiFilePane = gtk.Label("Multiple Files")
self.notebook.append_page(self.multiFilePane, gtk.Label("Multiple Files"))
self.window.add(self.notebook)
self.window.show_all()
print self.notebook.get_n_pages(), self.notebook.get_current_page()

This prints

2 0

Upvotes: 2

Related Questions