Thread: [Pyobjc-dev] shouldSelectRow not working as expected
Brought to you by:
ronaldoussoren
From: <bo...@pa...> - 2003-02-28 00:52:37
|
well, my tableview_shouldSelectRow is being called, but somehow the return value is getting ingored on the way back to the TableView. here's my delegate code, which hopes to make every other row selectable. it prints the results, but every row in the table is still selectable. changing it to return 0 doesnt help. def tableView_shouldSelectRow_(self, aTableView, rowIndex): print "shouldSelectRow %d is %d" % (rowIndex, rowIndex % 2) return rowIndex % 2 so, i made the same change to TableModel2, and that didn't produce the expected behavior, either. then, i took this sample objC NSTableView code http://www.macdevcenter.com/pub/a/mac/2002/08/27/cocoa.html wired up the controller as a delegate and added - (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(int)rowIndex { if (rowIndex % 2) { return YES; } else { return NO; } } and this of course works correctly. any ideas? --bob |
From: Chris R. <cp...@em...> - 2003-02-28 03:16:36
|
Bob-- Perhaps the BOOL return value is really what's needed, so you need to return YES or NO? On Thursday, February 27, 2003, at 07:52 PM, Bob Pasker wrote: > def tableView_shouldSelectRow_(self, aTableView, rowIndex): > print "shouldSelectRow %d is %d" % (rowIndex, rowIndex % 2) > return rowIndex % 2 Try return (rowIndex % 2) == 1 which should normalize to a true boolean value, or, perhaps more safely (is it necessary?), if (rowIndex % 2) == 1 return YES else return NO (or, if the latest conditional expression PEP gets approved ;-), return if (rowIndex % 2 == 1): YES else: NO Cheers! --Chris Ryland / Em Software, Inc. / www.emsoftware.com |
From: <bo...@pa...> - 2003-02-28 06:56:42
|
Hi Chris, good suggestion. i enabled column selection in IB, and this delegate method still runs and still permits column selecting. def tableView_shouldSelectTableColumn_(self, aTableView, aTableColumn): print "select table?" return 0==1 i think there's something wrong with the call linkages for boolean return types, but i can't figure out what it is. if anybody else can get this to actually work on TableModel2, i'd be interested to know how. --bob On Thursday, February 27, 2003, at 07:17 PM, Chris Ryland wrote: > Bob-- > > Perhaps the BOOL return value is really what's needed, so you need to > return YES or NO? > > On Thursday, February 27, 2003, at 07:52 PM, Bob Pasker wrote: >> def tableView_shouldSelectRow_(self, aTableView, rowIndex): >> print "shouldSelectRow %d is %d" % (rowIndex, rowIndex % 2) >> return rowIndex % 2 > > Try > > return (rowIndex % 2) == 1 > > which should normalize to a true boolean value, or, perhaps more > safely (is it necessary?), > > if (rowIndex % 2) == 1 > return YES > else > return NO > > (or, if the latest conditional expression PEP gets approved ;-), > > return if (rowIndex % 2 == 1): YES else: NO > > Cheers! > --Chris Ryland / Em Software, Inc. / www.emsoftware.com > |
From: Just v. R. <ju...@le...> - 2003-02-28 08:53:37
|
Bob Pasker wrote: > good suggestion. i enabled column selection in IB, and this delegate > method still > runs and still permits column selecting. > > def tableView_shouldSelectTableColumn_(self, aTableView, > aTableColumn): > print "select table?" > return 0==1 I've seen similar things: the only way I could force a false BOOL value was to return None. I think this is a bug. Just |
From: Ronald O. <ous...@ci...> - 2003-02-28 10:22:29
|
On Friday, Feb 28, 2003, at 09:52 Europe/Amsterdam, Just van Rossum wrote: > I think this is a bug. Right. Does the patch I just checked in solve the problem? Ronald |
From: Just v. R. <ju...@le...> - 2003-02-28 11:17:45
|
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. 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?). 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? 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). Just |
From: Just v. R. <ju...@le...> - 2003-02-28 11:51:44
|
Just van Rossum wrote: > 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). I just tried, and this indeed works for 2.3 (except I think the #ifdef PyObjC_HAVE_PYTHON_BOOL test should be removed, as it does the opposite of what I thought it would: PyObjC_HAVE_PYTHON_BOOL is defined when Python does _not_ have builtin bool support...). Thought about this a bit more: this is not going to work in a useful way in Python 2.2. Just |
From: Ronald O. <ous...@ci...> - 2003-02-28 12:45:49
|
On Friday, Feb 28, 2003, at 12:51 Europe/Amsterdam, Just van Rossum wrote: > Just van Rossum wrote: > >> 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). > > I just tried, and this indeed works for 2.3 (except I think the #ifdef > PyObjC_HAVE_PYTHON_BOOL test should be removed, as it does the opposite > of what I thought it would: PyObjC_HAVE_PYTHON_BOOL is defined when > Python does _not_ have builtin bool support...). Oops. I should have paid more attention... PyObjC_HAVE_PYTHON_BOOL should be defined only when python does have builtin bool support. Ronald |
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 |
From: <bb...@ma...> - 2003-02-28 15:21:33
|
On Friday, Feb 28, 2003, at 07:54 US/Eastern, Ronald Oussoren wrote: > 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. Yes. When defining such a thing, there is no need to wrap methods where all of the arguments are objects and the return value is an object. Correct? I'm adding NSOutlineViewDelegate now. b.bum |
From: <bo...@pa...> - 2003-02-28 15:51:37
|
its working as expected now. thanks, everyone. --bob |