Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/source/core_tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,22 @@ Here, we specify that our object method `connection_didFailWithError_` handles
the `connection:didFailWithError:` delegation of the `NSURLConnectionDelegate`
protocol. Pyobjus then redirects this Objective-C message to our method.

If the protocol method has a non-void return type, the value returned from
Python is written back onto the ``NSInvocation`` so Objective-C callers receive
it (for example an ``NSString *``, ``BOOL``, integer, ``char`` /
``unsigned char``, or ``float`` / ``double``). Supported return kinds today
are objects (``@``), common integer widths, ``BOOL``, ``char`` /
``unsigned char``, and ``f`` / ``d``; other encodings (structs, …) are not
forwarded yet.

Struct, union, and array arguments are not decoded yet either: those
parameters are passed to the Python method as ``None``.

On 64-bit platforms ``CGFloat`` is ``double``. Load the framework that
declares a protocol (AppKit, UIKit, …) before creating the delegate so
pyobjus can use the runtime type encodings; the static
``pyobjus/protocols.py`` table is only a fallback.

For a complete example, please see the `examples/delegate.py` file.

Using enum types
Expand Down
2 changes: 2 additions & 0 deletions pyobjus/common.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ cdef extern from "string.h":
cdef extern from "CoreFoundation/CoreFoundation.h":
ctypedef struct CFRange:
pass
void *CFRetain(void *cf)
void *CFAutorelease(void *cf)


