Forum: wxRuby Where can I find a list of events for each widget?

Posted by John Baker (fatdogs12)
on 2010-01-24 16:20
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.
Posted by John Baker (fatdogs12)
on 2010-01-24 16:48
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
Posted by Alpha Blue (elricstorm)
on 2010-01-24 17:22
Hi John,

This page here:

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

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.

Posted by John Baker (fatdogs12)
on 2010-01-24 18:21
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.
Posted by Alpha Blue (elricstorm)
on 2010-01-24 18:32
(Received via mailing list)
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 Dezenzio
Website Bio:  http://jdezenzio.com/
Rails Production Sites:  http://ncaastatpages.com
Posted by John Baker (fatdogs12)
on 2010-01-24 19:32
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.
Posted by Alpha Blue (elricstorm)
on 2010-01-25 01:01
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=

This might help you get started.

Enjoy.
Posted by Alpha Blue (elricstorm)
on 2010-01-25 01:18
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
Posted by Alex Fenton (Guest)
on 2010-01-25 16:56
(Received via mailing list)
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

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

hth
alex
Posted by John Baker (fatdogs12)
on 2010-01-26 13:32
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.
Posted by Alex Fenton (Guest)
on 2010-01-26 13:59
(Received via mailing list)
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
Posted by John Baker (fatdogs12)
on 2010-01-29 06:43
Hey sorry I'm way late on this but thanks. I'm gonna check out this 
code. I'll report back when I do.
Posted by John Baker (fatdogs12)
on 2010-01-30 04:00
Alex Fenton 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
Posted by John Baker (fatdogs12)
on 2010-01-30 04:03
Nevermind, I found evt_key_down which actually does work using your 
code. Awesome.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.