Hello All,
Here is a snippet for a dialog:
def OnSelectFont(self,event):
data = wx.FontData()
data.EnableEffects(True) dlg = wx.FontDialog(self, data)
if dlg.ShowModal() == wx.ID_OK: data = dlg.GetFontData()
font = data.GetChosenFont() self.fontdata = font.GetNativeFontInfoDesc()
self.eFontInfo.SetValue(self.fontdata)
frmExample(self,self.fontdata).Show(True)
# Don't destroy the dialog until you get everything you need from the
# dialog!
dlg.Destroy()
And here is the form showing the font example:
class frmExample(wx.Frame):
def __init__(self,parent,fontdata):
wx.Frame.__init__(self,parent,-1,'Font example')
font = self.GetFont()
font.SetNativeFontInfo(fontdata)
self.SetFont(font)
p = wx.Label(self,-1,'abcdef ABCDEF 0123456')
When I select a font with the dialog, I get this exception:
Traceback (most recent call last):
File "T:/Python/Lib/mess/wxMegaWidgets/utils/FontSelector.py", line 24, in OnSelectFont
frmExample(self,self.fontdata).Show(True)
File "T:/Python/Lib/mess/wxMegaWidgets/utils/FontSelector.py", line 33, in __init__
font.SetNativeFontInfo(fontdata)
File "C:\Python24\Lib\site-packages\wx-2.6-msw-ansi\wx\_gdi.py", line 1877, in SetNativeFontInfo
return _gdi_.Font_SetNativeFontInfo(*args, **kwargs)
TypeError: argument number 2: a 'wxNativeFontInfo *' is expected, 'str(0;-19;0;0;0;400;0;0;0;0;3;2;1;2;Smilly)' is received
Looks like "GetNativeFontInfoDesc" returns a string but "SetNativeFontInfo" expects a wx.NativeFontInfo instance.
However, the documentation says:
<snip>
wxFont::SetNativeFontInfo
*void* *SetNativeFontInfo*(*const wxString& */info/)
Creates the font corresponding to the given native font description string which must have been previously returned by GetNativeFontInfoDesc <wx_wxfont.html#wxfontgetnativefontinfodesc>. If the string is invalid, font is unchanged.
</snip>
What am I doing wrong?
Les