I can’t construct a Wx::Font object, because it leads to a Runtime
Error,
though it seems that I use it as per documentation of WxRuby.
Strangely, many mistakes lead to such an error instead of a verbose Ruby
exception
Could you please help me with this?
Thanks a lot in advance.
Please see the sample code below.
====================
require ‘wx’
class TestFrame < Wx::Frame
def initialize()
super(nil, -1, “CMD”)
Wx::Font.new(12, Wx::Font::FONTFAMILY_DECORATIVE)
end
end
class TestApp < Wx::App
def on_init
TestFrame.new().show()
end
end
TestApp.new.main_loop
Enviroment:
Windows XP SP-2
Ruby 1.8.6
WxRuby 1.9.8
Кирилл Лиходедов wrote:
Wx::Font.new(12, Wx::Font::FONTFAMILY_DECORATIVE)
Try replacing that line with:
Wx::Font.new(12, Wx::FONTFAMILY_DECORATIVE, Wx::FONTSTYLE_NORMAL,
Wx::FONTWEIGHT_NORMAL)
That worked (but why? Aren’t there default values for the rest of the
parameters?), but setting this font as the default style of TextCtrl
leads
to the same error:
text = Wx::TextCtrl.new(self, -1, “text”, :style =>
Wx::TE_RICH|Wx::TE_RICH2|Wx::TE_PROCESS_ENTER|Wx::TE_PROCESS_TAB)
font = Wx::Font.new(12, Wx::FONTFAMILY_DECORATIVE,
Wx::FONTSTYLE_NORMAL,
Wx::FONTWEIGHT_NORMAL)
text.set_default_style(Wx::TextAttr.new(font)) #This leads to
error
By the way, why is it a Runtime threatening error, not an exception?
2008/10/13 Andreas Garnæs [email protected]
Кирилл Лиходедов wrote:
Oops, sorry, that should be
text.set_default_style(Wx::TextAttr.new(Wx::BLACK,
Wx::WHITE, font))
OK, I understand, it works now, thanks for the hint!
But the main problem still exists: it is very hard to determine when you
use
wrong or incomplete method signature, when it just silently fails.Is it
some
configuration problem of mine or it is WxRuby feature?
2008/10/13 Кирилл Лиходедов [email protected]
I guess you just have to read the documentation very carefully. I get
significantly better error messages on Ubuntu, however, eg:
Wx::Font.new(20)
ArgumentError: Wrong arguments for overloaded method ‘wxFont.new’.
Possible C/C++ prototypes are:
wxFont.new()
wxFont.new(int pointSize, int family, int style, int weight, bool
const underline, wxString const &faceName, wxFontEncoding encoding)
Oops, sorry, that should be
text.set_default_style(Wx::TextAttr.new(Wx::BLACK,
Wx::WHITE, font))
OK, I understand, it works now, thanks for the hint!
But the main problem still exists: it is very hard to determine when you
use
wrong or incomplete method signature, when it just silently fails.Is it
some
configuration problem of mine or it is WxRuby feature?
2008/10/13 Кирилл Лиходедов [email protected]
Andreas, you definitely have much more descriptive messages.It looks
like a
problem of Windows version WxRuby, because Ruby itself doesn’t have
these
problems.
Does anybody know if anything can be done with it, maybe in future
releases?
2008/10/13 Andreas Garnæs [email protected]
Кирилл Лиходедов wrote:
Andreas, you definitely have much more descriptive messages.
It looks like a problem of Windows version WxRuby, because Ruby itself
doesn’t have these problems.
Does anybody know if anything can be done with it, maybe in future
releases?
The quality of error messages related to wrong types of arguments was
improved in recent versions of SWIG. I’ll double-check that the next
windows build is done with the latest version.
But when doing some development on Windows recently I had some similar
problems - ie I was getting a segfault where it should be raising an
exception. Which is pretty annoying b/c it’s hard to track these down.
I’ll investigate further.
cheers
alex
Thank you very much, Alex.
That would be very great if the problem will be fixed or at least
improved.
25.10.2008, × 17:45, Alex F. ÎÁÐÉÓÁÌ(Á):