From: Bob on
Hi,
Can someone point me in the right direction to research how to do the
following:

1. I want to be able to type text into a text box. This part is easy...I
already have this code. ;)
2. As soon as the first character is typed, I want another process (is
'process' the correct term?) to read that character (but leave it in the
text box) and go off and do some other code based on what character it is.
3. Meanwhile, I want to be able to continue to type characters into the text
box, that is, I don't want the process described in #2 to 'freeze' the text
box.
4. Once the process in #2 completes, it should read the next character and
do its work again.
5. Once all characters have been processed, the application should wait
until I start typing again, and repeat #2 etc.

The process to be executed in #2 is yet to be written, but will certainly
take more time to execute than it takes to type a character. That is to
say, my typing will always be ahead of the process in #2.

Thanks for any guidance.

Bob



From: Arjen Markus on
On 9 jul, 03:42, "Bob" <kava...(a)noga.com> wrote:
> Hi,
>   Can someone point me in the right direction to research how to do the
> following:
>
> 1. I want to be able to type text into a text box.  This part is easy....I
> already have this code.  ;)
> 2. As soon as the first character is typed, I want another process (is
> 'process' the correct term?) to read that character (but leave it in the
> text box) and go off and do some other code based on what character it is..
> 3. Meanwhile, I want to be able to continue to type characters into the text
> box, that is, I don't want the process described in #2 to 'freeze' the text
> box.
> 4. Once the process in #2 completes, it should read the next character and
> do its work again.
> 5. Once all characters have been processed, the application should wait
> until I start typing again, and repeat #2 etc.
>
> The process to be executed in #2 is yet to be written, but will certainly
> take more time to execute than it takes to type a character.  That is to
> say, my typing will always be ahead of the process in #2.
>
> Thanks for any guidance.
>
> Bob

The thing you are looking for is "event bindings". You can bind
commands to
any number of events, like this:

bind .text <KeyPress> {puts "Pressed: %K"}

This has the effect of running the command 'puts "Pressed: %K' each
time
you type a character in the widget .text. %K is a code that tells the
binding mechanism what to substitute - %K is replaced by the
character
that you typed.

If the processing takes a long time, there are several solutions:
- Split the processing in smaller parts that get scheduled
- Use the Threads extension, so that another thread will do the
processing

However, before you go along that route, first try if it is really
necessary.

Regards,

Arjen
 | 
Pages: 1
Prev: freewrap
Next: Tcl 8.5, Itcl 3.4 and [info frame]