#!/usr/bin/env python
import gtk
class Assistant:
def __init__(self):
assistant = gtk.Assistant()
assistant.connect("apply", self.button_pressed, "Apply")
assistant.connect("cancel", self.button_pressed, "Cancel")
vbox = gtk.VBox()
vbox.set_border_width(5)
page = assistant.append_page(vbox)
assistant.set_page_title(vbox, "Page 1: Starting Out")
assistant.set_page_type(vbox, gtk.ASSISTANT_PAGE_INTRO)
label = gtk.Label("""This is an example label within an Assistant. The
Assistant is used to guide a user through configuration of an
application.""")
label.set_line_wrap(True)
vbox.pack_start(label, True, True, 0)
assistant.set_page_complete(vbox, True)
vbox = gtk.VBox()
vbox.set_border_width(5)
assistant.append_page(vbox)
assistant.set_page_title(vbox, "Page 2: Moving On...")
assistant.set_page_type(vbox, gtk.ASSISTANT_PAGE_CONTENT)
label = gtk.Label("""This is an example of a label and checkbox within a
page. If this box is checked, the assistant will skip page 3.""")
label.set_line_wrap(True)
self.checkbutton = gtk.CheckButton("Skip next page")
vbox.pack_start(label, True, True, 0)
vbox.pack_start(self.checkbutton, False, False, 0)
assistant.set_page_complete(vbox, True)
vbox = gtk.VBox()
vbox.set_border_width(5)
assistant.append_page(vbox)
assistant.set_page_title(vbox, "Page 3: The skipped page")
assistant.set_page_type(vbox, gtk.ASSISTANT_PAGE_CONTENT)
label = gtk.Label("""This is an example of a page that contains
information that may be skipped depending on the status of
the previous pages.""")
label.set_line_wrap(True)
button = gtk.Button("Button Example")
vbox.pack_start(label, True, True, 0)
vbox.pack_start(button, False, False, 0)
assistant.set_page_complete(vbox, True)
vbox = gtk.VBox()
vbox.set_border_width(5)
assistant.append_page(vbox)
assistant.set_page_title(vbox, "Page 4: The Finale")
assistant.set_page_type(vbox, gtk.ASSISTANT_PAGE_CONFIRM)
label = gtk.Label("""This is the final page of the Assistant widget. It
could be used to confirm the preferences we have
set in the previous pages.""")
label.set_line_wrap(True)
vbox.pack_start(label, True, True, 0)
assistant.set_page_complete(vbox, True)
assistant.show_all()
# Set an alternative function to return the next page to go to
assistant.set_forward_page_func(self.pageforward)
def pageforward(self,page):
"""
Function called when the forward button is pressed,
Arguments:
page:
integer index of the current page
returns:
integer index of the next page to display
"""
if page == 1 and self.checkbutton.get_active():
return 3
else:
return page+1
def button_pressed(self, assistant, button):
print "%s button pressed" % button
gtk.main_quit()
Assistant()
gtk.main()
Comments
I would love to know what you think. To comment on this article, send me an email
No comments yet.