gnocl::assistant

WJG (19/05/09) The 2.10 release of Gtk saw the introduction of a number of new widgets and features into the core widget set. One of these is a preplacement for the deprecated GnomeDruid. The assistant widget allows the programmer to guide a user through a number of interactive steps in order to determine an outcome. Whilst at the time of writing this widget is still pre-release, here's a glimpse of the gnocl::assistant test script and how it can be used. As always, comments and feedback always welcome.

http://wjgiddings.googlepages.com/Screenshot-AssistantTest.tcl.png

#---------------
# AssistantTest.tcl
#---------------
# Author:   William J Giddings
# Date:     07/05/09
#---------------
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "[email protected]"
#---------------

package require Gnocl

proc gotoPage {w p} {
    gnocl::signalStop $w prepare
    $w page set $p
}

#---------------
# create widget
#---------------
set wid [ gnocl::assistant \
    -linear no \
    -onDelete { exit } \
    -onCancel { puts "Cancel %w %n" ; exit} \
    -onClose  { puts "Close %w %n" ; exit} \
    -onApply  { puts "Apply %w %n" } \
    -onPrepare  {
        puts "Prepare %w %n %p"
        #catch { puts "Page = $page(%n)" }
        #    $page(%n) configure -text "GATE GATE PARAGATE PARASAMGATE BODHI SVAHA"
        if {%n == 3 } {
                puts "PING"
                $wid configure -linear no
        }
        } \
    -resizable 0 \
    -keepAbove 1 \
    -modal 1 \
    -widthRequest 640 \
    -heightRequest 400 \
    -backgroundColor red \
    ]

# -backgroundImage gnocl_logo_sml.png \

# problems arising from this block of code.
if (0) {
$wid forward 1
}

#---------------
# Add some sample action buttons
#---------------
set ab(1) [gnocl::button -text "AB1" -onClicked {$wid page set 1}]
set ab(2) [gnocl::button -text "AB2"]
set ab(3) [gnocl::button \
    -text "Reset Defaults" \
    -onClicked {
        puts "currentpage = [$wid currentPage]"
        $wid page set 4
        #$wid removeWidget %w
        } ]

set abuttons [gnocl::box -homogeneous 1 -padding 0]
$abuttons add [list $ab(1) $ab(2) $ab(3)] -fill {1 1} -expand 1

$wid addWidget $abuttons

#---------------
# add pages
#---------------
$wid addPage intro      "Gnocl Assistant Widget"
$wid addPage content    "Step 1) Make a Choice"
$wid addPage content    "Step 2) Think of Something Else"
$wid addPage progress   "Step 3) Change it, then"
$wid addPage confirm    "Step 4) Do It!"
$wid addPage summary    "Finnished!"

#---------------
# set some defaults
#---------------
set sidebar(default) Porky_pig.jpg
set header(default) banner.png

#---------------
# set default graphics for each page
#---------------
for {set i 0} {$i < [$wid pages] } { incr i } {
    set header($i)  $header(default)
    set sidebar($i) $sidebar(default)
}

#---------------
# create page contents
# overide default for header & sidebar images
# define proceedure associate with the page
#---------------

#---------------
# page 0
#---------------
set page(0) [gnocl::image -image "%/WarnerBros.jpg" ]

proc action(0) {args} {
    puts "$args"
}

#---------------
# page 1
#---------------
set page(1) [gnocl::label -text "OM MANI PADME HUM"]
set sidebar(1) Bugs_Bunny.jpg

proc action(0) {args} {
    puts "$args"
}

#---------------
# page 2
#---------------
set but1 [gnocl::button -text "Daffy Duck"]
set but2 [gnocl::button -text "Bugs Bunny"]
set but3 [gnocl::button -text "Wily Coyote"]
set but4 [gnocl::button -text "Porky Pig"]

set page(2) [gnocl::box -orientation vertical ]
$page(2) add [list $but1 $but2 $but3 $but4] -fill {1 1} -expand 1

proc action(2) {args} {
    puts "$args"
}

#---------------
# page 3
#---------------
set page(3) [gnocl::label -text "OM MANI PADME HUM"]

proc action(3) {args} {
    puts "$args"
}


#---------------
# page 4
#---------------
set page(4) [gnocl::label -text "OK, this is the last page.\nDo it, or cancel!"]
set sidebar(4) Daffy_duck.jpg

proc action(4) {args} {
    puts "$args"
}

#---------------
# page 5
#---------------
set page(5) [gnocl::label -text "Job Completed.\nWell Done!" -baseFont {Sans 18}]
set sidebar(5) ThatsAllFolks.jpg

proc action(5) {args} {
    puts "$args"
}

#---------------
# configure pages in one swoop!
#---------------

for {set i 0} {$i < [$wid pages] } { incr i } {
    $wid page configure $i -child $page($i) -headerImage $header($i) -sidebarImage $sidebar($i)
}

gnocl::mainLoop

#---------------