Skip to main content

Posts

Showing posts from March, 2012

gnocl::setOpts -new command

Sometimes I want to set a block of variables within procedure either as a set of defaults or as variables passed to a proc as options. Hitherto I've used a tcl proc to do this work but thought it high time to add this utility to the gnocl core. Ok, its not strictly graphics but it does make writing event handlers easier. Take the following for example: doTagPopup -w %w -t %t -n %n -b %b -x %X -y %Y -matches OM|MANI|PADME|HUM|HRIH The -w options can be used to create local variables. Here's a test snippet: proc test-setOpts {args} {      gnocl::setOpts $args     puts "$x $y $z"       gnocl::setOpts [list j 4 k 5 l 6]     puts "$j $k $l" } test-setOpts -x 1 -y 2 -z 3 In the first call the args string is parsed and values set en bloc. The leading '-' will be stripped away. In the second example, a paired list is given from which values will be set.

Getting text tag ranges

Completed code for returning a list of the ranges of a text tag within a gnocl::text widget. widgetId tag ranges tagName

Implmenting text tag popup menus

Here's a short script to show how to get popup menus appearing for text tag objects. #--------------- # texttag-popup.tcl #--------------- #!/bin/sh #\ exec tclsh "$0" "$@" package require Gnocl set txt [gnocl::text -wrapMode word] gnocl::window -child $txt -setSize 0.25 #--------------- # display popup menu #--------------- proc doTagPopup {args} {         foreach {arg val} $args { set [string trimleft $arg "-"] $val }     if {$t == "buttonPress" && $b == "3" } {                 # these may need runtime re-definition         proc doHello {} {puts hello}         proc doGoodBye {} {puts goodbye}                 set menu [gnocl::menu -title "menu" -tearoff 0]         $menu add [gnocl::menuItem -text "Hello" -onClicked doHello]         $menu add [gnocl::menuItem -text "Goodbye" -onClicked doGoodBye]         $menu popup $x $y                 #proc doHello {} {}         #proc doGoodBye {} {}         

Another simple error fixed -gnocl::dialog

The gnocl::dialog command has been throwing out a 'message-type' warning. The cause of this has now been removed.