invalid font
5 answers - 1083 bytes -

Hello,
I've given up on wx.lib.plot for my purposes for now, and I'm rendering my
graph myself. 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
No.1 | | 1503 bytes |
| 
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. 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.
No.2 | | 1812 bytes |
| 
13/07/06 Robin Dunn said:
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 Paint
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 Paint
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
No.3 | | 2018 bytes |
| 
Michael P. Soulier wrote:
13/07/06 Robin Dunn said:
>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 Paint
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 ().
>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.
No.4 | | 760 bytes |
| 
14/07/06 Robin Dunn said:
>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 ().
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
No.5 | | 359 bytes |
| 
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 ().
Ah, ok. I'll set up a default font for the dc first then.
Indeed this was the issue.
Mike