Phoenix: no wx.Font.OSXGetCGFont ?

Hi,

I’m playing around with wx.lib.wxcairo from a recent Phoenix snapshot, using Python 3.3 on Mac OS X 10.8.3. After a few fixes to make it acceptable to Python 3.3 I have managed to get a version of the Cairo example from the wxPython demo running, up to the point where it tries to display text. The error I get is

File “Cairo.py”, line 30, in OnPaint

self.Render(dc)

File “Cairo.py”, line 71, in Render

wx.FFont(10, wx.SWISS, wx.FONTFLAG_BOLD))

File “/Users/colin/Python/wxPython-Phoenix-r73706-darwin-py3.3/wx/lib/wxcairo.py”, line 153, in FontFaceFromFont

fontfaceptr = font_face_create(voidp(font.OSXGetCGFont()))

AttributeError: ‘Font’ object has no attribute ‘OSXGetCGFont’

I’ve googled for information about the removal of OSXGetCGFont from wx.Font without much luck. Can anyone give me a hint on how to get the underlying CGFontRef from a wx.Font on Phoenix?

Thanks!

– CMcP

CMcP wrote:

Hi,

I'm playing around with wx.lib.wxcairo from a recent Phoenix snapshot,
using Python 3.3 on Mac OS X 10.8.3. After a few fixes to make it
acceptable to Python 3.3 I have managed to get a version of the Cairo
example from the wxPython demo running, up to the point where it tries
to display text. The error I get is
File "Cairo.py", line 30, in OnPaint
self.Render(dc)
File "Cairo.py", line 71, in Render
wx.FFont(10, wx.SWISS, wx.FONTFLAG_BOLD))
File
"/Users/colin/Python/wxPython-Phoenix-r73706-darwin-py3.3/wx/lib/wxcairo.py",
line 153, in FontFaceFromFont
fontfaceptr = font_face_create(voidp(font.OSXGetCGFont()))
AttributeError: 'Font' object has no attribute 'OSXGetCGFont'

I've googled for information about the removal of OSXGetCGFont from
wx.Font without much luck. Can anyone give me a hint on how to get the
underlying CGFontRef from a wx.Font on Phoenix?

It's an undocumented method, so I'll need to manually add it back in to the wx.Font wrapper.

···

--
Robin Dunn
Software Craftsman

Robin Dunn wrote:

CMcP wrote:

Hi,

I'm playing around with wx.lib.wxcairo from a recent Phoenix snapshot,
using Python 3.3 on Mac OS X 10.8.3. After a few fixes to make it
acceptable to Python 3.3 I have managed to get a version of the Cairo
example from the wxPython demo running, up to the point where it tries
to display text. The error I get is
File "Cairo.py", line 30, in OnPaint
self.Render(dc)
File "Cairo.py", line 71, in Render
wx.FFont(10, wx.SWISS, wx.FONTFLAG_BOLD))
File
"/Users/colin/Python/wxPython-Phoenix-r73706-darwin-py3.3/wx/lib/wxcairo.py",

line 153, in FontFaceFromFont
fontfaceptr = font_face_create(voidp(font.OSXGetCGFont()))
AttributeError: 'Font' object has no attribute 'OSXGetCGFont'

I've googled for information about the removal of OSXGetCGFont from
wx.Font without much luck. Can anyone give me a hint on how to get the
underlying CGFontRef from a wx.Font on Phoenix?

It's an undocumented method, so I'll need to manually add it back in to
the wx.Font wrapper.

I've added it and the equivalent for MSW and GTK. It will be in the snapshot build done tonight. The methods will either return None or a sip.voidptr object, which can be converted to an integer object to get the actual pointer value. I think this is the same as it worked in Classic so all should be good. If not please send a patch with whatever changes you needed to make.

···

--
Robin Dunn
Software Craftsman

Thank you! I will try it out (the Mac OS X variant) and report back.

···

On Thursday, 28 March 2013 00:29:16 UTC, Robin Dunn wrote:

