Re: [Pyobjc-dev] Structs, tuples and instances
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-10-31 12:43:25
|
On 31 okt 2003, at 11:54, Jack Jansen wrote: > > On 30 Oct 2003, at 10:36, Dinu Gherman wrote: > >> Hi, >> >> I'm trying to fake some kind of a solution which is more struct-like >> than plain Python tuples for things like NSPoint, NSSize, etc. Here's >> a simple one: >> >> class NSPoint: > > I don't have a real reason for it, but my gut feeling is that the > Pythonic way to do this is the other way around: use a list as the > baseclass, and subclass that. Actually, what you really want (I think) > is something based on structmember, but I don't know whether that > allows read/write access, and whether it's available from Python code. > > Hmm, even if it isn't available from Python the objc core could make > it available. Using structmember for the various toolbox structures is > something that's also on my to-do list, but I haven't done anything > about it yet so I don't know how feasible this approach is. Do you mean the new PyStructSequence_Type as used by os.stat and time.localtime? Those "structures" are (sadly) read-only. I'm thinking of adding a generic method for creating struct-like types, which could then be used to define NSPoint, NSRect, ... as a type. Something like this: def struct_type(name, signature, *fieldnames): """ implemented in C, return a new type the signature is used to type-check assignments, could be left out. """ pass NSPoint = objc.struct_type("NSPoint", "{_NSPoint=ff}", "x", "y") val = NSPoint(1.0, 2.0) x = val.x x = val[0] y = val.y y = val[1] val.x = 2.0 val[1] = 3 There would also be a C-level API for creating types and instances of it, this would be used to make sure that ObjC API's returning an NSPoint would actually create an instance of the NSPoint type defined earlier, instead of a tuple. Ronald > -- > Jack Jansen <Jac...@cw...> http://www.cwi.nl/~jack > If I can't dance I don't want to be part of your revolution -- Emma > Goldman > > > > ------------------------------------------------------- > This SF.net email is sponsored by: SF.net Giveback Program. > Does SourceForge.net help you be more productive? Does it > help you create better code? SHARE THE LOVE, and help us help > YOU! Click Here: http://sourceforge.net/donate/ > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev > |