Just added -height, -width, -x and -y options to the gnocl::dialog widget.

Friday, April 06, 2012
Wednesday, March 28, 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.
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.
Tuesday, March 27, 2012
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

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 {} {}
}
}
$txt tag create tag_popup -onEvent {doTagPopup -t %t -b %b -x %X -y %Y } -underline single -foreground blue
$txt lorem
$txt tag apply {1 0} "1 20" -tags tag_popup

#---------------
# 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 {} {}
}
}
$txt tag create tag_popup -onEvent {doTagPopup -t %t -b %b -x %X -y %Y } -underline single -foreground blue
$txt lorem
$txt tag apply {1 0} "1 20" -tags tag_popup
Sunday, March 11, 2012
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.

Thursday, February 09, 2012
gnocl::dialog -messy closure fixed
The glib warnings put to the console when the dialog is closed has now been fixed.

Friday, January 13, 2012
gnocl::dialog
Made some enhancements here today. Added the Gtk "other" option to the range of dialog types, i.e. no icon. But more significantly, implemented automatic setting of type to "other" if the -child option set.
Hiitherto, the gnocl::dialog was simply a means of giving yes/no feedback. Now, however, it's more useful for the setting of parameters and other forms of settings.
Here's a snippet from my current coding project which requires export to Abiword format. The following proc will build a dialog for the setting of vars. The code is not complete, but shows how the gnocl::dialog enhancements are working.
#---------------
# set file export properties
#---------------
# Args
#
# Return
#---------------
proc abi:properties {} {
global metaData
global pageSetup
set nb [gnocl::notebook]
# file metadata
set box(1) [gnocl::box -orientation vertical]
foreach name [lsort [array names metaData]] {
$box(1) add [gnocl::labelEntry \
-labelWidthChars 15 \
-align left \
-text [string totitle $name] ] \
-fill {1 1} -expand 0
}
# page setup
set box(2) [gnocl::box -orientation vertical]
foreach name [lsort [array names pageSetup]] {
$box(2) add [gnocl::labelEntry \
-labelWidthChars 15 \
-align left \
-text [string totitle $name] ] \
-fill {1 1} -expand 0
}
$nb addPage $box(1) "%__MetaData"
$nb addPage $box(2) "%__Page Setup"
set dlg [gnocl::dialog \
-title "Abiword Export Properties" \
-child $nb \
-buttons "%#No %#Yes" \
-onResponse {
puts %v
} ]
}

Hiitherto, the gnocl::dialog was simply a means of giving yes/no feedback. Now, however, it's more useful for the setting of parameters and other forms of settings.
Here's a snippet from my current coding project which requires export to Abiword format. The following proc will build a dialog for the setting of vars. The code is not complete, but shows how the gnocl::dialog enhancements are working.
#---------------
# set file export properties
#---------------
# Args
#
# Return
#---------------
proc abi:properties {} {
global metaData
global pageSetup
set nb [gnocl::notebook]
# file metadata
set box(1) [gnocl::box -orientation vertical]
foreach name [lsort [array names metaData]] {
$box(1) add [gnocl::labelEntry \
-labelWidthChars 15 \
-align left \
-text [string totitle $name] ] \
-fill {1 1} -expand 0
}
# page setup
set box(2) [gnocl::box -orientation vertical]
foreach name [lsort [array names pageSetup]] {
$box(2) add [gnocl::labelEntry \
-labelWidthChars 15 \
-align left \
-text [string totitle $name] ] \
-fill {1 1} -expand 0
}
$nb addPage $box(1) "%__MetaData"
$nb addPage $box(2) "%__Page Setup"
set dlg [gnocl::dialog \
-title "Abiword Export Properties" \
-child $nb \
-buttons "%#No %#Yes" \
-onResponse {
puts %v
} ]
}
Subscribe to:
Posts (Atom)
-
Given this module some attention today. Added some of the more package wide options to the module and created customised handler for settin...
-
Over the past few programming sessions I've been working on producing a central point, a dashboard, around which it's possible to se...
-
The contents of a GtkTextBuffer can be saved as serialized binary file. Whilst converting such a file to ascii may be problematic if the bu...