Forum: wxRuby Wx::Font.new fails in a Runtime Error

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Кирилл Лиходедов (Guest)
on 2008-10-13 16:43
(Received via mailing list)
Attachment: error.png (0 Bytes)
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
Andreas G. (Guest)
on 2008-10-13 17:17
Кирилл Лиходедов 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)

- andreas
Кирилл Лиходедов (Guest)
on 2008-10-13 17:33
(Received via mailing list)
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 <removed_email_address@domain.invalid>
Кирилл Лиходедов (Guest)
on 2008-10-13 17:44
(Received via mailing list)
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 Кирилл Лиходедов 
<removed_email_address@domain.invalid>
Andreas G. (Guest)
on 2008-10-13 18:17
Кирилл Лиходедов 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 Кирилл Лиходедов <removed_email_address@domain.invalid>

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)
Кирилл Лиходедов (Guest)
on 2008-10-14 11:30
(Received via mailing list)
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 <removed_email_address@domain.invalid>
Alex F. (Guest)
on 2008-10-25 17:47
(Received via mailing list)
Кирилл Лиходедов 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
Kirill L. (Guest)
on 2008-10-26 01:08
(Received via mailing list)
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. ÎÁÐÉÓÁÌ(Á):
This topic is locked and can not be replied to.