cdef extern from "CoreGraphics/CoreGraphics.h":
Expand Down
42 changes: 21 additions & 21 deletions pyobjus/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,8 @@
"webView:dragSourceActionMaskForPoint:": ("I16@0:4@8@12", "I32@0:8@16@24"),
"webView:willPerformDragSourceAction:fromPoint:withPasteboard:": ("v24@0:4@8@12@16@20", "v48@0:8@16@24@32@40"),
"webView:printFrameView:": ("v16@0:4@8@12", "v32@0:8@16@24"),
"webViewHeaderHeight:": ("f12@0:4@8", "f24@0:8@16"),
"webViewFooterHeight:": ("f12@0:4@8", "f24@0:8@16"),
"webViewHeaderHeight:": ("f12@0:4@8", "d24@0:8@16"),
"webViewFooterHeight:": ("f12@0:4@8", "d24@0:8@16"),
"webView:drawHeaderInRect:": ("v16@0:4@8@12", "v32@0:8@16@24"),
"webView:drawFooterInRect:": ("v16@0:4@8@12", "v32@0:8@16@24"),
"webView:runJavaScriptAlertPanelWithMessage:": ("v16@0:4@8@12", "v32@0:8@16@24"),
Expand Down Expand Up @@ -1294,12 +1294,12 @@
"tableView:mouseDownInHeaderOfTableColumn:": ("v16@0:4@8@12", "v32@0:8@16@24"),
"tableView:didClickTableColumn:": ("v16@0:4@8@12", "v32@0:8@16@24"),
"tableView:didDragTableColumn:": ("v16@0:4@8@12", "v32@0:8@16@24"),
"tableView:heightOfRow:": ("f16@0:4@8i12", "f32@0:8@16i24"),
"tableView:heightOfRow:": ("f16@0:4@8i12", "d32@0:8@16q24"),
"tableView:typeSelectStringForTableColumn:row:": ("@20@0:4@8@12i16", "@40@0:8@16@24i32"),
"tableView:nextTypeSelectMatchFromRow:toRow:forString:": ("i24@0:4@8i12i16@20", "i48@0:8@16i24i32@40"),
"tableView:shouldTypeSelectForEvent:withCurrentSearchString:": ("B20@0:4@8@12@16", "B40@0:8@16@24@32"),
"tableView:isGroupRow:": ("B16@0:4@8i12", "B32@0:8@16i24"),
"tableView:sizeToFitWidthOfColumn:": ("f16@0:4@8i12", "f32@0:8@16i24"),
"tableView:sizeToFitWidthOfColumn:": ("f16@0:4@8i12", "d32@0:8@16q24"),
"tableView:shouldReorderColumn:toColumn:": ("B20@0:4@8i12i16", "B40@0:8@16i24i32"),
"tableView:rowActionsForRow:edge:": ("@20@0:4@8i12@16", "@40@0:8@16i24@32"),
"tableViewSelectionDidChange:": ("v12@0:4@8", "v24@0:8@16"),
Expand Down Expand Up @@ -1397,7 +1397,7 @@
"animationShouldStart:": ("B12@0:4@8", "B24@0:8@16"),
"animationDidStop:": ("v12@0:4@8", "v24@0:8@16"),
"animationDidEnd:": ("v12@0:4@8", "v24@0:8@16"),
"animation:valueForProgress:": ("f16@0:4@8@12", "f32@0:8@16@24"),
"animation:valueForProgress:": ("f16@0:4@8f12", "f28@0:8@16f24"),
"animation:didReachProgressMark:": ("v16@0:4@8@12", "v32@0:8@16@24"),
},
"NSAccessibilityRow": {
Expand All @@ -1417,7 +1417,7 @@
"outlineView:didClickTableColumn:": ("v16@0:4@8@12", "v32@0:8@16@24"),
"outlineView:didDragTableColumn:": ("v16@0:4@8@12", "v32@0:8@16@24"),
"outlineView:toolTipForCell:rect:tableColumn:item:mouseLocation:": ("@32@0:4@8@12@16@20@24@28", "@64@0:8@16@24@32@40@48@56"),
"outlineView:heightOfRowByItem:": ("f16@0:4@8@12", "f32@0:8@16@24"),
"outlineView:heightOfRowByItem:": ("f16@0:4@8@12", "d32@0:8@16@24"),
"outlineView:typeSelectStringForTableColumn:item:": ("@20@0:4@8@12@16", "@40@0:8@16@24@32"),
"outlineView:nextTypeSelectMatchFromItem:toItem:forString:": ("@24@0:4@8@12@16@20", "@48@0:8@16@24@32@40"),
"outlineView:shouldTypeSelectForEvent:withCurrentSearchString:": ("B20@0:4@8@12@16", "B40@0:8@16@24@32"),
Expand All @@ -1428,7 +1428,7 @@
"outlineView:shouldExpandItem:": ("B16@0:4@8@12", "B32@0:8@16@24"),
"outlineView:shouldCollapseItem:": ("B16@0:4@8@12", "B32@0:8@16@24"),
"outlineView:willDisplayOutlineCell:forTableColumn:item:": ("v24@0:4@8@12@16@20", "v48@0:8@16@24@32@40"),
"outlineView:sizeToFitWidthOfColumn:": ("f16@0:4@8i12", "f32@0:8@16i24"),
"outlineView:sizeToFitWidthOfColumn:": ("f16@0:4@8i12", "d32@0:8@16q24"),
"outlineView:shouldReorderColumn:toColumn:": ("B20@0:4@8i12i16", "B40@0:8@16i24i32"),
"outlineView:shouldShowOutlineCellForItem:": ("B16@0:4@8@12", "B32@0:8@16@24"),
"outlineViewSelectionDidChange:": ("v12@0:4@8", "v24@0:8@16"),
Expand Down Expand Up @@ -1538,7 +1538,7 @@
"NSAccessibilityGroup": {
},
"NSDraggingSource": {
"draggingSession:sourceOperationMaskForDraggingContext:": ("@16@0:4@8@12", "@32@0:8@16@24"),
"draggingSession:sourceOperationMaskForDraggingContext:": ("I16@0:4@8i12", "Q32@0:8@16q24"),
"draggingSession:willBeginAtPoint:": ("v16@0:4@8@12", "v32@0:8@16@24"),
"draggingSession:movedToPoint:": ("v16@0:4@8@12", "v32@0:8@16@24"),
"draggingSession:endedAtPoint:operation:": ("v20@0:4@8@12@16", "v40@0:8@16@24@32"),
Expand Down Expand Up @@ -1574,7 +1574,7 @@
"browser:child:ofItem:": ("@20@0:4@8i12@16", "@40@0:8@16i24@32"),
"browser:isLeafItem:": ("B16@0:4@8@12", "B32@0:8@16@24"),
"browser:objectValueForItem:": ("@16@0:4@8@12", "@32@0:8@16@24"),
"browser:heightOfRow:inColumn:": ("f20@0:4@8i12i16", "f40@0:8@16i24i32"),
"browser:heightOfRow:inColumn:": ("f20@0:4@8i12i16", "d40@0:8@16q24q32"),
"rootItemForBrowser:": ("@12@0:4@8", "@24@0:8@16"),
"browser:setObjectValue:forItem:": ("v20@0:4@8@12@16", "v40@0:8@16@24@32"),
"browser:shouldEditItem:": ("B16@0:4@8@12", "B32@0:8@16@24"),
Expand All @@ -1585,8 +1585,8 @@
"browser:isColumnValid:": ("B16@0:4@8i12", "B32@0:8@16i24"),
"browserWillScroll:": ("v12@0:4@8", "v24@0:8@16"),
"browserDidScroll:": ("v12@0:4@8", "v24@0:8@16"),
"browser:shouldSizeColumn:forUserResize:toWidth:": ("f24@0:4@8i12B16f20", "f48@0:8@16i24B32f40"),
"browser:sizeToFitWidthOfColumn:": ("f16@0:4@8i12", "f32@0:8@16i24"),
"browser:shouldSizeColumn:forUserResize:toWidth:": ("f24@0:4@8i12B16f20", "d48@0:8@16q24B32d40"),
"browser:sizeToFitWidthOfColumn:": ("f16@0:4@8i12", "d32@0:8@16q24"),
"browserColumnConfigurationDidChange:": ("v12@0:4@8", "v24@0:8@16"),
"browser:shouldShowCellExpansionForRow:column:": ("B20@0:4@8i12i16", "B40@0:8@16i24i32"),
"browser:writeRowsWithIndexes:inColumn:toPasteboard:": ("B24@0:4@8@12i16@20", "B48@0:8@16@24i32@40"),
Expand Down Expand Up @@ -1638,9 +1638,9 @@
},
"NSLayoutManagerDelegate": {
"layoutManager:shouldGenerateGlyphs:properties:characterIndexes:font:forGlyphRange:": ("I32@0:4@8r@12r@16r@20@24@28", "I64@0:8@16r@24r@32r@40@48@56"),
"layoutManager:lineSpacingAfterGlyphAtIndex:withProposedLineFragmentRect:": ("f20@0:4@8I12@16", "f40@0:8@16I24@32"),
"layoutManager:paragraphSpacingBeforeGlyphAtIndex:withProposedLineFragmentRect:": ("f20@0:4@8I12@16", "f40@0:8@16I24@32"),
"layoutManager:paragraphSpacingAfterGlyphAtIndex:withProposedLineFragmentRect:": ("f20@0:4@8I12@16", "f40@0:8@16I24@32"),
"layoutManager:lineSpacingAfterGlyphAtIndex:withProposedLineFragmentRect:": ("f20@0:4@8I12@16", "d64@0:8@16Q24{CGRect={CGPoint=dd}{CGSize=dd}}32"),
"layoutManager:paragraphSpacingBeforeGlyphAtIndex:withProposedLineFragmentRect:": ("f20@0:4@8I12@16", "d64@0:8@16Q24{CGRect={CGPoint=dd}{CGSize=dd}}32"),
"layoutManager:paragraphSpacingAfterGlyphAtIndex:withProposedLineFragmentRect:": ("f20@0:4@8I12@16", "d64@0:8@16Q24{CGRect={CGPoint=dd}{CGSize=dd}}32"),
"layoutManager:shouldUseAction:forControlCharacterAtIndex:": ("@20@0:4@8@12I16", "@40@0:8@16@24I32"),
"layoutManager:shouldBreakLineByWordBeforeCharacterAtIndex:": ("B16@0:4@8I12", "B32@0:8@16I24"),
"layoutManager:shouldBreakLineByHyphenatingBeforeCharacterAtIndex:": ("B16@0:4@8I12", "B32@0:8@16I24"),
Expand Down Expand Up @@ -1722,9 +1722,9 @@
"NSSplitViewDelegate": {
"splitView:canCollapseSubview:": ("B16@0:4@8@12", "B32@0:8@16@24"),
"splitView:shouldCollapseSubview:forDoubleClickOnDividerAtIndex:": ("B20@0:4@8@12i16", "B40@0:8@16@24i32"),
"splitView:constrainMinCoordinate:ofSubviewAt:": ("f20@0:4@8f12i16", "f40@0:8@16f24i32"),
"splitView:constrainMaxCoordinate:ofSubviewAt:": ("f20@0:4@8f12i16", "f40@0:8@16f24i32"),
"splitView:constrainSplitPosition:ofSubviewAt:": ("f20@0:4@8f12i16", "f40@0:8@16f24i32"),
"splitView:constrainMinCoordinate:ofSubviewAt:": ("f20@0:4@8f12i16", "d40@0:8@16d24q32"),
"splitView:constrainMaxCoordinate:ofSubviewAt:": ("f20@0:4@8f12i16", "d40@0:8@16d24q32"),
"splitView:constrainSplitPosition:ofSubviewAt:": ("f20@0:4@8f12i16", "d40@0:8@16d24q32"),
"splitView:resizeSubviewsWithOldSize:": ("v16@0:4@8@12", "v32@0:8@16@24"),
"splitView:shouldAdjustSizeOfSubview:": ("B16@0:4@8@12", "B32@0:8@16@24"),
"splitView:shouldHideDividerAtIndex:": ("B16@0:4@8i12", "B32@0:8@16i24"),
Expand Down Expand Up @@ -1781,8 +1781,8 @@
"attributedSubstringForProposedRange:actualRange:": ("@16@0:4@8@12", "@32@0:8@16@24"),
"firstRectForCharacterRange:actualRange:": ("@16@0:4@8@12", "@32@0:8@16@24"),
"characterIndexForPoint:": ("I12@0:4@8", "I24@0:8@16"),
"fractionOfDistanceThroughGlyphForPoint:": ("f12@0:4@8", "f24@0:8@16"),
"baselineDeltaForCharacterAtIndex:": ("f12@0:4I8", "f24@0:8I16"),
"fractionOfDistanceThroughGlyphForPoint:": ("f12@0:4@8", "d32@0:8{CGPoint=dd}16"),
"baselineDeltaForCharacterAtIndex:": ("f12@0:4I8", "d24@0:8Q16"),
"drawsVerticallyForCharacterAtIndex:": ("B12@0:4I8", "B24@0:8I16"),
},
"NSMenuDelegate": {
Expand Down Expand Up @@ -1855,8 +1855,8 @@
"NSCollectionViewDelegateFlowLayout": {
"collectionView:layout:sizeForItemAtIndexPath:": ("@20@0:4@8@12@16", "@40@0:8@16@24@32"),
"collectionView:layout:insetForSectionAtIndex:": ("@20@0:4@8@12i16", "@40@0:8@16@24i32"),
"collectionView:layout:minimumLineSpacingForSectionAtIndex:": ("f20@0:4@8@12i16", "f40@0:8@16@24i32"),
"collectionView:layout:minimumInteritemSpacingForSectionAtIndex:": ("f20@0:4@8@12i16", "f40@0:8@16@24i32"),
"collectionView:layout:minimumLineSpacingForSectionAtIndex:": ("f20@0:4@8@12i16", "d40@0:8@16@24q32"),
"collectionView:layout:minimumInteritemSpacingForSectionAtIndex:": ("f20@0:4@8@12i16", "d40@0:8@16@24q32"),
"collectionView:layout:referenceSizeForHeaderInSection:": ("@20@0:4@8@12i16", "@40@0:8@16@24i32"),
"collectionView:layout:referenceSizeForFooterInSection:": ("@20@0:4@8@12i16", "@40@0:8@16@24i32"),
},
Expand Down
Loading
Loading