Version 4 of gnocl::canvas

Updated 2009-01-22 22:41:53 by RLH

WJG (22/Jan/09) A few lines from the manual give some incation

A canvas displays any number of items, which may be rectangles, circles, lines, text, bezier paths or standard widgets. Items may be manipulated (e.g. moved, scaled, rotated or re-colored) and commands may be associated with items with the bind command. For example, a particular command may be associated with the <button>-event so that the command is invoked whenever a button is pressed with the mouse cursor over an item. This means that items in a canvas can have behaviors defined by the Tcl scripts bound to them. Each canvas item has an integer value as uniq ID, which is returned on item creation. Furthermore each item may be associated with one or more tags. All canvas commands which operate on canvas items accept a tag-or-id-expression. This expression may contain tags or IDs combined with the operators (in descending order) ! (not), & (and), ^ (xor), | (or) and parenthezised subexpressions. E.g. "t1|(t2^t3)" or "!t2".

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

 package require Gnocl

 set canv [gnocl::canvas -background white -antialiased 1]
 set coords {10 100 30 60 50 20 110 20 150 60 190 100}
 foreach {x y} $coords {
   $canv create ellipse -coords [list $x $y 3] -centerRadius 1 -tags dots
 }
 $canv create bPath -coords {30 60 curveTo 50 20 110 20 150 60} -outline red -width 2 -tags "path t2"
 $canv create line -coords [lrange $coords 0 5] -fill blue
 $canv create line -coords [lrange $coords 6 11] -fill blue
 $canv create ellipse -coords {70 140 50} -centerRadius 1 -fill "" -outline mediumOrchid -width 3 -dash {16 4}
 $canv create rectangle -coords {90 110 180 180} -fill "blue 0.2" -outline green -width 3
 $canv create text -coords {105 80} -text "gnocl" -font "Utopia 14"
 $canv itemConfigure dots -fill darkgreen 
 $canv itemConfigure "dots|path" -onButtonPress "puts pressed" -onButtonRelease "puts released" 
 gnocl::window -title "Canvas" -child $canv -onDestroy exit

 gnocl::mainLoop


 Produces the following output:

http://wjgiddings.googlepages.com/ScreenShot-gnocl_canvas.png


D. McC 2009 Jan 22: Are there things the standard Tk canvas can do that the gnocl canvas can't? If so, what?

RLH -- That would be a good list to make what Gnocl has or hasn't versus Tk.


enter categories here