WJG (22/Jan/09) A few lines from the manual give some indication on how to use this powerful widget.
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:
pcam Which version of Gnocl is required for the gnocl::canvas widget ? I am running 0.9.91 on Win XP, I guess I need to upgrade to 0.9.94. Any chance of making a Windows binary build available ?
WJG (28-Apr-09) At present Gnocl is only supported on the Linux platform. Other platform compilations have been provided by other users. Since 0.9.91 there has been no one coming forward to maintain the Windows and Maemo packages. It would be really useful if someone did step forward to fill the void! Fancy volunteering? The compilation instructions for the later versions are available in the Gnocl for Windows documentation.
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.
WJG (23/Jan/09) Straight from the docs. This are the current opts and cmds for the gnocl::canvas widget.
RLH Where are the docs?
WJG Included in the full distribution of Gnocl, available for download from Sourceforge.
RLH Maybe a domain like gnocl-docs.org or something, kind of like Tcl/Tk has? That would be nice. Of course, there is overhead there.
-antialiased
-background
-centerScroll
-data
-hasFocus
-height
-name
-onButtonPress
%w widget name %t type of event: one of buttonPress, button2Press or button3Press %x x coordinate %y y coordinate %b button number %s state of the buttons and modifiers (bitmask)
-onButtonRelease
%w widget name %t type of event: always buttonRelease %x x coordinate %y y coordinate %b button number %s state of the buttons and modifiers (bitmask)
-onEnter
%w widget name %x x coordinate %y y coordinate %s state of the buttons and modifiers (bitmask)
-onKeyPress
%w widget name %k key code as integer %K key code as symbol %a unicode unicode character, or the empty string if there is no corresponding character. %s state of the buttons and modifiers (bitmask)
-onKeyRelease
%w widget name %k key code as integer %K key code as symbol %a unicode unicode character, or the empty string if there is no corresponding character. %s state of the buttons and modifiers (bitmask)
-onLeave
%w widget name %x x coordinate %y y coordinate %s state of the buttons and modifiers (bitmask)
-onMap
%w widget name TABLE
-onMotion
%w widget name %x x coordinate %y y coordinate %s state of the buttons and modifiers (bitmask) TABLE
-onResize
%w widget name %x x coordinate %y y coordinate %W new width %H new height
-onUnmap
%w widget name
-pixelPerUnit
-scrollRegion
-visible
-width
id affine tag-or-id-expr list-of-coordinates
id canvasToWindow list-of-coordinates
id cget option
id configure [-option value…]
id create type [-option value…]
id delete
id findItemAt x y
id findWithTag tag-or-id-expr
id getBounds tag-or-id-expr
id getCurrentSize
id isMapped
id itemCommand tag-or-id-expr cmd [-option value…]
id itemConfigure tag-or-id-expr [-option value…]
id itemCget tag-or-id-expr ?option?
id itemDelete tag-or-id-expr
id itemHide tag-or-id-expr
id itemShow tag-or-id-expr
id lower tag-or-id-expr ?level?
id move tag-or-id-expr list-of-coordinates
id raise tag-or-id-expr ?level?
id rotate tag-or-id-expr list-of-coordinates
id scale tag-or-id-expr list-of-coordinates
id update
id windowToCanvas list-of-coordinates