Problems with CoreGraphics API post-Snow Leopard

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with CoreGraphics API post-Snow Leopard

João Leão
Hi list

I have an old script using the CoreGraphics API that's no longer working properly since Snow Leopard.
I' running Lion with the default Python, which is 2.7.1.
I googled about this and it seems that's because Python is 64-bit now and some old data types don't work anymore.


The first error I got was in the function CGBitmapContextCreateWithColor.
The Console spits the following error:
---
TypeError: in method 'CGBitmapContextCreateWithColor', argument 4 of type 'CGFloat const [5]'
---

My code looks like this:
c = CGBitmapContextCreateWithColor(new_Width, new_Height, cs, (0,0,0,0))

The problem is in the last argument "(0, 0, 0, 0)" [a color reference] which, the new API expects to be CGFloatArray.
I couldn't find any documentation on how to create such an object in python but, fortunately, I found some code here http://stuffineededtoknow.blogspot.pt/2009_01_01_archive.html  that solved this issue:
---
bg = CGFloatArray(5)
c = CGBitmapContextCreateWithColor(new_Width, new_Height, cs, bg)
---


But now I'm getting another error (and I'll probably get some more) with another function that expects a CGFloat object instead of a plain integer.
The code looks like this:
---
self.pdf.drawPlainTextInRect(text_prov, textRect, 10)
---

And the error (again caused by the last argument, in this case "10"):
---
TypeError: in method 'CGContext_drawPlainTextInRect', argument 4 of type 'CGFloat'
---


I'm sure that it can't be so hard to create a CGFloat but I didn't find the right documentation or sample code to do it.
Does anybody know how to do this?

Thanks in advance.
João
_______________________________________________
Pythonmac-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG
Reply | Threaded
Open this post in threaded view
|

Re: Problems with CoreGraphics API post-Snow Leopard

jalopyuser
João Leão <[hidden email]> wrote:

> But now I'm getting another error (and I'll probably get some more) with another function that expects a CGFloat object instead of a plain integer.
> The code looks like this:
> ---
> self.pdf.drawPlainTextInRect(text_prov, textRect, 10)
> ---
>
> And the error (again caused by the last argument, in this case "10"):
> ---
> TypeError: in method 'CGContext_drawPlainTextInRect', argument 4 of type 'CGFloat'
> ---
>
>
> I'm sure that it can't be so hard to create a CGFloat but I didn't find the right documentation or sample code to do it.
> Does anybody know how to do this?

Did you try "self.pdf.drawPlainTextInRect(text_prov, textRect, 10.0)"?

Bill
_______________________________________________
Pythonmac-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG
Reply | Threaded
Open this post in threaded view
|

Re: Problems with CoreGraphics API post-Snow Leopard

João Leão
> João Leão <[hidden email]> wrote:
>
>> But now I'm getting another error (and I'll probably get some more) with another function that expects a CGFloat object instead of a plain integer.
>> The code looks like this:
>> ---
>> self.pdf.drawPlainTextInRect(text_prov, textRect, 10)
>> ---
>>
>> And the error (again caused by the last argument, in this case "10"):
>> ---
>> TypeError: in method 'CGContext_drawPlainTextInRect', argument 4 of type 'CGFloat'
>> ---
>>
>>
>> I'm sure that it can't be so hard to create a CGFloat but I didn't find the right documentation or sample code to do it.
>> Does anybody know how to do this?
>
> Did you try "self.pdf.drawPlainTextInRect(text_prov, textRect, 10.0)"?

Yes I did, but it didn't work.
Thanks anyway.

>
> Bill

_______________________________________________
Pythonmac-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG
Reply | Threaded
Open this post in threaded view
|

Re: Problems with CoreGraphics API post-Snow Leopard

Ronald Oussoren
In reply to this post by João Leão

On 17 Apr, 2012, at 17:48, João Leão wrote:

> Hi list
>
> I have an old script using the CoreGraphics API that's no longer working properly since Snow Leopard.
> I' running Lion with the default Python, which is 2.7.1.
> I googled about this and it seems that's because Python is 64-bit now and some old data types don't work anymore.

Which library do you use? That is, is there "import CoreGraphics" at the top of your file or "import Quartz"?  The former is a Apple library, the latter is part of PyObjC.

Ronald


_______________________________________________
Pythonmac-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG

smime.p7s (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Problems with CoreGraphics API post-Snow Leopard

João Leão

On Apr 19, 2012, at 10:16 AM, Ronald Oussoren wrote:

>
> On 17 Apr, 2012, at 17:48, João Leão wrote:
>
>> Hi list
>>
>> I have an old script using the CoreGraphics API that's no longer working properly since Snow Leopard.
>> I' running Lion with the default Python, which is 2.7.1.
>> I googled about this and it seems that's because Python is 64-bit now and some old data types don't work anymore.
>
> Which library do you use? That is, is there "import CoreGraphics" at the top of your file or "import Quartz"?  The former is a Apple library, the latter is part of PyObjC.

import CoreGraphics. It´s the Apple library.

>
> Ronald
>

_______________________________________________
Pythonmac-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG