Forum: wxRuby wxRichTextCtrl not Working through wxFormBuilder

Posted by Michael Satterwhite (msatterwhite)
on 2010-08-12 03:46
I've used wxFormBuilder to put a wxRichTextCtrl on my form. After doing
this, I run xrcise and try to use the control. The variable for the rich
text control is a FixNum. On examination, I saw that the class name in
the xrc file is "unknown".

Is there no way to use this control without manually laying out the
controls - or writing this routine in C++? Does anyone know a
workaround?

Thanks in advance.
---Michael
Posted by Alex Fenton (Guest)
on 2010-08-12 09:20
(Received via mailing list)
Hi

On 12/08/2010 02:46, Michael Satterwhite wrote:
> I've used wxFormBuilder to put a wxRichTextCtrl on my form. After doing
> this, I run xrcise and try to use the control. The variable for the rich
> text control is a FixNum. On examination, I saw that the class name in
> the xrc file is "unknown".
>
> Is there no way to use this control without manually laying out the
> controls - or writing this routine in C++? Does anyone know a
> workaround?
>    

I worked around it by designing the XRC with a bog-standard
Wx::TextCtrl, then in the initialise method of the inheriting Ruby
class, replacing it with a RichTextCtrl.

I wrote a convenience method to handle it properly. It's called like
this (assuming a TextCtrl mapped to the instance var @text_box)

rtc = Wx::RichTextCtrl.new(....)
replace_xrc(:text_box, rtc)

The replace_xrc method looks like this:

class Wx::Window
   # Convenience function to replace one Window with another. Useful
   # because there are elements which are not available or convenient in
   # XRC, but a placeholder can be used with a real child created in
   # ruby.
   #
   # Expects a symbol (eg :@child by which the old can be got) and a new
   # child to replace it. The instance variable's value is overwritten.
   def replace_xrc(old_sym, new_win)
     old_win = instance_variable_get("@#{old_sym}")
     old_win.containing_sizer.replace( old_win, new_win )
     old_win.destroy
     instance_variable_set("@#{old_sym}", new_win)
     new_win.containing_sizer.layout
   end
end

(from 
http://weft-qda.rubyforge.org/svn/trunk/weft-qda/lib/weft/wxgui/utilities.rb)


hth
alex
Posted by Chloro Form (tony44)
on 2010-09-23 15:43
> I wrote a convenience method to handle it properly. It's called like
> this (assuming a TextCtrl mapped to the instance var @text_box)

thanks, that worked fine for me, too.

One thing to note is that, strangely, it doesn't work if the RTC is the 
only control in the sizer. So make sure that there is at least one more 
control in the same sizer with your edit control.

Cheers,
Tony
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.