invalid font

Hello,

I've given up on wx.lib.plot for my purposes for now, and I'm rendering my
graph myself. On Linux it's starting to look great, but I'm getting an error
on Windows about picking an invalid font.

I'm doing things like this

    def DrawLabels(self, dc):
        """Draw all labels on the graph."""
        size = self.GetClientSize()
        font = dc.GetFont()
        pointSize = font.GetPointSize()

        # The graph title.
        font.SetPointSize(pointSize*1.5)
        dc.SetFont(font)
        dc.DrawText(self.title, int(size.width*0.4), 10)

        # The X and Y axes.
        font.SetPointSize(pointSize)
        dc.SetFont(font)
        # X-axis
        dc.DrawText(self.xaxisLabel, int(size.width*0.5),
self.bottomMargin+25)
        # Y-axis
        dc.DrawRotatedText(self.yaxisLabel,
                           self.leftMargin-35,
                           int(size.height*0.5),
                           90)

I assume that setting point size to values like 1/2 current and 1 1/2 current
are causing invalid fonts on windows. How can I do this portably, and correct
for fonts that don't exist?

Thanks,
Mike

···

--
Michael P. Soulier <msoulier@digitaltorque.ca>
"Any intelligent fool can make things bigger and more complex... It
takes a touch of genius - and a lot of courage to move in the opposite
direction." --Albert Einstein

Michael P. Soulier wrote:

Hello,

I've given up on wx.lib.plot for my purposes for now, and I'm rendering my
graph myself. On Linux it's starting to look great, but I'm getting an error
on Windows about picking an invalid font.

What exactly is the error? Is it an exception? If so, what line is it coming from?

I'm doing things like this

    def DrawLabels(self, dc):
        """Draw all labels on the graph."""
        size = self.GetClientSize()
        font = dc.GetFont()

Has the DC previously had a SetFont call or is this font invalid here?

        pointSize = font.GetPointSize()

        # The graph title.
        font.SetPointSize(pointSize*1.5)
        dc.SetFont(font)
        dc.DrawText(self.title, int(size.width*0.4), 10)

        # The X and Y axes.
        font.SetPointSize(pointSize)
        dc.SetFont(font)
        # X-axis
        dc.DrawText(self.xaxisLabel, int(size.width*0.5),
self.bottomMargin+25)
        # Y-axis
        dc.DrawRotatedText(self.yaxisLabel,
                           self.leftMargin-35,
                           int(size.height*0.5),
                           90)

I assume that setting point size to values like 1/2 current and 1 1/2 current
are causing invalid fonts on windows.

It shouldn't be. The pointSize parameter is an integer, so the floating point portion will be truncated when the API is called.

How can I do this portably, and correct
for fonts that don't exist?

We'll need more details about the error and/or a small runnable sample that demonstrates it.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

What exactly is the error? Is it an exception? If so, what line is it
coming from?

Actually, it's looping forever and I have to interrupt it.

Lots of these

wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed in
..\..\src\m
sw\font.cpp(976): invalid font
Traceback (most recent call last):
  File "MiProfGraph.py", line 172, in OnPaint
    self.InitBuffer()
  File "MiProfGraph.py", line 59, in InitBuffer
    self.DrawLabels(dc)
  File "MiProfGraph.py", line 68, in DrawLabels
    pointSize = font.GetPointSize()
  File "C:\Python24\Lib\site-packages\wx-2.6-msw-ansi\wx\_gdi.py", line 1853,
