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.
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
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.
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.
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/
Rails Production Sites: http://ncaastatpages.com
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.
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
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:
This might help you get started.
Enjoy.
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
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.
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
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
Nevermind, I found evt_key_down which actually does work using your
code. Awesome.
Hey sorry I’m way late on this but thanks. I’m gonna check out this
code. I’ll report back when I do.