Re: [Pyobjc-dev] shouldSelectRow not working as expected
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-02-28 12:55:46
|
On Friday, Feb 28, 2003, at 12:17 Europe/Amsterdam, Just van Rossum wrote: > Ronald Oussoren wrote: > >> Right. Does the patch I just checked in solve the problem? > > Partly, it seems. However, you _must_ return an int/bool for methods > that are declared to return a BOOL; when I return None instead I get an > exception. I assume that's because ObjC can't see the difference > between > a BOOL and a char at the time the conversion happens. Right. As far as the runtime, and therefore the bridge, is concerned BOOL is an alias for 'unsigned char'. > > In my PythonBrowser playground I have an inconsitency, though. Two > methods are supposed to return BOOLs, yet one is part of the > NSOutlineViewDataSource protocol, the other is an NSOutlineView > delegate > method (is there even a NSOutlineViewDelegate protocol?). Not yet :-) > > class PythonBrowserModel(AutoBaseClass, NSOutlineViewDataSource): > > [..snippo..] > > def outlineView_isItemExpandable_(self, view, item): > # part of the NSOutlineViewDataSource protocol, > # must return int/bool > if item is None: > item = self.root > return item.isExpandable() > > def outlineView_shouldEditTableColumn_item_(self, view, col, item): > # this is a delegate method of NSOutlineView, I _must_ return > # None as "NO", any other object as "YES", hence the "or None" > # hack. > return item.isEditable() or None > > I suppose this is not solvable without adding an NSOutlineViewDelegate > informal protocol? Yup. Feel free to add this to Lib/AppKit/__init__.py ;-). It should contain all the methods a NSOutlineView delegate can implement. We should probably add informal_protocol definitions for all delegates in Cocoa. > > Here's a thought: what if the bridge would convert the False bool > instance to nil? Hm, this would only work with Python 2.3 unless we add > proper bool support to 2.2 ourselves (btw. plistlib.py contains code > that does just that, but only for that module). That would work only by accident. If the bit-pattern of the pointer to the (proxy-)object for a true value happened to contain 8 0-bits at the right location it would also be interpreted as NO by the objective-C side of thinks. Not that adding a private bool type on Python 2.2 would be bad, it would allow for the creation of the right kind of NSNumber for boolean values, NSNumbers created using numberWithBool: have a different kind of representation in plist files. BTW. Later 2.2 versions introduce builtins for True and False, does that also introduce a bool type or are these just names for 1 and 0? Ronald |