Moose has this nice library for building wizards called Merlin. Unfortunately there’s really no documentation apart from couple of examples. Because I need to use this library (I’m sick of creating forms by hand like some kind of animal…), I might as well publish my notes.
Installation
Merlin is available by default in the Moose distribution; for regular Pharo install it via Metacello.
|
|
Composition
As you can see in the introductory image, the UI consists of three parts:
WizardControl— the main containerWizardPane— a single step of the wizardWizardPart— a single item in a pane
|
|
So you basically create an instance of WizardControl, add to it a bunch of WizardPanes, and each pane populate with WizardParts.
Creating a wizard
1. WizardControl
To start creating a new wizard, you need an instance of WizardControl.
|
|
With that, you are interested mainly in these three methods:
addPane:to add a new paneopento open the wizardatEndDo: aOneArgBlockthat will be evaluated when the wizard finished
Alternatively to atEndDo: you can also use wizardInformations. Both will provide you with a Dictionary containing the value of each individual Part.
2. WizardPane
Now you need to populate the wizard with panes.
|
|
There are several choices for a WizardPane:
WizardSinglePane— used only if the wizard has a single pane; adds the Finish buttonWizardFirstPane— first pane of a multipane wizard; adds the Next buttonWizardMiddlePane— middle pane; has the Back and Next buttonsWizardLastPane— last pane; has the Back and Finish buttonsWizardMessagePane— ¯\_(ツ)_/¯
Just make sure you are adding the panes in the correct order (first, middle*, last) XOR (single).
You can also name the pane with pane name: 'My Pane' (it will appear as the title of the wizard for the active pane).
3. Adding Parts
To add parts to a pane, use one of the following methods
addPart:associatedTo:addPart:associatedTo:requiring:column:associatedTo:column:associatedTo:requiring:row:associatedTo:row:associatedTo:requiring:
associatedTo: takes a symbol under which you can retrieve the value (output) of the part in atEndDo: (see WizardControl).
requiring: takes a list of symbols this Part needs to operate
addPart: takes an instance of WizardPart, and
column: or row: takes either a part, or a block, e.g.
|
|
With a combination of row: and column: you can customize the layout of the wizard to your needs.
4. WizardPart
Finally you have a wealth of WizardParts: checkboxes, file inputs, text inputs, etc. Not much point going through them one by one, look at the API to see how each should be used.
|
|
Two methods common to all parts that might be interesting:
inGroupboxNamed: aString— a label container around the inputdefaultValue: aValueOrBlock— a default value or a one arg block of required inputs
|
|
More examples
To see the wizard in action, it’s best to download the latest Moose image from Moose site and take a look at the subclasses of WizardControl and at the class-side of MerlinExamples.