Monday, September 06, 2010

gnocl::pixbuf

Last night I decided that I wanted to have a desktop gadget that would give me a rolling-slideshow of some my favourite family photos. With the implementation of the gnocl::pixBuf command I hacked together something useful in about half an hour. I wanted a nice dissolve and so finished the previously existing composite stub. Here's the script:

#---------------
# photoAlbumGadget.tcl
#---------------
# Produce a desktop photo 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
    # show the first frame, and dissolve thereafter
    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


No comments: