Desktop Slide Show

WJG (06/Sep/10) The development of the Gnocl Tcl/Gtk bindings is moving along well and the recently added gnocl::pixBuf object offers a great deal to those application developers who want fast and flexible manipulation full colour graphics. Last night I thought it was about time that I had a desktop slideshow gadget that would read the contents of an album directory. It took me less that half an hour to get the whole lot running. Here's the script:

#---------------
# photoAlbumGadget.tcl
#---------------
# Produce a desktop slideshow.
#---------------
# William J Giddings
# 05/09/2010
#---------------

#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

package require Gnocl

#---------------
#
#---------------
proc init {} {
        set ::dt 3000
        set ::size {200 150}
        set ::i 0
        set ::first 1

        # create a list of images
        set ::album [glob ./album/*]
}

#---------------
#
#---------------
proc slideChange {} {
        incr ::i
        if {$::i == [llength $::album] } {set ::i 0}

        $::pb delete

        # transition or straight cut
        if {$::first} {
                set ::pb [gnocl::pixBuf load -file [lindex $::album $::i]]
                $::img configure -image %?$::pb -size $::size
                set ::first 0
        } else {
            set src [gnocl::pixBuf load -file [lindex $::album $::i]]

                for {set i 5} {$i <= 255 } {incr i } {
                $::pb composite $src -alpha $i
                $::img configure -image %?$::pb -size $::size
                gnocl::update
                        after 10
                }
                        $src delete
        }

        after $::dt slideChange

}

#---------------
#
#---------------
proc main {} {

        set ::pb [gnocl::pixBuf new]
        set ::img [gnocl::image]

        gnocl::window \
                -child $::img \
                -defaultHeight 150 \
                -defaultWidth 150 \
                -decorated 0 \
                -x 1200 \
                -y 200

        slideChange

        gnocl::mainLoop
}

init
main