[Pyobjc-dev] Still struggling with NSOutlineView
Brought to you by:
ronaldoussoren
From: Just v. R. <ju...@le...> - 2003-01-15 22:13:17
|
I just noticed that my PythonBrowser application doesn't work correctly after all if I don't subclass PythonItem from NSObject. I was getting strange messages in the log if I tried to unpack certain items: 2003-01-15 21:48:37.838 python[13055] PythonItem instance has no attribute '__getitem__' but I was sure *I* didn't do any subscripting on PythonItem instances. It appears Cocoa is calling it (*), through PyObjC, and while trying to find what's wrong I came across this snippet in Modules/objc/objc_support.m: else if (PySequence_Check(argument)) *(id *) datum = [OC_PythonArray newWithPythonObject:argument]; PySequence_Check() is a lame check, it always returns true for simple instances. But since there's a PyDict_Check() below (which really checks isinstance(x, dict)), I think the following would be better/safer: else if (PyList_Check(argument) || PyTuple_Check(argument)) *(id *) datum = [OC_PythonArray newWithPythonObject:argument]; However, if I make that change, PythonBrowser doesn't run at all anymore: it crashes before any window is shown. So I'm pretty sure my Python objects are (wrongly) wrapped in an OC_PythonArray object, yet when they are wrapped in a OC_PythonObject (which would happen after my change) it stops working completely. *) I have no clue why NSOutlineView would do that: perhaps it tries to get at children by itself if the object is array-like, instead of going through outlineView:child:ofItem: ? The NSOutlineView and NSOutlineViewDataSource documentation don't seem to mention such magic. Just |