Hi,
I think probably the XML route.
Thanks for the hint and the link to the wxpython project. Looks doable
to me.
So I’ll go the XML way then. With my first spike attempts I’m getting
strange results though. Here’s my test class.
Two things
(a) I would expect it to write an XML file to my home dir, which it
doesn’t. Actually I would much rather like it to a string but my first
attempt (file) fails already
(b) I would expect it to copy the contents of the editor to the
clipboard, which it doesn’t => crashes with NoMethodError: undefined
method ‘begin’ for #SWIG::TYPE_p_wxRichTextRange:0x234d2e20
Any ideas what might be going wrong? Or maybe an idea of what’s the best
way to actually get the XML out of the control in order to parse it?
I’m using wxruby 2.0.1, ruby 1.8.7p174 on OSX 10.6.4
Thanks so much,
Tony
#!/usr/bin/env arch -i386 ruby
require ‘rubygems’
require “wx”
include Wx
class MyFrame < Wx::Frame
def initialize
super(nil, :title => “RichText Example”, :pos => [150, 25], :size =>
[800, 500])
panel = Wx::Panel.new(self) #Parent = self = this Frame
@editor = Wx::RichTextCtrl.new(
panel, # parent
ID_ANY, # ID
"Initial text", # value
[0, 20], # position
[400, 400] #size
)
boldbtn = Wx::Button.new(panel, ID_ANY, "bold", [0,0], [100,50])
dumpbtn = Wx::Button.new(panel, ID_ANY, "dump",[100,0], [100,50])
evt_button(boldbtn) { |evt| @editor.apply_bold_to_selection() }
evt_button(dumpbtn) { |evt|
buffer.save_file("/Users/tm/test.xml", Wx::RICHTEXT_TYPE_XML)
@editor.select_all()
range = @editor.get_selection_range()
buffer = @editor.get_buffer()
buffer.copy_to_clipboard(range)
}
show()
end
end
class MinimalApp < Wx::App
def on_init
MyFrame.new
end
end
MinimalApp.new.main_loop