Hey Tim and Alex,
Tim Field wrote:
Tim
Wow, must be one of the first fast ones I’ve actually debugged here.
I’ve done my own debugging, and it looks like, your trying to setup the
ID for your objects, and they haven’t even been defined yet. And for
you Alex, in order to access “finder” You should proabbly store that as
a Method Call, or store it as a Class Variable, so that it can be
accessed, in this sistuation.
Anyways, the core problem, is first, for the method at which your
generating the code, and adding to it, you need to change the “finder”
variable in my_frame.rb in TestFrameBase#initialize() to a class
variable, so it can be accessed by sub-classed versions of the
TestFrameBase. You can do this easily by just adding an ‘@’ symbol to
it. Nothing to it really.
Next, in your sub-classed version in tutorial.rb, I made a few changes.
Basically, I added the three calls to
@finder.call(“id_we_are_looking_for”) for upper_bt, lower_bt, and
text_box, then changed the upcase and downcase to the following:
text_box.value = text_box.value.upcase/downcase As you can modify the
string with upcase!/downcase!, but it doesn’t modify it in the wxRuby
Buffer, so you need to re-assign it to the buffer, so that it will
convert over properly for you, and display the changes. The New code
goes as follows:
======================my_frame.rb=======================
This class was automatically generated from XRC source. It is not
recommended that this file is edited directly; instead, inherit from
this class and extend its behaviour there.
Source file: tutorial.xrc
Generated at: Sat Nov 03 13:22:37 +1300 2007
class TextFrameBase < Wx::Frame
def initialize(parent = nil)
super()
xml = Wx::XmlResource.get
xml.flags = 2 # Wx::XRC_NO_SUBCLASSING
xml.init_all_handlers
xml.load(“tutorial.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
end
end
=====================tutorial.rb===========================
require ‘wx’
load in the generated code
require ‘my_frame’
Mix-in for a Wx::TextCtrl
module CaseChangeTextCtrl
convert all the text in the control to upper case
def upcase!
self.value = self.value.upcase
end
convert all the text in the control to lower case
def downcase!
self.value = self.value.downcase
end
end
Inherit from the generated base class and set up event handlers
class CaseChangeFrame < TextFrameBase
def initialize
super
upper_bt = @finder.call(“upper_bt”)
lower_bt = @finder.call(“lower_bt”)
text_box = @finder.call(“text_box”)
evt_button(upper_bt) { text_box.value = text_box.value.upcase }
evt_button(lower_bt) { text_box.value = text_box.value.downcase }
end
end
Run the class
Wx::App.run do
CaseChangeFrame.new.show
end
============================================================
Enjoy the new code, and Alex, you should look into this, incase someone
decides they want to do something similar to this. This would exactly
be the way that I would want to do it.
L8ers,
Mario S.