I’ve added it and the equivalent for MSW and GTK. It will be in the
snapshot build done tonight. The methods will either return None or a
sip.voidptr object, which can be converted to an integer object to get
the actual pointer value. I think this is the same as it worked in
Classic so all should be good. If not please send a patch with whatever
changes you needed to make.

I’ve added it and the equivalent for MSW and GTK. It will be in the
snapshot build done tonight. The methods will either return None or a
sip.voidptr object, which can be converted to an integer object to get
the actual pointer value. I think this is the same as it worked in
Classic so all should be good. If not please send a patch with whatever
changes you needed to make.

Thank you! I will try it out (the Mac OS X variant) and report back.

The wrapper for OSXGetCGFont worked fine, thank you. I had to make some other changes to get wxcairo.py to work with python 3.3. Also, I couldn’t resist a very small amount of refactoring in the name of efficiency - sorry.

I have attached file wxcairo.tgz which contains my version of wx.lib.wxcairo.py, a diff of same versus the original, and Cairo.py which is an example program ripped from the wx demo. The example runs OK except that it doesn’t display bmp2 (see end of method render). I think Mac OS X, or the Mac implementation of wxWidgets, must be picky about the order of doing things: if the code that creates bmp2 and writes it to the DC is moved to before any Cairo drawing commands then bmp2 gets displayed OK.

I have only run this code on Mac OS X 10.8.3 using

wxcairo.tgz (6.71 KB)

···

On Thursday, 28 March 2013 09:08:18 UTC, CMcP wrote:

On Thursday, 28 March 2013 00:29:16 UTC, Robin Dunn wrote:

Python 3.3.0 final 0

WxPython 2.9.5.80 osx-cocoa (phoenix)

Cairo 1.12.14

PyCairo 1.10.1

CMcP wrote:

        I've added it and the equivalent for MSW and GTK. It will be in the
        snapshot build done tonight. The methods will either return None
        or a
        sip.voidptr object, which can be converted to an integer object
        to get
        the actual pointer value. I think this is the same as it worked in
        Classic so all should be good. If not please send a patch with
        whatever
        changes you needed to make.

    Thank you! I will try it out (the Mac OS X variant) and report back.

The wrapper for OSXGetCGFont worked fine, thank you. I had to make some
other changes to get wxcairo.py to work with python 3.3. Also, I
couldn't resist a very small amount of refactoring in the name of
efficiency - sorry.

I have attached file wxcairo.tgz which contains my version of
wx.lib.wxcairo.py, a diff of same versus the original, and Cairo.py
which is an example program ripped from the wx demo.

Could you please redo the patch file using either "git diff" or "svn diff" if you've got the source checked out that way, or use the -u diff flag so it generates it in the unified diff format. Thanks.

The example runs OK
except that it doesn't display bmp2 (see end of method render). I think
Mac OS X, or the Mac implementation of wxWidgets, must be picky about
the order of doing things: if the code that creates bmp2 and writes it
to the DC is moved to before any Cairo drawing commands then bmp2 gets
displayed OK.

That's not too surprising actually. Cairo is probably buffering the drawing it is doing, or perhaps just taking over the CGContext, in a way that it overwrites or skips what is dawn using the wxDC directly.

···

On Thursday, 28 March 2013 09:08:18 UTC, CMcP wrote:
    On Thursday, 28 March 2013 00:29:16 UTC, Robin Dunn wrote:

--
Robin Dunn
Software Craftsman

I’ve attached wxcairo-u.diff.

Regards,

– CMcP

wxcairo-u.diff (7.86 KB)

···

On Saturday, 30 March 2013 04:25:00 UTC, Robin Dunn wrote:

Could you please redo the patch file using either “git diff” or “svn
diff” if you’ve got the source checked out that way, or use the -u diff
flag so it generates it in the unified diff format. Thanks.

CMcP wrote:

    Could you please redo the patch file using either "git diff" or "svn
    diff" if you've got the source checked out that way, or use the -u diff
    flag so it generates it in the unified diff format. Thanks.

I've attached wxcairo-u.diff.

Thanks

···

On Saturday, 30 March 2013 04:25:00 UTC, Robin Dunn wrote:

--
Robin Dunn
Software Craftsman