# Where can I find a list of events for each widget?

**URL:** <https://www.ruby-forum.com/t/where-can-i-find-a-list-of-events-for-each-widget/182184>\
**Category:** wxRuby\
**Created:** [January 24, 2010, 4:20pm UTC](https://www.ruby-forum.com/t/where-can-i-find-a-list-of-events-for-each-widget/182184 "2010-01-24T16:20:00Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [January 24, 2010, 4:20pm UTC](https://www.ruby-forum.com/t/where-can-i-find-a-list-of-events-for-each-widget/182184/1 "2010-01-24T16:20:00Z")

</div>

I’ve searched the documentation like crazy but I can’t seem to find the  
events for each of the widgets. Any info on this would be greatly  
appreciated.

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [January 24, 2010, 4:48pm UTC](https://www.ruby-forum.com/t/where-can-i-find-a-list-of-events-for-each-widget/182184/2 "2010-01-24T16:48:45Z")

</div>

Maybe a better questions is: Is there a way to attack your event  
listeners to objects? Like can I take a control and add a mouse listener  
to it? If not then how would things be handled in a custom control

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [January 24, 2010, 5:22pm UTC](https://www.ruby-forum.com/t/where-can-i-find-a-list-of-events-for-each-widget/182184/3 "2010-01-24T17:22:31Z")

</div>

Hi John,

This page here:

[http://rubyhelp.org/docs/wxruby/](http://rubyhelp.org/docs/wxruby/)

Scroll all the way down until you see the Events section. Each of the  
events sub-sections when clicked on will show you all of the evt\_events  
for that section. It’s a little confusing, I know, event to me. This  
is partly because the documentation was not created like a standard RI  
documentation.

Your mouse events are here:

[http://rubyhelp.org/docs/wxruby/mouseevent.html](http://rubyhelp.org/docs/wxruby/mouseevent.html)

When you have a control you can extend upon its behavior within a  
module.

I’m still very new to wxruby but I’m learning quickly. Hopefully some  
of the links will help. I’m going to be very busy reading boards so  
don’t be afraid to post your comments. I know sometimes this board  
appears very quiet, but it just needs some new life.

Alex and Mario are great responders.

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [January 24, 2010, 6:21pm UTC](https://www.ruby-forum.com/t/where-can-i-find-a-list-of-events-for-each-widget/182184/4 "2010-01-24T18:21:28Z")

</div>

Hey I appreciate the info. I have checked all that info out already, the  
problem I have is how to implement it. Like I want to take a window and  
add key\_down listener to it. I have a hard time finding how that is  
achievable.

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [January 24, 2010, 6:32pm UTC](https://www.ruby-forum.com/t/where-can-i-find-a-list-of-events-for-each-widget/182184/5 "2010-01-24T18:32:17Z")

</div>

Hi John,

How are you developing your GUIs. Are you coding everything by hand or  
are  
you designing your layouts with a GUI designer and using Xrcise to  
compile  
the XRC (xml) for use with WxRuby? I’m doing the latter with  
DialogBlocks  
so how the events are tied into things are a little different for me  
because  
all of my elements are automatically setup for me and all I have to do  
is  
extend from those elements by setting up my listener events. If you  
have  
XRC and can post some code, I can help you or someone else can.

Personally, I believe in GUI designers because I like to keep the  
graphical  
elements separate from the code. Let me know and post some code and I  
or  
someone else will try to help you out.

Sincerely,

Joel D.  
Website Bio: [http://jdezenzio.com/](http://jdezenzio.com/)  
Rails Production Sites: [http://ncaastatpages.com](http://ncaastatpages.com)

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [January 24, 2010, 7:32pm UTC](https://www.ruby-forum.com/t/where-can-i-find-a-list-of-events-for-each-widget/182184/6 "2010-01-24T19:32:02Z")

</div>

Well so far I have no code. What I’m doing is writing a IDE for  
programming that is similar to TextMate but written in ruby. I wanted to  
use StyledTextCtrl but while it has the charadded event that isn’t  
really useful to me since it doesn’t detect backspaces. So for lack of  
any other options I was going to try to create my own widget. I was just  
going to extend the scrolledWindow. It looks like it will do the trick,  
but I can’t figure out how to capture keystrokes with it or even what  
events it possesses.

So I’m kinda stuck unfortuantely.

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [January 25, 2010, 1:18am UTC](https://www.ruby-forum.com/t/where-can-i-find-a-list-of-events-for-each-widget/182184/7 "2010-01-25T01:18:16Z")

</div>

You could also look at incorporating highline with your app. I came  
across an interesting article concerning key captures here:

[http://blog.grayproductions.net/articles/i\_just\_want\_one\_character](http://blog.grayproductions.net/articles/i_just_want_one_character)

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [January 25, 2010, 1:01am UTC](https://www.ruby-forum.com/t/where-can-i-find-a-list-of-events-for-each-widget/182184/8 "2010-01-25T01:01:28Z")

</div>

Hi John,

One GUI application that I wrote in another language is a special search  
engine that also parses and finds code across the web. I just got back  
from a birthday party and performed a quick query for you and found the  
following:

[http://www.google.com/codesearch?as\_q=Wx::StyledTextCtrl&hl=en&as\_lang=ruby&as\_license\_restrict=i&as\_license=&as\_package=&as\_filename=&as\_case=](http://www.google.com/codesearch?as_q=Wx::StyledTextCtrl&hl=en&as_lang=ruby&as_license_restrict=i&as_license=&as_package=&as_filename=&as_case=)

This might help you get started.

Enjoy.

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [January 25, 2010, 4:56pm UTC](https://www.ruby-forum.com/t/where-can-i-find-a-list-of-events-for-each-widget/182184/9 "2010-01-25T16:56:43Z")

</div>

John Baker wrote:

> Hey I appreciate the info. I have checked all that info out already, the  
> problem I have is how to implement it. Like I want to take a window and  
> add key\_down listener to it. I have a hard time finding how that is  
> achievable.

You might find this document useful:

[http://wxruby.rubyforge.org/doc/eventhandlingoverview.html](http://wxruby.rubyforge.org/doc/eventhandlingoverview.html)

The only slightly complicated thing is understanding the difference  
between Command events and others. For other, generic events like mouse  
and key events, it’s basically

event\_source.evt\_type { # … handler code }

Since it inherits from Window, StyledTextCtrl should emit the  
evt\_key\_xxx family of events as well as the specialised STC events  
listed here:

[http://wxruby.rubyforge.org/doc/styledtextctrl.html](http://wxruby.rubyforge.org/doc/styledtextctrl.html)

hth  
alex

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [January 26, 2010, 1:32pm UTC](https://www.ruby-forum.com/t/where-can-i-find-a-list-of-events-for-each-widget/182184/10 "2010-01-26T13:32:18Z")

</div>

Hey Alex, yeah I checked it out, but the evt\_key didn’t seem to return  
any substantial data, or at least I wasn’t able to get at it if it did.  
I printed out every single attribute and I never got a character code or  
anything.

I may have missed something but I don’t know.

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [January 26, 2010, 1:59pm UTC](https://www.ruby-forum.com/t/where-can-i-find-a-list-of-events-for-each-widget/182184/11 "2010-01-26T13:59:58Z")

</div>

On 26/01/2010 12:32, John Baker wrote:

> Hey Alex, yeah I checked it out, but the evt\_key didn’t seem to return  
> any substantial data, or at least I wasn’t able to get at it if it did.  
> I printed out every single attribute and I never got a character code or  
> anything.

It (evt\_char) seems to work fine for me - try the sample below. Note  
that you’ll need to skip() the event if you want normal handling by the  
STC to proceed.

Depending on the use case, you might also look into  
Wx::AcceleratorTable, which is a standardised, easy way to set up  
keyboard shortcuts, rather than handling the raw keypresses.

## alex

require ‘wx’

class STCFrame \< Wx::Frame  
def initialize  
super(nil, :title =\> ‘Key Event Test’)  
@stc = Wx::StyledTextCtrl.new(self)  
@stc.evt\_char do | e |  
p e.key\_code  
end  
end  
end

Wx::App.run do  
STCFrame.new.show  
end

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [January 30, 2010, 4:00am UTC](https://www.ruby-forum.com/t/where-can-i-find-a-list-of-events-for-each-widget/182184/12 "2010-01-30T04:00:50Z")

</div>

Alex F. wrote:

> On 26/01/2010 12:32, John Baker wrote:
> 
> > Hey Alex, yeah I checked it out, but the evt\_key didn’t seem to return  
> > any substantial data, or at least I wasn’t able to get at it if it did.  
> > I printed out every single attribute and I never got a character code or  
> > anything.

aww man I got so excited for this to work but then it doesn’t recognize  
the backspace key! Not sure if there is another solution but that is  
pretty useless otherwise. I hope that is not the case

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [January 30, 2010, 4:03am UTC](https://www.ruby-forum.com/t/where-can-i-find-a-list-of-events-for-each-widget/182184/13 "2010-01-30T04:03:44Z")

</div>

Nevermind, I found evt\_key\_down which actually does work using your  
code. Awesome.

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [January 29, 2010, 6:43am UTC](https://www.ruby-forum.com/t/where-can-i-find-a-list-of-events-for-each-widget/182184/14 "2010-01-29T06:43:50Z")

</div>

Hey sorry I’m way late on this but thanks. I’m gonna check out this  
code. I’ll report back when I do.
