Part 8
Notebook
Creating the Glade
-
Open up glade8.glade and remove the labels from page 1 and 2 and replace them with a table. Put some labels in the table and two buttons.
Your project should look like this now.
-
Change the labels to Left and Right and add on_left_clicked and on_right_clicked' handlers to the clicked signal.
Your project should look like this now.
The Python
-
Open up glade8.py and add the following methods to the main class.
on_left_clicked
# this method is excuted for each press of any left button
def on_left_clicked(self, widget, data=None):
# get the current page number, page numbers start at 0
self.current_page = self.notebook.get_current_page()
if self.current_page > 0:
# get child widget contained in the page
self.child = self.notebook.get_nth_page(self.current_page)
# reorder the child widget to the left one page
self.notebook.reorder_child(self.child, self.current_page - 1)
else:
print 'At far left postion'
on_right_clicked
# this method is excuted for each press of any right button
def on_right_clicked(self, widget, data=None):
# get the current page number, page numbers start at 0
self.current_page = self.notebook.get_current_page()
# find out how many pages we have and subtract 1 because the page
# numbers start with 0
self.pages = self.notebook.get_n_pages() - 1
print self.pages
if self.current_page < self.pages:
# get child widget contained in the page
self.child = self.notebook.get_nth_page(self.current_page)
# reorder the child widget to the right one page
self.notebook.reorder_child(self.child, self.current_page + 1)
else:
print 'At far right position'
Now when you run the application you can move the pages to the left and right.
Your project should look like this now.
Next up is…