pyobjc-dev Mailing List for PyObjC (Page 46)
Brought to you by:
ronaldoussoren
You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(9) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(1) |
Feb
(2) |
Mar
(3) |
Apr
(30) |
May
(18) |
Jun
|
Jul
(4) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2002 |
Jan
(7) |
Feb
(2) |
Mar
(1) |
Apr
|
May
|
Jun
(3) |
Jul
(13) |
Aug
|
Sep
(23) |
Oct
(180) |
Nov
(291) |
Dec
(95) |
2003 |
Jan
(338) |
Feb
(352) |
Mar
(97) |
Apr
(46) |
May
(226) |
Jun
(184) |
Jul
(145) |
Aug
(141) |
Sep
(69) |
Oct
(161) |
Nov
(96) |
Dec
(90) |
2004 |
Jan
(66) |
Feb
(87) |
Mar
(98) |
Apr
(132) |
May
(115) |
Jun
(68) |
Jul
(150) |
Aug
(92) |
Sep
(59) |
Oct
(52) |
Nov
(17) |
Dec
(75) |
2005 |
Jan
(84) |
Feb
(191) |
Mar
(133) |
Apr
(114) |
May
(158) |
Jun
(185) |
Jul
(62) |
Aug
(28) |
Sep
(36) |
Oct
(88) |
Nov
(65) |
Dec
(43) |
2006 |
Jan
(85) |
Feb
(62) |
Mar
(92) |
Apr
(75) |
May
(68) |
Jun
(101) |
Jul
(73) |
Aug
(37) |
Sep
(91) |
Oct
(65) |
Nov
(30) |
Dec
(39) |
2007 |
Jan
(24) |
Feb
(28) |
Mar
(10) |
Apr
(2) |
May
(18) |
Jun
(16) |
Jul
(21) |
Aug
(6) |
Sep
(30) |
Oct
(31) |
Nov
(153) |
Dec
(31) |
2008 |
Jan
(63) |
Feb
(70) |
Mar
(47) |
Apr
(24) |
May
(59) |
Jun
(22) |
Jul
(12) |
Aug
(7) |
Sep
(14) |
Oct
(26) |
Nov
(5) |
Dec
(5) |
2009 |
Jan
(10) |
Feb
(41) |
Mar
(70) |
Apr
(88) |
May
(49) |
Jun
(62) |
Jul
(34) |
Aug
(15) |
Sep
(55) |
Oct
(40) |
Nov
(67) |
Dec
(21) |
2010 |
Jan
(60) |
Feb
(17) |
Mar
(26) |
Apr
(26) |
May
(29) |
Jun
(4) |
Jul
(21) |
Aug
(21) |
Sep
(10) |
Oct
(12) |
Nov
(3) |
Dec
(19) |
2011 |
Jan
(3) |
Feb
(13) |
Mar
(8) |
Apr
(8) |
May
(17) |
Jun
(20) |
Jul
(21) |
Aug
(7) |
Sep
|
Oct
|
Nov
(9) |
Dec
(11) |
2012 |
Jan
(3) |
Feb
|
Mar
|
Apr
(5) |
May
(4) |
Jun
(14) |
Jul
(5) |
Aug
(2) |
Sep
(15) |
Oct
(2) |
Nov
(23) |
Dec
(1) |
2013 |
Jan
(8) |
Feb
(1) |
Mar
|
Apr
|
May
(5) |
Jun
(1) |
Jul
(5) |
Aug
(4) |
Sep
|
Oct
(12) |
Nov
(10) |
Dec
(3) |
2014 |
Jan
(7) |
Feb
(14) |
Mar
(2) |
Apr
|
May
(2) |
Jun
(11) |
Jul
(10) |
Aug
(4) |
Sep
|
Oct
(8) |
Nov
(1) |
Dec
(2) |
2015 |
Jan
(9) |
Feb
(7) |
Mar
(1) |
Apr
|
May
(7) |
Jun
|
Jul
(5) |
Aug
(6) |
Sep
|
Oct
(1) |
Nov
(4) |
Dec
|
2016 |
Jan
(1) |
Feb
(1) |
Mar
(4) |
Apr
(2) |
May
(1) |
Jun
|
Jul
(6) |
Aug
(8) |
Sep
(21) |
Oct
(17) |
Nov
|
Dec
(36) |
2017 |
Jan
(6) |
Feb
(2) |
Mar
(4) |
Apr
(2) |
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
(1) |
Dec
(6) |
2018 |
Jan
(2) |
Feb
(3) |
Mar
(3) |
Apr
(14) |
May
(2) |
Jun
(2) |
Jul
(4) |
Aug
(3) |
Sep
(6) |
Oct
(16) |
Nov
(1) |
Dec
(6) |
2019 |
Jan
(3) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
(6) |
Nov
|
Dec
|
2020 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(2) |
Jun
(1) |
Jul
(7) |
Aug
(1) |
Sep
(1) |
Oct
|
Nov
(2) |
Dec
(1) |
2021 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
(5) |
Sep
(1) |
Oct
|
Nov
(1) |
Dec
|
2023 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
2025 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Ron G. <ro...@fl...> - 2009-05-19 07:20:29
|
[Apologies if this is a repeat. First attempt seems to have failed.] Followed the instructions and got this on a Macbook Pro (i.e. an Intel machine) running Python 2.6, OS X 10.5.6 and XCode 3.0: [ron@mickey:~]$ sudo easy_install pyobjc==2.2b1 Searching for pyobjc==2.2b1 Best match: pyobjc 2.2b1 Processing pyobjc-2.2b1-py2.6.egg pyobjc 2.2b1 is already the active version in easy-install.pth Using /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/pyobjc-2.2b1-py2.6.egg Processing dependencies for pyobjc==2.2b1 Searching for pyobjc-framework-ScreenSaver==2.2b1 Reading http://pypi.python.org/simple/pyobjc-framework-ScreenSaver/ Reading http://pyobjc.sourceforge.net Best match: pyobjc-framework-ScreenSaver 2.2b1 Downloading http://pypi.python.org/packages/source/p/pyobjc-framework-ScreenSaver/pyobjc-framework-ScreenSaver-2.2b1.tar.gz#md5 =efc75de2224a13c1726b67307c37a99e Processing pyobjc-framework-ScreenSaver-2.2b1.tar.gz Running pyobjc-framework-ScreenSaver-2.2b1/setup.py -q bdist_egg -- dist-dir /var/folders/nT/nTiypn-v2RatkU+BYncrKU+++TI/-Tmp-/ easy_install-m0V45R/pyobjc-framework-ScreenSaver-2.2b1/egg-dist-tmp- fWseAC /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ distutils/dist.py:266: UserWarning: Unknown distribution option: 'options' warnings.warn(msg) ld: in /Developer/SDKs/MacOSX10.4u.sdk/usr/local/lib/libTIFF.dylib, file is not of required architecture for architecture ppc collect2: ld returned 1 exit status lipo: can't open input file: /var/folders/nT/nTiypn-v2RatkU+BYncrKU++ +TI/-Tmp-//ccuez0lM.out (No such file or directory) error: Setup script exited with error: command 'gcc' failed with exit status 1 Clues appreciated. Thanks. rg |
From: Jonas O. <jo...@fr...> - 2009-05-18 18:15:14
|
Hi, I'm having the same problem as the author of this post: http://news.gmane.org/gmane.comp.python.pyobjc.devel/cutoff=5048 Basically, my application crashes whenever I try to invoke 'setFrame' on the animator proxy. 'performSelector' works fine, but as the author of the original post already noted isn't of much use when you can't pass in any values. I tried using NSInvocation, but that crashes the application, too. Could this be a bug in PyObjC? Jonas |
From: Ron G. <ro...@fl...> - 2009-05-16 23:18:01
|
Followed the instructions and got this on a Macbook Pro (i.e. an Intel machine) running Python 2.6, OS X 10.5.6 and XCode 3.0: [ron@mickey:~]$ sudo easy_install pyobjc==2.2b1 Searching for pyobjc==2.2b1 Best match: pyobjc 2.2b1 Processing pyobjc-2.2b1-py2.6.egg pyobjc 2.2b1 is already the active version in easy-install.pth Using /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/pyobjc-2.2b1-py2.6.egg Processing dependencies for pyobjc==2.2b1 Searching for pyobjc-framework-ScreenSaver==2.2b1 Reading http://pypi.python.org/simple/pyobjc-framework-ScreenSaver/ Reading http://pyobjc.sourceforge.net Best match: pyobjc-framework-ScreenSaver 2.2b1 Downloading http://pypi.python.org/packages/source/p/pyobjc-framework-ScreenSaver/pyobjc-framework-ScreenSaver-2.2b1.tar.gz#md5 =efc75de2224a13c1726b67307c37a99e Processing pyobjc-framework-ScreenSaver-2.2b1.tar.gz Running pyobjc-framework-ScreenSaver-2.2b1/setup.py -q bdist_egg -- dist-dir /var/folders/nT/nTiypn-v2RatkU+BYncrKU+++TI/-Tmp-/ easy_install-m0V45R/pyobjc-framework-ScreenSaver-2.2b1/egg-dist-tmp- fWseAC /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ distutils/dist.py:266: UserWarning: Unknown distribution option: 'options' warnings.warn(msg) ld: in /Developer/SDKs/MacOSX10.4u.sdk/usr/local/lib/libTIFF.dylib, file is not of required architecture for architecture ppc collect2: ld returned 1 exit status lipo: can't open input file: /var/folders/nT/nTiypn-v2RatkU+BYncrKU++ +TI/-Tmp-//ccuez0lM.out (No such file or directory) error: Setup script exited with error: command 'gcc' failed with exit status 1 Clues appreciated. Thanks. rg |
From: Ronald O. <ron...@ma...> - 2009-05-16 06:21:13
|
On 15 May, 2009, at 18:25, Ilan Volow wrote: > > I've googled around for a little while, and I haven't found a clear, > up-to-date answer on this. > > Does PyObjc work with Python 3.0 yet, or is it still a work in > process? Would betting on Python 3.0+PyObjC working together in 10.6 > be a sure bet, or should I take the safe route and write my project > purely in Objective-C for the time being? PyObjC does not work with Python 3.x yet. I have looked at this, and this will be a signifant effort both because of changes in the Python extension API and because of changes in the language (such as abstract base classes). I want to get 2.2 out before a start working on that. 10.6 support will happen, but I can neither talk about that nor provide code without breaking NDA. W.r.t. your last question: why is Python 2.6 not an option for you? IMHO Python 3.0 shouldn't be used for application development, the python.org team is working hard on a release of Python 3.1 because that will fix some serious annoyances with 3.0. Even then a large subset of Python libraries won't support Python 3. Ronald > > -- Ilan > > ------------------------------------------------------------------------------ > Crystal Reports - New Free Runtime and 30 Day Trial > Check out the new simplified licensing option that enables > unlimited royalty-free distribution of the report engine > for externally facing server and web deployment. > http://p.sf.net/sfu/businessobjects > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |
From: Ronald O. <ron...@ma...> - 2009-05-16 06:16:00
|
On 15 May, 2009, at 15:50, Mic Pringle wrote: > Hi, > > I primarily develop using x-code on Leopard, and was wondering if you > can set it up to include any dependencies in the built application > bundle, in the same way you can with py2app ? If so, how ? Not really. Adding code to py2app to do this is on my todo list, but that's probably not something I'll get around to soon. Ronald > > Thanks > > -Mic > > ------------------------------------------------------------------------------ > Crystal Reports - New Free Runtime and 30 Day Trial > Check out the new simplified licensing option that enables > unlimited royalty-free distribution of the report engine > for externally facing server and web deployment. > http://p.sf.net/sfu/businessobjects > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |
From: Orestis M. <or...@or...> - 2009-05-15 17:00:44
|
I haven't seen any checkins relating to Python 3 yet, so barring any ultra-secret work on this (or perhaps a branch I haven't noticed), I'd say that Python 3 work hasn't even started yet. That said, the safest bet is to use the current stable, released version of PyObjC, or even helping out with the 2.2 beta. I'm confused about the "purely Objective-C" option. That is clearly the safest thing to do, but you will not gain any of the benefits PyObjC gives you. With regard to 10.6, even if Ronald has done any work on it, he's probably under NDA and will not be able to confirm anything at this point. Orestis -- or...@or... http://orestis.gr/ On 15 May 2009, at 19:25, Ilan Volow wrote: > > I've googled around for a little while, and I haven't found a clear, > up-to-date answer on this. > > Does PyObjc work with Python 3.0 yet, or is it still a work in > process? Would betting on Python 3.0+PyObjC working together in 10.6 > be a sure bet, or should I take the safe route and write my project > purely in Objective-C for the time being? > > -- Ilan > > ------------------------------------------------------------------------------ > Crystal Reports - New Free Runtime and 30 Day Trial > Check out the new simplified licensing option that enables > unlimited royalty-free distribution of the report engine > for externally facing server and web deployment. > http://p.sf.net/sfu/businessobjects > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |
From: Ilan V. <li...@cl...> - 2009-05-15 16:51:54
|
I've googled around for a little while, and I haven't found a clear, up-to-date answer on this. Does PyObjc work with Python 3.0 yet, or is it still a work in process? Would betting on Python 3.0+PyObjC working together in 10.6 be a sure bet, or should I take the safe route and write my project purely in Objective-C for the time being? -- Ilan |
From: Mic P. <mic...@gm...> - 2009-05-15 13:55:45
|
Hi, I primarily develop using x-code on Leopard, and was wondering if you can set it up to include any dependencies in the built application bundle, in the same way you can with py2app ? If so, how ? Thanks -Mic |
From: Ronald O. <ron...@ma...> - 2009-05-13 19:30:37
|
On 13 May, 2009, at 21:26, James Kelly wrote: > On 4/16/09 3:36 AM, "Ronald Oussoren" <ron...@ma...> wrote: >> Yikes, I really need to start testing with a standard build of Python >> again. My guess is that the problem is caused by ' -isysroot / >> Developer/SDKs/MacOSX10.4u.sdk ' in the compiler flags below. This >> forces the compiler to use the system headers for 10.4, even when >> building on 10.5. >> >> I have an idea on how to work around this (basicly force usage of - >> isysroot=/ on OSX 10.5 or later), but won't have time to commit >> such a >> change today. > > Hi Ronald, > > I'm having the same problem (except I'm attempting to use Python > 2.6). I > tried changing -isysroot to / instead of /Developer/SDKs/ > MacOSX10.4u.sdk, > but while it got further it still failed to completely install > (failed with > the message I'll paste below). Any ideas? Easy_install fails with a > similar error. Your problem is that you have some non-universal libraries installed in /usr/local, which get picked up by the compiler. Getting the compiler to ignore /usr/local is annoyingly hard although I'll probably try to find a clean way to do that. Luckily that would only be needed in pyobjc core, which already has a complicated setup.py script. Ronald |
From: Ronald O. <ron...@ma...> - 2009-05-10 17:15:27
|
On 10 May, 2009, at 19:06, Mic Pringle wrote: > Ronald, > > So is there no way at all the be able to call a Python pyobj-c class > from Obj-C as from your earlier response you did imply this ?? > > '...the same is true for methods you add in a subclass, those can be > called from ObjC as well...' You can call methods on a class that's defined in Python. You cannot have direct references to a class that's defined in Python though. That is: BKTextile* object = [BKTextile new]; // This get's you a link-time error BKTextile* object = [NSClassFromString(@"BKTextile") new] // This should work > > I'm mainly a Obj-C programmer, and have only recently turned to > PyObj-c as a way to utilise many libraries that simply aren't > available to Obj-C, such as for processing Textile and Yaml ? > > I have got it working so far using another method I found on the > internet which involves creating a wrapper class for the Python part > and using NSClassFromString to instantiate the class, but I was hoping > to drop these two extra files in favour of just using a header file > and the original Python file like with the category stuff. Is this > then not possible ? AFAIK the only limitation is that you cannot have [APythonClass classmethod] in your code, you must use NSClassFromString to access the class object. This is purely for technical limitations, the ObjC compiler needs link-time access to the class when you call a classmethod, and that's impossible to arrange for using PyObjC. Ronald > > Thank > > -Mic > > > 2009/5/10 Ronald Oussoren <ron...@ma...>: >> Mic, >> >> You cannot refer to the class directly in Objective-C, that's >> because PyObjC >> will create the class at runtime and your ObjC code tries to link >> to it at >> compile-time. >> >> I tend to write all my code in Python, using ObjC as a way to >> optimize code >> where needed and to access API's that are not available in Python. >> This >> means I tend to be able to get away with creating instances in >> Python code, >> while still calling methods on them in ObjC. >> >> Ronald >> >> On 10 May, 2009, at 18:26, Mic Pringle wrote: >> >>> Hi Ronald, >>> >>> As you have probably seen, I now have categories working fine, >>> thanks >>> to your help. >>> >>> You mentioned in one of your earlier replies that I can also do the >>> same for subclasses, not just categories. So following this I have >>> created a header file in Objective-C with the following contents ... >>> >>> #import <Cocoa/Cocoa.h> >>> >>> @interface BKTextile : NSObject >>> >>> - (NSString *)decodeTextile:(NSString *)aString; >>> >>> @end >>> >>> And then created the following Python implementation ... >>> >>> from Foundation import * >>> import textile >>> >>> class BKTextile(NSObject): >>> >>> def decodeTextile_(self, aString): >>> return u"it worked!" >>> >>> Which is pretty much what I've done to get the category to work, >>> except when I try to compile I get the following error ... >>> >>> .objc_class_name_BKTextile referenced from: >>> literal-pointer@_OBJC@__cls_refs@BKTextile in PythonServerTest.o >>> symbol(s) not found >>> >>> Any ideas ?? >>> >>> Thanks, >>> >>> Mic >>> >>> >>> 2009/5/8 Ronald Oussoren <ron...@ma...>: >>>> >>>> On Friday, May 08, 2009, at 10:59AM, "Mic Pringle" <mic...@gm... >>>> > >>>> wrote: >>>>> >>>>> Hi, >>>>> >>>>> Just a quick question regarding categories. >>>>> >>>>> I have a hybrid Obj-c/PyObj-c application and I'd like to know >>>>> if I >>>>> add a category in a PyObj-c module, will it be availble to use >>>>> in the >>>>> Obj-c side of the project ?? >>>>> >>>>> If so, does it just work or are there any special instructions I >>>>> need >>>>> to follow to get it working ? >>>> >>>> Methods you add using an Python category are available in ObjC as >>>> well >>>> (the same is true for methods you add in a subclass, those can be >>>> called >>>> from ObjC as well). >>>> >>>> Two possible sources for confusion/problems: >>>> >>>> * Unless the methods you add are already known to the compiler >>>> you'll >>>> have to write a header file that the ObjC compiler >>>> can use. You'll get compiler warnings otherwise. >>>> >>>> * Methods that you add in python by default have arguments and a >>>> return >>>> value of type 'id'. This can be overridden by: >>>> >>>> - information extracted from the superclass (if you override a >>>> method >>>> PyObjC knows the new method should have the >>>> same signature as the one in a superclass). >>>> - the method is defined in an informal_protocol that's known to >>>> PyObjC, >>>> the method signature is then extracted from >>>> that protocol >>>> - manual annotations (objc.accessor, objc.selector, ....) >>>> >>>> Ronald >>>>> >>>>> Thanks >>>>> >>>>> -Mic >>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> The NEW KODAK i700 Series Scanners deliver under ANY >>>>> circumstances! Your >>>>> production scanning environment may not be a perfect world - but >>>>> thanks >>>>> to >>>>> Kodak, there's a perfect scanner to get the job done! With the >>>>> NEW KODAK >>>>> i700 >>>>> Series Scanner you'll get full speed at 300 dpi even with all >>>>> image >>>>> processing features enabled. http://p.sf.net/sfu/kodak-com >>>>> _______________________________________________ >>>>> Pyobjc-dev mailing list >>>>> Pyo...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev >>>>> >>>>> >>>> >> >> |
From: Mic P. <mic...@gm...> - 2009-05-10 17:06:08
|
Ronald, So is there no way at all the be able to call a Python pyobj-c class from Obj-C as from your earlier response you did imply this ?? '...the same is true for methods you add in a subclass, those can be called from ObjC as well...' I'm mainly a Obj-C programmer, and have only recently turned to PyObj-c as a way to utilise many libraries that simply aren't available to Obj-C, such as for processing Textile and Yaml ? I have got it working so far using another method I found on the internet which involves creating a wrapper class for the Python part and using NSClassFromString to instantiate the class, but I was hoping to drop these two extra files in favour of just using a header file and the original Python file like with the category stuff. Is this then not possible ? Thank -Mic 2009/5/10 Ronald Oussoren <ron...@ma...>: > Mic, > > You cannot refer to the class directly in Objective-C, that's because PyObjC > will create the class at runtime and your ObjC code tries to link to it at > compile-time. > > I tend to write all my code in Python, using ObjC as a way to optimize code > where needed and to access API's that are not available in Python. This > means I tend to be able to get away with creating instances in Python code, > while still calling methods on them in ObjC. > > Ronald > > On 10 May, 2009, at 18:26, Mic Pringle wrote: > >> Hi Ronald, >> >> As you have probably seen, I now have categories working fine, thanks >> to your help. >> >> You mentioned in one of your earlier replies that I can also do the >> same for subclasses, not just categories. So following this I have >> created a header file in Objective-C with the following contents ... >> >> #import <Cocoa/Cocoa.h> >> >> @interface BKTextile : NSObject >> >> - (NSString *)decodeTextile:(NSString *)aString; >> >> @end >> >> And then created the following Python implementation ... >> >> from Foundation import * >> import textile >> >> class BKTextile(NSObject): >> >> def decodeTextile_(self, aString): >> return u"it worked!" >> >> Which is pretty much what I've done to get the category to work, >> except when I try to compile I get the following error ... >> >> .objc_class_name_BKTextile referenced from: >> literal-pointer@_OBJC@__cls_refs@BKTextile in PythonServerTest.o >> symbol(s) not found >> >> Any ideas ?? >> >> Thanks, >> >> Mic >> >> >> 2009/5/8 Ronald Oussoren <ron...@ma...>: >>> >>> On Friday, May 08, 2009, at 10:59AM, "Mic Pringle" <mic...@gm...> >>> wrote: >>>> >>>> Hi, >>>> >>>> Just a quick question regarding categories. >>>> >>>> I have a hybrid Obj-c/PyObj-c application and I'd like to know if I >>>> add a category in a PyObj-c module, will it be availble to use in the >>>> Obj-c side of the project ?? >>>> >>>> If so, does it just work or are there any special instructions I need >>>> to follow to get it working ? >>> >>> Methods you add using an Python category are available in ObjC as well >>> (the same is true for methods you add in a subclass, those can be called >>> from ObjC as well). >>> >>> Two possible sources for confusion/problems: >>> >>> * Unless the methods you add are already known to the compiler you'll >>> have to write a header file that the ObjC compiler >>> can use. You'll get compiler warnings otherwise. >>> >>> * Methods that you add in python by default have arguments and a return >>> value of type 'id'. This can be overridden by: >>> >>> - information extracted from the superclass (if you override a method >>> PyObjC knows the new method should have the >>> same signature as the one in a superclass). >>> - the method is defined in an informal_protocol that's known to PyObjC, >>> the method signature is then extracted from >>> that protocol >>> - manual annotations (objc.accessor, objc.selector, ....) >>> >>> Ronald >>>> >>>> Thanks >>>> >>>> -Mic >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your >>>> production scanning environment may not be a perfect world - but thanks >>>> to >>>> Kodak, there's a perfect scanner to get the job done! With the NEW KODAK >>>> i700 >>>> Series Scanner you'll get full speed at 300 dpi even with all image >>>> processing features enabled. http://p.sf.net/sfu/kodak-com >>>> _______________________________________________ >>>> Pyobjc-dev mailing list >>>> Pyo...@li... >>>> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev >>>> >>>> >>> > > |
From: Ronald O. <ron...@ma...> - 2009-05-10 16:55:05
|
Mic, You cannot refer to the class directly in Objective-C, that's because PyObjC will create the class at runtime and your ObjC code tries to link to it at compile-time. I tend to write all my code in Python, using ObjC as a way to optimize code where needed and to access API's that are not available in Python. This means I tend to be able to get away with creating instances in Python code, while still calling methods on them in ObjC. Ronald On 10 May, 2009, at 18:26, Mic Pringle wrote: > Hi Ronald, > > As you have probably seen, I now have categories working fine, thanks > to your help. > > You mentioned in one of your earlier replies that I can also do the > same for subclasses, not just categories. So following this I have > created a header file in Objective-C with the following contents ... > > #import <Cocoa/Cocoa.h> > > @interface BKTextile : NSObject > > - (NSString *)decodeTextile:(NSString *)aString; > > @end > > And then created the following Python implementation ... > > from Foundation import * > import textile > > class BKTextile(NSObject): > > def decodeTextile_(self, aString): > return u"it worked!" > > Which is pretty much what I've done to get the category to work, > except when I try to compile I get the following error ... > > .objc_class_name_BKTextile referenced from: > literal-pointer@_OBJC@__cls_refs@BKTextile in PythonServerTest.o > symbol(s) not found > > Any ideas ?? > > Thanks, > > Mic > > > 2009/5/8 Ronald Oussoren <ron...@ma...>: >> >> On Friday, May 08, 2009, at 10:59AM, "Mic Pringle" <mic...@gm... >> > wrote: >>> Hi, >>> >>> Just a quick question regarding categories. >>> >>> I have a hybrid Obj-c/PyObj-c application and I'd like to know if I >>> add a category in a PyObj-c module, will it be availble to use in >>> the >>> Obj-c side of the project ?? >>> >>> If so, does it just work or are there any special instructions I >>> need >>> to follow to get it working ? >> >> Methods you add using an Python category are available in ObjC as >> well (the same is true for methods you add in a subclass, those can >> be called from ObjC as well). >> >> Two possible sources for confusion/problems: >> >> * Unless the methods you add are already known to the compiler >> you'll have to write a header file that the ObjC compiler >> can use. You'll get compiler warnings otherwise. >> >> * Methods that you add in python by default have arguments and a >> return value of type 'id'. This can be overridden by: >> >> - information extracted from the superclass (if you override a >> method PyObjC knows the new method should have the >> same signature as the one in a superclass). >> - the method is defined in an informal_protocol that's known to >> PyObjC, the method signature is then extracted from >> that protocol >> - manual annotations (objc.accessor, objc.selector, ....) >> >> Ronald >>> Thanks >>> >>> -Mic >>> >>> ------------------------------------------------------------------------------ >>> The NEW KODAK i700 Series Scanners deliver under ANY >>> circumstances! Your >>> production scanning environment may not be a perfect world - but >>> thanks to >>> Kodak, there's a perfect scanner to get the job done! With the NEW >>> KODAK i700 >>> Series Scanner you'll get full speed at 300 dpi even with all image >>> processing features enabled. http://p.sf.net/sfu/kodak-com >>> _______________________________________________ >>> Pyobjc-dev mailing list >>> Pyo...@li... >>> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev >>> >>> >> |
From: Mic P. <mic...@gm...> - 2009-05-10 16:26:51
|
Hi Ronald, As you have probably seen, I now have categories working fine, thanks to your help. You mentioned in one of your earlier replies that I can also do the same for subclasses, not just categories. So following this I have created a header file in Objective-C with the following contents ... #import <Cocoa/Cocoa.h> @interface BKTextile : NSObject - (NSString *)decodeTextile:(NSString *)aString; @end And then created the following Python implementation ... from Foundation import * import textile class BKTextile(NSObject): def decodeTextile_(self, aString): return u"it worked!" Which is pretty much what I've done to get the category to work, except when I try to compile I get the following error ... .objc_class_name_BKTextile referenced from: literal-pointer@_OBJC@__cls_refs@BKTextile in PythonServerTest.o symbol(s) not found Any ideas ?? Thanks, Mic 2009/5/8 Ronald Oussoren <ron...@ma...>: > > On Friday, May 08, 2009, at 10:59AM, "Mic Pringle" <mic...@gm...> wrote: >>Hi, >> >>Just a quick question regarding categories. >> >>I have a hybrid Obj-c/PyObj-c application and I'd like to know if I >>add a category in a PyObj-c module, will it be availble to use in the >>Obj-c side of the project ?? >> >>If so, does it just work or are there any special instructions I need >>to follow to get it working ? > > Methods you add using an Python category are available in ObjC as well (the same is true for methods you add in a subclass, those can be called from ObjC as well). > > Two possible sources for confusion/problems: > > * Unless the methods you add are already known to the compiler you'll have to write a header file that the ObjC compiler > can use. You'll get compiler warnings otherwise. > > * Methods that you add in python by default have arguments and a return value of type 'id'. This can be overridden by: > > - information extracted from the superclass (if you override a method PyObjC knows the new method should have the > same signature as the one in a superclass). > - the method is defined in an informal_protocol that's known to PyObjC, the method signature is then extracted from > that protocol > - manual annotations (objc.accessor, objc.selector, ....) > > Ronald >>Thanks >> >>-Mic >> >>------------------------------------------------------------------------------ >>The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your >>production scanning environment may not be a perfect world - but thanks to >>Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700 >>Series Scanner you'll get full speed at 300 dpi even with all image >>processing features enabled. http://p.sf.net/sfu/kodak-com >>_______________________________________________ >>Pyobjc-dev mailing list >>Pyo...@li... >>https://lists.sourceforge.net/lists/listinfo/pyobjc-dev >> >> > |
From: Mic P. <mic...@gm...> - 2009-05-10 16:06:06
|
Thankyou all so much. Between Bob and Ronald I now have this working. -Mic 2009/5/10 Ronald Oussoren <ron...@ma...>: > > On 8 May, 2009, at 13:44, Mic Pringle wrote: > >> Okay, fantastic ! >> >> Would it be possible for you to give me an example of your last point >> (re: manual annotations for some method you may use in a category) as >> this is the only part I don't have any experience with ? >> >> I am looking to add two methods to NSString, one which returns a >> string and another which returns an array. >> >> This would be greatly appreciated. > > Both strings and arrays are objects and hence no manual annotation is > needed, something like this should work: > > class MyStringCategory (objc.Category(NSString)): > def myStringValue(self): > return u"hello" > > def myArrayValue(self): > return [1,2] > > > You only need manual annotations when an argument or return value is a basic > C type (such as a C "int" or "NSPoint"). Adding annotations is described in > the pyobjc documentation and is definitely advanced behaviour because it > uses some very lowlevel machinery. > > > Ronald >> >> Thanks >> >> -Mic >> >> 2009/5/8 Ronald Oussoren <ron...@ma...>: >>> >>> On Friday, May 08, 2009, at 10:59AM, "Mic Pringle" <mic...@gm...> >>> wrote: >>>> >>>> Hi, >>>> >>>> Just a quick question regarding categories. >>>> >>>> I have a hybrid Obj-c/PyObj-c application and I'd like to know if I >>>> add a category in a PyObj-c module, will it be availble to use in the >>>> Obj-c side of the project ?? >>>> >>>> If so, does it just work or are there any special instructions I need >>>> to follow to get it working ? >>> >>> Methods you add using an Python category are available in ObjC as well >>> (the same is true for methods you add in a subclass, those can be called >>> from ObjC as well). >>> >>> Two possible sources for confusion/problems: >>> >>> * Unless the methods you add are already known to the compiler you'll >>> have to write a header file that the ObjC compiler >>> can use. You'll get compiler warnings otherwise. >>> >>> * Methods that you add in python by default have arguments and a return >>> value of type 'id'. This can be overridden by: >>> >>> - information extracted from the superclass (if you override a method >>> PyObjC knows the new method should have the >>> same signature as the one in a superclass). >>> - the method is defined in an informal_protocol that's known to PyObjC, >>> the method signature is then extracted from >>> that protocol >>> - manual annotations (objc.accessor, objc.selector, ....) >>> >>> Ronald >>>> >>>> Thanks >>>> >>>> -Mic >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your >>>> production scanning environment may not be a perfect world - but thanks >>>> to >>>> Kodak, there's a perfect scanner to get the job done! With the NEW KODAK >>>> i700 >>>> Series Scanner you'll get full speed at 300 dpi even with all image >>>> processing features enabled. http://p.sf.net/sfu/kodak-com >>>> _______________________________________________ >>>> Pyobjc-dev mailing list >>>> Pyo...@li... >>>> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev >>>> >>>> >>> > > |
From: Ronald O. <ron...@ma...> - 2009-05-10 08:18:03
|
On 8 May, 2009, at 13:44, Mic Pringle wrote: > Okay, fantastic ! > > Would it be possible for you to give me an example of your last point > (re: manual annotations for some method you may use in a category) as > this is the only part I don't have any experience with ? > > I am looking to add two methods to NSString, one which returns a > string and another which returns an array. > > This would be greatly appreciated. Both strings and arrays are objects and hence no manual annotation is needed, something like this should work: class MyStringCategory (objc.Category(NSString)): def myStringValue(self): return u"hello" def myArrayValue(self): return [1,2] You only need manual annotations when an argument or return value is a basic C type (such as a C "int" or "NSPoint"). Adding annotations is described in the pyobjc documentation and is definitely advanced behaviour because it uses some very lowlevel machinery. Ronald > > Thanks > > -Mic > > 2009/5/8 Ronald Oussoren <ron...@ma...>: >> >> On Friday, May 08, 2009, at 10:59AM, "Mic Pringle" <mic...@gm... >> > wrote: >>> Hi, >>> >>> Just a quick question regarding categories. >>> >>> I have a hybrid Obj-c/PyObj-c application and I'd like to know if I >>> add a category in a PyObj-c module, will it be availble to use in >>> the >>> Obj-c side of the project ?? >>> >>> If so, does it just work or are there any special instructions I >>> need >>> to follow to get it working ? >> >> Methods you add using an Python category are available in ObjC as >> well (the same is true for methods you add in a subclass, those can >> be called from ObjC as well). >> >> Two possible sources for confusion/problems: >> >> * Unless the methods you add are already known to the compiler >> you'll have to write a header file that the ObjC compiler >> can use. You'll get compiler warnings otherwise. >> >> * Methods that you add in python by default have arguments and a >> return value of type 'id'. This can be overridden by: >> >> - information extracted from the superclass (if you override a >> method PyObjC knows the new method should have the >> same signature as the one in a superclass). >> - the method is defined in an informal_protocol that's known to >> PyObjC, the method signature is then extracted from >> that protocol >> - manual annotations (objc.accessor, objc.selector, ....) >> >> Ronald >>> Thanks >>> >>> -Mic >>> >>> ------------------------------------------------------------------------------ >>> The NEW KODAK i700 Series Scanners deliver under ANY >>> circumstances! Your >>> production scanning environment may not be a perfect world - but >>> thanks to >>> Kodak, there's a perfect scanner to get the job done! With the NEW >>> KODAK i700 >>> Series Scanner you'll get full speed at 300 dpi even with all image >>> processing features enabled. http://p.sf.net/sfu/kodak-com >>> _______________________________________________ >>> Pyobjc-dev mailing list >>> Pyo...@li... >>> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev >>> >>> >> |
From: Greg E. <gre...@ca...> - 2009-05-10 01:14:40
|
Johan Rydberg wrote: > I suspect that this comes from the fact the the first class must > be the Objective-C class. > > With that constrain, a mixin class wouldn't be able to override > methods of the first class. Yes, I think that's the reason I did it the way I did. A better idea might be to search the base classes for one that derives from NSObject and use that as the "main" class, then merge from right to left. -- Greg |
From: Johan R. <joh...@gm...> - 2009-05-09 10:10:33
|
>> Note that this implementation results in methods in >> later base classes overriding those in earlier ones, >> which is more or less the opposite of what normally >> happens. If you use this technique, you might want >> to reverse the order of the merging. > > Wouldn't it be more useful to tweak NSMulticlass to do the updates of the > class dict in the right order? I suspect that this comes from the fact the the first class must be the Objective-C class. With that constrain, a mixin class wouldn't be able to override methods of the first class. |
From: Greg E. <gre...@ca...> - 2009-05-08 23:24:27
|
Ronald Oussoren wrote: > > On 8 May, 2009, at 1:46, Greg Ewing wrote: > >> If you use this technique, you might want >> to reverse the order of the merging. > > Wouldn't it be more useful to tweak NSMulticlass to do the updates of > the class dict in the right order? That's what I meant by "reverse the order of the merging". -- Greg |
From: Bob V. <pyo...@bo...> - 2009-05-08 18:49:41
|
I believe you must define stringFromTextile: as a class method in Python because that's how you're defining its interface in Objective-C. Don't know what the @objc.signature('#:#:) aims to accomplish, but I think this should work instead: @classmethod def stringFromTextile_(self, aString): Bob On May 8, 2009, at 10:35 AM, Mic Pringle wrote: > Hi Ronald, > > I'm still having issues with this. My category is defined in the file > NSStringTextile.py as follows ... > > from Foundation import * > import objc > import textile > > class NSString(objc.Category(NSString)): > > @objc.signature('#:#') > def stringFromTextile_(self, aString): > try: > data = textile.textile(aString) > except: > data = '' > return data > > And my header file, NSStringTextile.h, as follows ... > > #import <Cocoa/Cocoa.h> > > @interface NSString (Textile) > > + (NSString *)stringFromTextile:(NSString *)aString; > > @end > > However, when ever I try to use the category I get the following > message box popup ... > > [NSString stringFromTextile:]: unrecognized selector sent to class > 0xa0839f20 > > I have also added my python file to main.py > > Any ideas on where I'm going wrong ? > > Cheers > > -Mic > > 2009/5/8 Ronald Oussoren <ron...@ma...>: >> >> On Friday, May 08, 2009, at 10:59AM, "Mic Pringle" <mic...@gm... >> > wrote: >>> Hi, >>> >>> Just a quick question regarding categories. >>> >>> I have a hybrid Obj-c/PyObj-c application and I'd like to know if I >>> add a category in a PyObj-c module, will it be availble to use in >>> the >>> Obj-c side of the project ?? >>> >>> If so, does it just work or are there any special instructions I >>> need >>> to follow to get it working ? >> >> Methods you add using an Python category are available in ObjC as >> well (the same is true for methods you add in a subclass, those can >> be called from ObjC as well). >> >> Two possible sources for confusion/problems: >> >> * Unless the methods you add are already known to the compiler >> you'll have to write a header file that the ObjC compiler >> can use. You'll get compiler warnings otherwise. >> >> * Methods that you add in python by default have arguments and a >> return value of type 'id'. This can be overridden by: >> >> - information extracted from the superclass (if you override a >> method PyObjC knows the new method should have the >> same signature as the one in a superclass). >> - the method is defined in an informal_protocol that's known to >> PyObjC, the method signature is then extracted from >> that protocol >> - manual annotations (objc.accessor, objc.selector, ....) >> >> Ronald >>> Thanks >>> >>> -Mic >>> >>> ------------------------------------------------------------------------------ >>> The NEW KODAK i700 Series Scanners deliver under ANY >>> circumstances! Your >>> production scanning environment may not be a perfect world - but >>> thanks to >>> Kodak, there's a perfect scanner to get the job done! With the NEW >>> KODAK i700 >>> Series Scanner you'll get full speed at 300 dpi even with all image >>> processing features enabled. http://p.sf.net/sfu/kodak-com >>> _______________________________________________ >>> Pyobjc-dev mailing list >>> Pyo...@li... >>> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev >>> >>> >> > > ------------------------------------------------------------------------------ > The NEW KODAK i700 Series Scanners deliver under ANY circumstances! > Your > production scanning environment may not be a perfect world - but > thanks to > Kodak, there's a perfect scanner to get the job done! With the NEW > KODAK i700 > Series Scanner you'll get full speed at 300 dpi even with all image > processing features enabled. http://p.sf.net/sfu/kodak-com > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |
From: Mic P. <mic...@gm...> - 2009-05-08 17:35:24
|
Hi Ronald, I'm still having issues with this. My category is defined in the file NSStringTextile.py as follows ... from Foundation import * import objc import textile class NSString(objc.Category(NSString)): @objc.signature('#:#') def stringFromTextile_(self, aString): try: data = textile.textile(aString) except: data = '' return data And my header file, NSStringTextile.h, as follows ... #import <Cocoa/Cocoa.h> @interface NSString (Textile) + (NSString *)stringFromTextile:(NSString *)aString; @end However, when ever I try to use the category I get the following message box popup ... [NSString stringFromTextile:]: unrecognized selector sent to class 0xa0839f20 I have also added my python file to main.py Any ideas on where I'm going wrong ? Cheers -Mic 2009/5/8 Ronald Oussoren <ron...@ma...>: > > On Friday, May 08, 2009, at 10:59AM, "Mic Pringle" <mic...@gm...> wrote: >>Hi, >> >>Just a quick question regarding categories. >> >>I have a hybrid Obj-c/PyObj-c application and I'd like to know if I >>add a category in a PyObj-c module, will it be availble to use in the >>Obj-c side of the project ?? >> >>If so, does it just work or are there any special instructions I need >>to follow to get it working ? > > Methods you add using an Python category are available in ObjC as well (the same is true for methods you add in a subclass, those can be called from ObjC as well). > > Two possible sources for confusion/problems: > > * Unless the methods you add are already known to the compiler you'll have to write a header file that the ObjC compiler > can use. You'll get compiler warnings otherwise. > > * Methods that you add in python by default have arguments and a return value of type 'id'. This can be overridden by: > > - information extracted from the superclass (if you override a method PyObjC knows the new method should have the > same signature as the one in a superclass). > - the method is defined in an informal_protocol that's known to PyObjC, the method signature is then extracted from > that protocol > - manual annotations (objc.accessor, objc.selector, ....) > > Ronald >>Thanks >> >>-Mic >> >>------------------------------------------------------------------------------ >>The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your >>production scanning environment may not be a perfect world - but thanks to >>Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700 >>Series Scanner you'll get full speed at 300 dpi even with all image >>processing features enabled. http://p.sf.net/sfu/kodak-com >>_______________________________________________ >>Pyobjc-dev mailing list >>Pyo...@li... >>https://lists.sourceforge.net/lists/listinfo/pyobjc-dev >> >> > |
From: Mic P. <mic...@gm...> - 2009-05-08 11:44:35
|
Okay, fantastic ! Would it be possible for you to give me an example of your last point (re: manual annotations for some method you may use in a category) as this is the only part I don't have any experience with ? I am looking to add two methods to NSString, one which returns a string and another which returns an array. This would be greatly appreciated. Thanks -Mic 2009/5/8 Ronald Oussoren <ron...@ma...>: > > On Friday, May 08, 2009, at 10:59AM, "Mic Pringle" <mic...@gm...> wrote: >>Hi, >> >>Just a quick question regarding categories. >> >>I have a hybrid Obj-c/PyObj-c application and I'd like to know if I >>add a category in a PyObj-c module, will it be availble to use in the >>Obj-c side of the project ?? >> >>If so, does it just work or are there any special instructions I need >>to follow to get it working ? > > Methods you add using an Python category are available in ObjC as well (the same is true for methods you add in a subclass, those can be called from ObjC as well). > > Two possible sources for confusion/problems: > > * Unless the methods you add are already known to the compiler you'll have to write a header file that the ObjC compiler > can use. You'll get compiler warnings otherwise. > > * Methods that you add in python by default have arguments and a return value of type 'id'. This can be overridden by: > > - information extracted from the superclass (if you override a method PyObjC knows the new method should have the > same signature as the one in a superclass). > - the method is defined in an informal_protocol that's known to PyObjC, the method signature is then extracted from > that protocol > - manual annotations (objc.accessor, objc.selector, ....) > > Ronald >>Thanks >> >>-Mic >> >>------------------------------------------------------------------------------ >>The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your >>production scanning environment may not be a perfect world - but thanks to >>Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700 >>Series Scanner you'll get full speed at 300 dpi even with all image >>processing features enabled. http://p.sf.net/sfu/kodak-com >>_______________________________________________ >>Pyobjc-dev mailing list >>Pyo...@li... >>https://lists.sourceforge.net/lists/listinfo/pyobjc-dev >> >> > |
From: Ronald O. <ron...@ma...> - 2009-05-08 09:11:56
|
On Friday, May 08, 2009, at 10:59AM, "Mic Pringle" <mic...@gm...> wrote: >Hi, > >Just a quick question regarding categories. > >I have a hybrid Obj-c/PyObj-c application and I'd like to know if I >add a category in a PyObj-c module, will it be availble to use in the >Obj-c side of the project ?? > >If so, does it just work or are there any special instructions I need >to follow to get it working ? Methods you add using an Python category are available in ObjC as well (the same is true for methods you add in a subclass, those can be called from ObjC as well). Two possible sources for confusion/problems: * Unless the methods you add are already known to the compiler you'll have to write a header file that the ObjC compiler can use. You'll get compiler warnings otherwise. * Methods that you add in python by default have arguments and a return value of type 'id'. This can be overridden by: - information extracted from the superclass (if you override a method PyObjC knows the new method should have the same signature as the one in a superclass). - the method is defined in an informal_protocol that's known to PyObjC, the method signature is then extracted from that protocol - manual annotations (objc.accessor, objc.selector, ....) Ronald >Thanks > >-Mic > >------------------------------------------------------------------------------ >The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your >production scanning environment may not be a perfect world - but thanks to >Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700 >Series Scanner you'll get full speed at 300 dpi even with all image >processing features enabled. http://p.sf.net/sfu/kodak-com >_______________________________________________ >Pyobjc-dev mailing list >Pyo...@li... >https://lists.sourceforge.net/lists/listinfo/pyobjc-dev > > |
From: Mic P. <mic...@gm...> - 2009-05-08 08:59:10
|
Hi, Just a quick question regarding categories. I have a hybrid Obj-c/PyObj-c application and I'd like to know if I add a category in a PyObj-c module, will it be availble to use in the Obj-c side of the project ?? If so, does it just work or are there any special instructions I need to follow to get it working ? Thanks -Mic |
From: Ronald O. <ron...@ma...> - 2009-05-08 05:42:39
|
On 8 May, 2009, at 1:46, Greg Ewing wrote: > Ronald Oussoren wrote: > >> Mixins cannot be used to add new methods that the ObjC runtime >> will see. > > In PyGUI I'm using the following metaclass to get a > similar effect to multiple inheritance. It merges the > class dicts of all the base classes before creating > the class. > > Usage example: > > class PyGUI_NSWindow(NSWindow, PyGUI_NS_EventHandler): > __metaclass__ = NSMultiClass > ... > > The first base class should be an ObjC class; the > rest can be ordinary Python classes. > > Note that this implementation results in methods in > later base classes overriding those in earlier ones, > which is more or less the opposite of what normally > happens. If you use this technique, you might want > to reverse the order of the merging. Wouldn't it be more useful to tweak NSMulticlass to do the updates of the class dict in the right order? Ronald > > #-------------------------------------------------- > > from inspect import getmro > > def NSMultiClass(name, bases, dic): > # Workaround for PyObjC classes not supporting > # multiple inheritance properly. Note: MRO is > # right to left across the bases. > main = bases[0] > dic2 = {} That is: for mix in bases[::-1]: > for mix in bases[1:]: > for cls in getmro(mix)[::-1]: > dic2.update(cls.__dict__) # drop the next line: > dic2.update(dic) > cls = type(main)(name, (main,), dic2) > return cls > > #-------------------------------------------------- > > -- > Greg |
From: Greg E. <gre...@ca...> - 2009-05-07 23:45:13
|
Ronald Oussoren wrote: > Mixins cannot be used to add new > methods that the ObjC runtime will see. In PyGUI I'm using the following metaclass to get a similar effect to multiple inheritance. It merges the class dicts of all the base classes before creating the class. Usage example: class PyGUI_NSWindow(NSWindow, PyGUI_NS_EventHandler): __metaclass__ = NSMultiClass ... The first base class should be an ObjC class; the rest can be ordinary Python classes. Note that this implementation results in methods in later base classes overriding those in earlier ones, which is more or less the opposite of what normally happens. If you use this technique, you might want to reverse the order of the merging. #-------------------------------------------------- from inspect import getmro def NSMultiClass(name, bases, dic): # Workaround for PyObjC classes not supporting # multiple inheritance properly. Note: MRO is # right to left across the bases. main = bases[0] dic2 = {} for mix in bases[1:]: for cls in getmro(mix)[::-1]: dic2.update(cls.__dict__) dic2.update(dic) cls = type(main)(name, (main,), dic2) return cls #-------------------------------------------------- -- Greg |