Thread: Re: [Pyobjc-dev] Catergory Question ...
Brought to you by:
ronaldoussoren
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 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: 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: 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: Ronald O. <ron...@ma...> - 2009-05-10 08:18:03
Attachments:
smime.p7s
|
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: 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: 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: Ronald O. <ron...@ma...> - 2009-05-10 16:55:05
Attachments:
smime.p7s
|
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 17:15:27
Attachments:
smime.p7s
|
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 >>>>> >>>>> >>>> >> >> |