Hello.
I have two questions.
Here is my code:
---------
require "wx"
class FFF < Wx::Frame
def initialize
@b = Array.new
super(nil, 2, "Bljllll", [5,5], [640,480])
@mypanel = Wx::Panel.new(self)
for i in 0..6
@b[i] = Wx::Button.new(@mypanel, i, "#{i}", [10+25*i, 10],
[20,20])
evt_button(i){puts i}
end
end
end
Wx::App.run do
FFF.new.show
end
--------
1) I''m create pre-condition number of buttons(7 in example above). What
I must do to set every button event which puts button id(btw, it''s
equal
label of buttons too)? For example: if I print button "0", it must
puts
0, not 6 as a my code(in my code click to all buttons puts last number
in array, here it is 6).
2) Are there events to images such as click and mouse_on?
--
Posted via http://www.ruby-forum.com/.
Hello Michael, On Fri, Nov 12, 2010 at 5:24 PM, Misha Ognev <lists at ruby-forum.com> wrote:> Hello. > > I have two questions. > > Here is my code: > --------- > require "wx" > > class FFF < Wx::Frame > def initialize > @b = Array.new > super(nil, 2, "Bljllll", [5,5], [640,480]) > @mypanel = Wx::Panel.new(self) > for i in 0..6 > @b[i] = Wx::Button.new(@mypanel, i, "#{i}", [10+25*i, 10], > [20,20]) > evt_button(i){puts i} >evt_button(@b[i]) { puts i }> end > end > > end > > Wx::App.run do > FFF.new.show > end > -------- > > 1) I''m create pre-condition number of buttons(7 in example above). What > I must do to set every button event which puts button id(btw, it''s equal > label of buttons too)? For example: if I print button "0", it must puts > 0, not 6 as a my code(in my code click to all buttons puts last number > in array, here it is 6). >This is answered in-line in the code.> 2) Are there events to images such as click and mouse_on? >I believe the standard event handlers for StaticBitmap will work, as it''s hierarchy is Object > EvtHandler > Window > Control > StaticBitmap. Standard Images, through Wx::Image, Wx::Bitmap, and such, do not have Events, as they are considered Memory Objects, not Actual Controls. Basically, if you look at the docs for any class we have, and it has somewhere in it''s hierarchy EvtHandler, then there are events that the Class will receive. hth, Mario> > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >-- Mario Steele Lieutenant Commander 3 XO - Geo 99 XO - STO IFT Fleet http://www.trekfederation.com http://geo99.ruby-im.net -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20101113/97c3e16e/attachment.html>
1) evt_button(@b[i]) { puts i } doesn''t work I need. It works like a
evt_button(i){puts i}. I don''t know why.
--
Posted via http://www.ruby-forum.com/.
Hi!
That''s the way to do it - it''s not very clean since it
probably will be
triggered by any button event
but you can process only events starting with a specific value etc and
ignore the rest (and use more strict handlers):
class FFF < Wx::Frame
def initialize
@b = Array.new
super(nil, 2, "Bljllll", [5,5], [640,480])
@mypanel = Wx::Panel.new(self)
for i in 0..6
@b[i] = Wx::Button.new(@mypanel, i, "#{i}", [10+25*i, 10],
[20,20])
end
# here you specify global event handler which
# will process any button press
# this uses event delegation and works dynamically
# so it will works regardless of number of buttons
evt_button(Wx::ID_ANY){ |ev| puts ev.get_id }
end
end
If you want clickable images you should use Wx::BitmapButton class:
http://wxruby.rubyforge.org/doc/bitmapbutton.html
Hope that helps :-)
?ukasz
--
Posted via http://www.ruby-forum.com/.
Hello else one.
I decided a problem 1):
evt_button(i){|xx| puts xx.get_id}
Now working with problem 2
--
Posted via http://www.ruby-forum.com/.
Misha Ognev wrote in post #961550:> Hello else one. > > I decided a problem 1): > > evt_button(i){|xx| puts xx.get_id} > > Now working with problem 2Did you try wx::BitmapButton? ?ukasz -- Posted via http://www.ruby-forum.com/.
Can I match the event "click right button of the mouse? (non left)"? -- Posted via http://www.ruby-forum.com/.
Hi Yes, there is evt_right_down, evt_right_up and evt_right_dclick (and also similar events for the middle button). Note that if you''re creating context menus (a common use for right clicks) it is better to use evt_context_menu which abstracts away platform differences in the means by which such a menu is summoned and dismissed. alex On 15/11/2010 18:00, Misha Ognev wrote:> Can I match the event "click right button of the mouse? (non left)"? >
Can you help me?
For example, I create the button:
b = Wx::Button.new(@mypanel, 10, "This is button")
evt_button(10){puts "This is button-10"} # Here is event for
left-click
mouse.
Can you write event for b, but with the right click?
--
Posted via http://www.ruby-forum.com/.
Else one question: how I can disable a button? -- Posted via http://www.ruby-forum.com/.
I tried to add evt_right_dclick, for example, but this is an error: C:/Ruby/lib/ruby/gems/1.9.1/gems/wxruby-ruby19-2.0.1-x86-mingw32/lib/wx/classes/evthandler.rb:136:in `acquire_handler'': Specify event handler with a method, name, proc OR block (ArgumentError) -- Posted via http://www.ruby-forum.com/.
Else one question: how can I close the frame and stop the program? -- Posted via http://www.ruby-forum.com/.
It is easy to do: evt_button(@button) do self.close end If that is the only window you have, the app should end on it''s own, otherwise you will need to call Wx::App.exit_main_loop hth, Mario Sent from my iPod On Nov 20, 2010, at 1:01 PM, Misha Ognev <lists at ruby-forum.com> wrote:> Else one question: how can I close the frame and stop the program? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users
Thanks. Another question: how can I make in Wx::Frame a scrollbar(vertical)? I have big number of labels, that''s not fit into screen. -- Posted via http://www.ruby-forum.com/.
On 23/11/10 22:32, Misha Ognev wrote:> Another question: how can I make in Wx::Frame a scrollbar(vertical)? I > have big number of labels, that''s not fit into screen. >Maybe Wx::ScrolledWindow? Have a look at the samples as there are several ways to use this class. The easiest way is with sizers where the scrolling will be calculated automatically for you. alex