#!/usr/bin/perl # # This short script tries to demonstrate with a simple example what you can # do with Tk Zinc widget, in particular how to use group item, clipping, and # transformations. # $Id$ # this demo has been developped by D. Etienne etienne@cena.fr # use Tk; # Zinc module is loaded... use Tk::Zinc; # to find the Wheel class. Should be included in this source file! use lib Tk->findINC('demos/widget_lib'); # my Wheel object class too. See below... use Wheel; # We create a classical root widget called MainWindow; then we create Zinc # widget child with size, color and relief attributes, and we display it using # the geometry manager called 'pack'. my $mw = MainWindow->new; $mw->geometry("320x565"); $mw->resizable(0,0); my $zinc = $mw->Zinc(-width => 300, -height => 500, -backcolor => 'gray70', -borderwidth => 3, -relief => 'sunken'); $zinc->pack; # Then we create a gray filled rectangle, in which we will display explain text. $zinc->add('rectangle', 1 , [10, 400, 290, 490], -linewidth => 0, -filled => 1, -fillcolor => 'gray80', ); my $text = $zinc->add('text', 1, -position => [150, 445], -anchor => 'center', ); # Create the Wheel object (see Wheel.pm) my $wheel = Wheel->new($zinc, 150, 500, 100); # Display comment &comment("Strike any key to begin"); # Create Tk binding $mw->Tk::bind('', \&openmode); MainLoop; # Callback bound to '' event when wheel is unmapped sub openmode { return if $wheel->ismoving; # set binding to unmap the wheel $mw->Tk::bind('', \&closemode); # set binding to rotate the hand $zinc->bind($wheel, '<1>', sub {$wheel->rotatehand(300)}); # map the wheel $wheel->show(150, 150); # and then inform user &comment("Click on the wheel to rotate the hand.\n". "Strike any other key to hide the wheel."); } # Callback bound to '' event when wheel is already mapped sub closemode { return if $wheel->ismoving; # set binding to map the wheel $mw->Tk::bind('', \&openmode); # unmap the wheel $wheel->hide(150, 400); # and then inform user &comment("Strike any key to show the wheel"); } # Just display comment sub comment { my $string = shift; $zinc->itemconfigure($text, -text => $string); }