# wxRuby2-preview: strange event of TextCtrl

**URL:** <https://www.ruby-forum.com/t/wxruby2-preview-strange-event-of-textctrl/68838>\
**Category:** Ruby\
**Created:** [September 15, 2006, 8:29pm UTC](https://www.ruby-forum.com/t/wxruby2-preview-strange-event-of-textctrl/68838 "2006-09-15T20:29:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kuuul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ad7895/32.png) [@kuuul](https://www.ruby-forum.com/u/kuuul)\
**Post date:** [September 15, 2006, 8:29pm UTC](https://www.ruby-forum.com/t/wxruby2-preview-strange-event-of-textctrl/68838/1 "2006-09-15T20:29:05Z")

</div>

…  
evt\_text(TEXTCTRL\_ID){  
puts self.get\_value  
}  
…

When I input “Hello”,  
output:  
H  
He  
Hel  
Hell  
Hello

When I select “ello”,and input “i”  
output:  
H  
Hi

How can I ignore the event outputs “H”?

---

<div class="post-metadata">

**Author:** ![kuuul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ad7895/32.png) [@kuuul](https://www.ruby-forum.com/u/kuuul)\
**Post date:** [September 15, 2006, 9:47pm UTC](https://www.ruby-forum.com/t/wxruby2-preview-strange-event-of-textctrl/68838/2 "2006-09-15T21:47:17Z")

</div>

Kuang D. wrote:

> He  
> Hel  
> Hell  
> Hello
> 
> When I select “ello”,and input “i”  
> output:  
> H  
> Hi
> 
> How can I ignore the event outputs “H”?

You have to choose which text events you want to act on. You are  
presently  
acting on each entered character. I _think_ you want to act only on  
enter  
being pressed.

---

<div class="post-metadata">

**Author:** ![kuuul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ad7895/32.png) [@kuuul](https://www.ruby-forum.com/u/kuuul)\
**Post date:** [September 15, 2006, 10:37pm UTC](https://www.ruby-forum.com/t/wxruby2-preview-strange-event-of-textctrl/68838/3 "2006-09-15T22:37:47Z")

</div>

Paul L. wrote:

> Kuang D. wrote:
> 
> > He  
> > Hel  
> > Hell  
> > Hello
> > 
> > When I select “ello”,and input “i”  
> > output:  
> > H  
> > Hi
> > 
> > How can I ignore the event outputs “H”?
> 
> You have to choose which text events you want to act on. You are  
> presently  
> acting on each entered character. I _think_ you want to act only on  
> enter  
> being pressed.

Acutally,I wanted to do something like google suggest  
([Google](http://www.google.com/webhp?complete=1))

When I select “ello” of “Hello” and press “i”,two “text change event”  
raised,one is Hello-\>H and the other is H-\>Hi.Now I have to ignore the  
first event(do nothing),and give suggestion by the last word.I have no  
idea.

---

<div class="post-metadata">

**Author:** ![kuuul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ad7895/32.png) [@kuuul](https://www.ruby-forum.com/u/kuuul)\
**Post date:** [September 16, 2006, 1:11am UTC](https://www.ruby-forum.com/t/wxruby2-preview-strange-event-of-textctrl/68838/4 "2006-09-16T01:11:35Z")

</div>

Kuang D. wrote:

/ …

> When I select “ello” of “Hello” and press “i”,two “text change event”  
> raised,one is Hello-\>H and the other is H-\>Hi.Now I have to ignore the  
> first event(do nothing),and give suggestion by the last word.I have no  
> idea.

I really do not understand the problem you are having, apart from the  
fact  
that you are writing a completion engine.

A completion engine is very easy to write, but the user has to enter the  
first characters correctly.

* * *

#!/usr/bin/ruby

dictionary = File.read("/usr/share/dict/words")

test = “zeal”

matches = dictionary.scan(/^#{test}.\*$/)

puts matches

* * *

(surprisingly long list of words whose first characters match the test  
string)

Maybe you could explain the problem by saying very clearly what you  
hoped to  
accomplish, and, equally clearly, what happened instead.

---

<div class="post-metadata">

**Author:** ![kuuul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ad7895/32.png) [@kuuul](https://www.ruby-forum.com/u/kuuul)\
**Post date:** [September 16, 2006, 11:46am UTC](https://www.ruby-forum.com/t/wxruby2-preview-strange-event-of-textctrl/68838/5 "2006-09-16T11:46:12Z")

</div>

Hi

Kuang D. wrote:

> …  
> evt\_text(TEXTCTRL\_ID){  
> puts self.get\_value  
> }  
> …  
> When I input “Hello”,  
> …  
> When I select “ello”,and input “i”  
> output:  
> H  
> Hi

I don’t see this behaviour. If I type in ‘Hello’, then select ‘ello’ and  
overtype with ‘i’, get\_value in the event handler returns ‘Hi’.

> How can I ignore the event outputs “H”?

Are you looking for event.veto?

evt\_text(the\_id) { | event | event.veto }

alex
