Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Snit widgets and bindings under Etcl

8 views
Skip to first unread message

relaxmike

unread,
Dec 2, 2008, 11:14:00 AM12/2/08
to
Hi All Tclers,

I have the following problem that my Snit-based extended text widget
does not behave as I want : the events I generate from the script
are not captured, while interactive events are. That make the unit
tests
difficult to perform.

The following script is the smallest I can write which exhibits the
problem.
It creates a snit widgetadaptor above Tk's text.
The insert method is modified so that it inserts the letter, then a
"!".
In the end of the script, I generate the event associated with the
"a" key.

package require Tk
package require snit
::snit::widgetadaptor rptext {
constructor {args} {
installhull using text
$self configurelist $args
}
method insert {args} {
set cmd [list $hull insert]
set cmd [concat $cmd $args]
eval $cmd
$hull insert insert "!"
return ""
}
method delete {args} {}
# Enable ins and del as synonyms, so the program can insert and
# delete.
delegate method ins to hull as insert
delegate method del to hull as delete
# Pass all other methods and options to the real text widget, so
# that the remaining behavior is as expected.
delegate method * to hull
delegate option * to hull
}
frame .f1
pack .f1
button .f1.bn1 -text "X" -command {exit}
pack .f1.bn1 -side left
button .f1.bn2 -text "A" -command {
focus .mytext
event generate .mytext <Key-A>
}
pack .f1.bn2 -side left
rptext .mytext -height 8 -width 40
pack .mytext
update
focus .mytext
event generate .mytext <Key-a>
update

When this script is executed on my Pocket PC 4100 with Etcl 19/09/2008
running under Windows CE, the text widget is displayed but the "a!"
text
is not displayed. But when I interactively type on my virtual
keyboard,
the events are processed normally.

When I execute the same script on my Win XP station with AS Tcl
8.4.19,
the text appears with a "a!" at the beginning, as expected (as well
as interactively typed letters of course).

From my experience, I noticed that the following rules
must be satisfied so that the events generated can be captured :
- the widget must be packed,
- the widget must have the focus
- the update command must be executed, to force the event
loop to process the event.
When I apply these rules, the "event generate" instructions I use in
my unit
tests generally get processed.

But not here : do you have any idea why ?

Best regards,

Michaël

0 new messages