in
GetPointSize
    return _gdi_.Font_GetPointSize(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed in
..\..\src\m
sw\font.cpp(976): invalid font
Traceback (most recent call last):
  File "MiProfGraph.py", line 172, in OnPaint
    self.InitBuffer()
  File "MiProfGraph.py", line 59, in InitBuffer
    self.DrawLabels(dc)
  File "MiProfGraph.py", line 68, in DrawLabels
    pointSize = font.GetPointSize()
  File "C:\Python24\Lib\site-packages\wx-2.6-msw-ansi\wx\_gdi.py", line 1853,
in
GetPointSize
^C

Has the DC previously had a SetFont call or is this font invalid here?

I didn't set a font previously...

It shouldn't be. The pointSize parameter is an integer, so the floating
point portion will be truncated when the API is called.

I thought that the font just didn't exist...

We'll need more details about the error and/or a small runnable sample
that demonstrates it.

How's the traceback above? I find it odd that it's locked in an infinite loop,
or at least a very long loop.

Mike

···

On 13/07/06 Robin Dunn said:

--
Michael P. Soulier <msoulier@digitaltorque.ca>
"Any intelligent fool can make things bigger and more complex... It
takes a touch of genius - and a lot of courage to move in the opposite
direction." --Albert Einstein

Michael P. Soulier wrote:

What exactly is the error? Is it an exception? If so, what line is it coming from?

Actually, it's looping forever and I have to interrupt it.

Lots of these

wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed in
..\..\src\m
sw\font.cpp(976): invalid font
Traceback (most recent call last):
  File "MiProfGraph.py", line 172, in OnPaint
    self.InitBuffer()
  File "MiProfGraph.py", line 59, in InitBuffer
    self.DrawLabels(dc)
  File "MiProfGraph.py", line 68, in DrawLabels
    pointSize = font.GetPointSize()
  File "C:\Python24\Lib\site-packages\wx-2.6-msw-ansi\wx\_gdi.py", line 1853,
in
GetPointSize
    return _gdi_.Font_GetPointSize(*args, **kwargs)

Has the DC previously had a SetFont call or is this font invalid here?

I didn't set a font previously...

That's the problem then, the font being returned from dc.GetFont() is invalid, which is a signal that the dc's font hasn't been set yet. You can verify by checking the value of font.Ok().

It shouldn't be. The pointSize parameter is an integer, so the floating point portion will be truncated when the API is called.

I thought that the font just didn't exist...

The exception is happening before you are trying to create a new font.

We'll need more details about the error and/or a small runnable sample that demonstrates it.

How's the traceback above? I find it odd that it's locked in an infinite loop,
or at least a very long loop.

This is called from a EVT_PAINT handler, right? A quirk of Windows is that if there is no wx.PaintDC created in the EVT_PAINT handler then the system assumes that the paint hasn't been done yet and so sends another paint event right away.

···

On 13/07/06 Robin Dunn said:

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

>I didn't set a font previously...

That's the problem then, the font being returned from dc.GetFont() is
invalid, which is a signal that the dc's font hasn't been set yet. You
can verify by checking the value of font.Ok().

Ah, ok. I'll set up a default font for the dc first then.

This is called from a EVT_PAINT handler, right? A quirk of Windows is
that if there is no wx.PaintDC created in the EVT_PAINT handler then the
system assumes that the paint hasn't been done yet and so sends another
paint event right away.

Indeed. I put it there so that my graph will repaint itself when the window is
resized.

Thanks,
Mike

···

On 14/07/06 Robin Dunn said:

--
Michael P. Soulier <msoulier@digitaltorque.ca>
"Any intelligent fool can make things bigger and more complex... It
takes a touch of genius - and a lot of courage to move in the opposite
direction." --Albert Einstein

Indeed this was the issue.

Mike

···

On 17/07/06 Michael P. Soulier said:

> That's the problem then, the font being returned from dc.GetFont() is
> invalid, which is a signal that the dc's font hasn't been set yet. You
> can verify by checking the value of font.Ok().

Ah, ok. I'll set up a default font for the dc first then.

--
Michael P. Soulier <msoulier@digitaltorque.ca>
"Any intelligent fool can make things bigger and more complex... It takes a
touch of genius - and a lot of courage to move in the opposite direction."
--Albert Einstein