I’m trying to get my first small test wxRuby app up and running. I have
created an XRC file using DialogBlocks and then used xrcise to produce
the ruby code which loads it. I then did a bit of cutting and pasting to
produce my own ruby code to add functionality. However I keep running
into the same problem of ‘undefined method’. I’ve tried lots of
different alternatives to get_selection (ie, value, get_value,
get_item_data etc but with no luck).
I’m sure I’m doing something wrong that someone will find to be a basic
error (hopefully!). Happy to post XRC file if necessary. Any help
gratefully appreciated.
___ The error message:__________________________________________________
$ ruby xrctest.rb
xrctest.rb:10:in generatetext': undefined method
get_selection’ for
nil:NilClass (NoMethodError)
from xrctest.rb:18:in initialize' from /usr/lib/ruby/gems/1.8/gems/wxruby-1.9.10-x86_64-linux/lib/wx/classes/app.rb:16:in
call’
from
/usr/lib/ruby/gems/1.8/gems/wxruby-1.9.10-x86_64-linux/lib/wx/classes/app.rb:16:in
process_event' from /usr/lib/ruby/gems/1.8/gems/wxruby-1.9.10-x86_64-linux/lib/wx/classes/app.rb:16:in
on_run’
from
/usr/lib/ruby/gems/1.8/gems/wxruby-1.9.10-x86_64-linux/lib/wx/classes/app.rb:16:in
main_loop' from /usr/lib/ruby/gems/1.8/gems/wxruby-1.9.10-x86_64-linux/lib/wx/classes/app.rb:16:in
run’
from xrctest.rb:23
Xrcise produced this (myframe.rb):_______________________________
class FrameBaseClass < Wx::Frame
attr_reader :id_choice_select, :id_datectrl, :id_button_test,
:id_textctrl_test, :id_button_close
def initialize(parent = nil)
super()
xml = Wx::XmlResource.get
xml.flags = 2 # Wx::XRC_NO_SUBCLASSING
xml.init_all_handlers
xml.load(“testwindow.xrc”)
xml.load_frame_subclass(self, parent, “ID_WXFRAME”)
finder = lambda do | x |
int_id = Wx::xrcid(x)
begin
Wx::Window.find_window_by_id(int_id, self) || int_id
# Temporary hack to work around regression in 1.9.2; remove
# begin/rescue clause in later versions
rescue RuntimeError
int_id
end
end
@id_choice_select = finder.call("id_choice_select")
@id_datectrl = finder.call("id_datectrl")
@id_button_test = finder.call("id_button_test")
@id_textctrl_test = finder.call("id_textctrl_test")
@id_textctrl_test.extend(ClassTextCtrl)
@id_button_close = finder.call("id_button_close")
if self.class.method_defined? "on_init"
self.on_init()
end
end
end
And my own code (xrctest.rb):_______________________________
require ‘rubygems’
require ‘wx’
load in the generated code
require ‘myframe’
Mix-in
module ClassTextCtrl
def generatetext
self.value = @id_choice_select.get_selection
end
end
Inherit from the generated base class and set up event handlers
class FrameBase < FrameBaseClass
def initialize
super()
evt_button(id_button_test) { id_textctrl_test.generatetext }
end
end
Run the class
Wx::App.run do
FrameBase.new.show
end