Skip to content

Instantly share code, notes, and snippets.

@cfobel
Created December 1, 2014 15:02
Show Gist options
  • Save cfobel/d7a288a2445fcef5951d to your computer and use it in GitHub Desktop.
Save cfobel/d7a288a2445fcef5951d to your computer and use it in GitHub Desktop.
pygtk2 gtk.Assistant example

This gist includes a pygtk2 port of the gtk.Assistant example available here.

#!/usr/bin/env python
import gtk
def apply_button_clicked(assistant):
print("The 'Apply' button has been clicked")
def close_button_clicked(assistant):
print("The 'Close' button has been clicked")
gtk.main_quit()
def cancel_button_clicked(assistant):
print("The 'Cancel' button has been clicked")
gtk.main_quit()
def checkbutton_toggled(checkbutton):
assistant.set_page_complete(box1, checkbutton.get_active())
assistant = gtk.Assistant()
assistant.connect("cancel", cancel_button_clicked)
assistant.connect("close", close_button_clicked)
assistant.connect("apply", apply_button_clicked)
box = gtk.VBox()
assistant.append_page(box)
assistant.set_page_type(box, gtk.ASSISTANT_PAGE_INTRO)
assistant.set_page_title(box, "Page 1: Introduction")
label = gtk.Label("An 'Intro' page is the first page of an Assistant. It is used to provide information about what configuration settings need to be configured. The introduction page only has a 'Continue' button.")
label.set_line_wrap(True)
box.pack_start(label, True, True, 0)
assistant.set_page_complete(box, True)
box = gtk.VBox()
assistant.append_page(box)
assistant.set_page_type(box, gtk.ASSISTANT_PAGE_CONTENT)
assistant.set_page_title(box, "Page 2: Content")
label = gtk.Label("The 'Content' page provides a place where widgets can be positioned. This allows the user to configure a variety of options as needed. The page contains a 'Continue' button to move onto other pages, and a 'Go Back' button to return to the previous page if necessary.")
label.set_line_wrap(True)
box.pack_start(label, True, True, 0)
assistant.set_page_complete(box, True)
box1 = gtk.VBox()
age = assistant.append_page(box1)
assistant.set_page_type(box1, gtk.ASSISTANT_PAGE_PROGRESS)
assistant.set_page_title(box1, "Page 3: Progress")
label = gtk.Label("A 'Progress' page is used to prevent changing pages within the Assistant before a long-running process has completed. The 'Continue' button will be marked as insensitive until the process has finished. Once finished, the button will become sensitive.")
label.set_line_wrap(True)
box1.pack_start(label, True, True, 0)
checkbutton = gtk.CheckButton("Mark page as complete")
checkbutton.connect("toggled", checkbutton_toggled)
box1.pack_start(checkbutton, False, False, 0)
box = gtk.VBox()
assistant.append_page(box)
assistant.set_page_type(box, gtk.ASSISTANT_PAGE_CONFIRM)
assistant.set_page_title(box, "Page 4: Confirm")
label = gtk.Label("The 'Confirm' page may be set as the final page in the Assistant, however this depends on what the Assistant does. This page provides an 'Apply' button to explicitly set the changes, or a 'Go Back' button to correct any mistakes.")
label.set_line_wrap(True)
box.pack_start(label, True, True, 0)
assistant.set_page_complete(box, True)
box = gtk.VBox()
assistant.append_page(box)
assistant.set_page_type(box, gtk.ASSISTANT_PAGE_SUMMARY)
assistant.set_page_title(box, "Page 5: Summary")
label = gtk.Label("A 'Summary' should be set as the final page of the Assistant if used however this depends on the purpose of your Assistant. It provides information on the changes that have been made during the configuration or details of what the user should do next. On this page only a Close button is displayed. Once at the Summary page, the user cannot return to any other page.")
label.set_line_wrap(True)
box.pack_start(label, True, True, 0)
assistant.set_page_complete(box, True)
assistant.show_all()
gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment