Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
help about return type
-
@ryubai CGSize is not an object, it is a structure. You need to make your return type a CGSize Structure, not a c_void_p
-
I think there is a way to specify argtypes and restype when you create the class/method?
-
thank you all
when i overwrite a method requested a return type in a new class.
number and string can be returned directly.
cell object in tableview is returned in cell.ptr
but how to return a CGSize structure?
objc's CGSize does't work -
-
anyone can help? please
-
@ryubai, I tried a few things:
- confirming that defining another method of the same protocol that returns a float works fine
- looking a the definition of CGSize in objc_util
- fiddling with the retype of the function
- using CGSizeMake function, but could not get it defined
- checking if ctypes.Structure would have some additional capabilities
No help nowhere.
-
okay, the issue here is that ctypes does not allow complex return types, such as Unions or Structures for callbacks.
see
https://bugs.python.org/issue5710However, @dgelessus actually came up with a solution.
https://github.com/beeware/rubicon-objc/pull/85/filesyou need to download ctypes_patch.py and place in site-packages (or, you can use this executable link
Then, you just need to call
import ctypes_patch ... ctypes_patch.make_callback_returnable(CGSize) DataSource = create_objc_class('DataSource', methods=methods, protocols=['UICollectionViewDelegateFlowLayout', 'UICollectionViewDataSource', 'UICollectionViewDelegate'])
-
Sincerely, what could we do without @dgelessus and @JonB
Thanks to be here. -
i updated the exec link, to download and install the patch into site-packages. click the link, then click run.
-
-
run more than once will raise such errs,then how to solve?
ctypes_patch.make_callback_returnable(CGSize)
File "/private/var/mobile/Containers/Shared/AppGroup/02422888-CC52-45FC-BB53-72013D3F4AFA/Pythonista3/Documents/site-packages/ctypes_patch.py", line 128, in make_callback_returnable
raise ValueError("The ctype {} already has a getfunc")
ValueError: The ctype {} already has a getfunc -
Probably you can just use a try/except around that, or explicitly check for the existence of a getfunc.
-
Sorry for the late reply - I forgot to check the forum recently... The version of ctypes_patch that @JonB linked to is the original version from the pull request that added it. There have been some updates to it that fix a few problems, including the "The ctype {} already has a getfunc" error that @ryubai posted above. I would recommend using the current version of ctypes_patch from the repo and not the old one from the pull request.
-
This post is deleted! -
File "/private/var/mobile/Containers/Shared/AppGroup/02422888-CC52-45FC-BB53-72013D3F4AFA/Pythonista3/Documents/site-packages/ctypes_patch.py", line 128, in make_callback_returnable https://snaptube.cam/ https://wordtopdf.ltd/ https://vidmate.bid/