Forum: wxRuby key event down

3afff55639e69487e25d6c4684b5152b?d=identicon&s=25 Ivan Vilches Basaul (Guest)
on 2012-05-11 09:24
(Received via mailing list)
i cannot do work key down event pls give me a hand thanks this is my
code:



require "rubygems"
require "wx"
include Wx

class MyFrame < Frame

  def initialize
    super(nil,                             #Parent
          :title => "RadioBox Example",    #Displays on top of window
          :pos => [1030, 25],               #or Wx::DEFAULT_POSITION
          :size => [250, 500]              #or Wx::DEFAULT_SIZE

          #For the position and size arguments, you don't need to
specify Point and Size
          #objects anymore. See: wxRuby Overview on the doc page
wxruby_intro.html
    )
    evt_key_down() { | ev | @text_position.label = "working key down" }

    panel = Wx::Panel.new(self)    #Parent = self = this Frame

    drink_choices = ["coffee", "tea", "juice", "milk"]   #labels for
radio buttons

    radios = Wx::RadioBox.new(
        panel,                        #Parent
        :label => "Drinks",           #Label for box surrounding radio
buttons
        :pos => [20, 5],
        :size => Wx::DEFAULT_SIZE,
        :choices => drink_choices,    #The labels for the radio buttons
        :major_dimension => 1,        #Max number of columns(see next
line)--try changing it to 2
        :style => Wx::RA_SPECIFY_COLS #:major_dimension value applies to
columns

        #The :major_dimension and :style in combination determine the
layout of the
        #RadioBox.  In this case, the maximum number of columns is 1,
which means
        #there can only be one radio button per line.  Because there are
4 radio buttons,
        #that means there will be 4 lines, with one radio button per
line.

    )
    evt_radiobox(radios.get_id()) {|cmd_event|
on_change_radio(cmd_event)}

    @text_widget = Wx::StaticText.new(
        panel,                  #Parent
        :label => "coffee",
        :pos => [150, 25],
        :size => Wx::DEFAULT_SIZE

        #Store a widget in an instance variable when other
        #methods, like the one below, need access to it.
    )

    boton = Wx::Button.new(
      panel,
      :label => "Posicion",
      :pos => [20,120],
      :size => Wx::DEFAULT_SIZE,
      :style => 0,
      :validator => Wx::DEFAULT_VALIDATOR,
      :name => "button"

      )
    evt_button(boton) {|cmd_event| on_click(cmd_event)}

     @text_position = Wx::StaticText.new(
        panel,                  #Parent
        :label => "Position",
        :pos => [150, 120],
        :size => Wx::DEFAULT_SIZE

        #Store a widget in an instance variable when other
        #methods, like the one below, need access to it.
    )



    #When there is an event of type evt_radiobox on the widget with the
id radios.get_id(),
    #the block is called and an "event object" is passed to the block.
The block calls
    #the method on_change_radio(), defined below, relaying the event
object to the
    #method. The event object contains useful information about the
radio button
    #that was selected.





    show     #equivalent to self.show, makes the frame visible
  end


  def on_change_radio(cmd_event)
    selected_drink = cmd_event.string  #Selected radio's label

    #Instead of calling cmd_event.get_string() or
cmd_event.set_string(), you can
    #now call an accessor method with the same name as the property you
are trying
    #to get or set. See: wxRuby Overview on the doc page
wxruby_intro.html

    @text_widget.label = selected_drink
  end
  def on_click(cmd_event)

     @text_position.label = "testeando"
   end

end


class MinimalApp < Wx::App
  def on_init
    MyFrame.new
  end
end

MinimalApp.new.main_loop    #main_loop() tells wxruby to start reacting
                            #to radio button selections, button clicks,
etc.
                            #on your App.
This topic is locked and can not be replied to.