1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
#------------------------------------------------------------------------------
# Copyright (c) 2005, Enthought, Inc.
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in enthought/LICENSE.txt and may be redistributed only
# under the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
# Thanks for using Enthought open source!
#
# Author: Enthought, Inc.
# Description: <Enthought pyface package component>
#------------------------------------------------------------------------------
""" The interface for all pyface wizards. """
# Enthought library imports.
from enthought.traits.api import Bool, Instance, List, Unicode
from enthought.pyface.i_dialog import IDialog
# Local imports.
from i_wizard_controller import IWizardController
from i_wizard_page import IWizardPage
class IWizard(IDialog):
""" The interface for all pyface wizards. """
#### 'IWizard' interface ##################################################
# The pages in the wizard.
pages = List(IWizardPage)
# The wizard controller provides the pages displayed in the wizard, and
# determines when the wizard is complete etc.
controller = Instance(IWizardController)
# Should the 'Cancel' button be displayed?
show_cancel = Bool(True)
#### 'IWindow' interface ##################################################
# The dialog title.
title = Unicode('Wizard')
###########################################################################
# 'IWizard' interface.
###########################################################################
def next(self):
""" Advance to the next page in the wizard. """
def previous(self):
""" Return to the previous page in the wizard. """
class MWizard(object):
""" The mixin class that contains common code for toolkit specific
implementations of the IWizard interface.
Implements: next(), previous()
Reimplements: _create_contents()
"""
###########################################################################
# 'IWizard' interface.
###########################################################################
def next(self):
""" Advance to the next page in the wizard. """
page = self.controller.get_next_page(self.controller.current_page)
self._show_page(page)
return
def previous(self):
""" Return to the previous page in the wizard. """
page = self.controller.get_previous_page(self.controller.current_page)
self._show_page(page)
return
###########################################################################
# Protected 'IWindow' interface.
###########################################################################
def _create_contents(self, parent):
""" Creates the window contents. """
# This creates the dialog and button areas.
super(MWizard, self)._create_contents(parent)
# Wire up the controller.
self._initialize_controller(self.controller)
# Show the first page.
self._show_page(self.controller.get_first_page())
return
###########################################################################
# Protected MWizard interface.
###########################################################################
def _show_page(self, page):
""" Show the specified page. """
# Set the current page in the controller.
#
# fixme: Shouldn't this interface be reversed? Maybe calling
# 'next_page' on the controller should cause it to set its own current
# page?
self.controller.current_page = page
def _update(self):
""" Enables/disables buttons depending on the state of the wizard. """
pass
###########################################################################
# Private interface.
###########################################################################
def _initialize_controller(self, controller):
""" Initializes the wizard controller. """
controller.on_trait_change(self._update, 'complete')
controller.on_trait_change(
self._on_current_page_changed, 'current_page'
)
return
#### Trait event handlers #################################################
def _on_current_page_changed(self, obj, trait_name, old, new):
""" Called when the current page is changed. """
if old is not None:
old.on_trait_change(self._update, 'complete', remove=True)
if new is not None:
new.on_trait_change(self._update, 'complete')
self._update()
return
def _on_closed_changed(self):
""" Called when the wizard is closed. """
self.controller.dispose_pages()
return
#### EOF ######################################################################
|