I want to access my images/photo gallery on an iOS device from a kivy application. Kivy has no native way implemented to do this, so I'm trying to solve it with kivy/pyobjus where I can use the UIImagePickerController (from Apples UIKit).
from kivy.app import App
from kivy.lang import Builder
from pyobjus import autoclass, protocol
class TestApp(App):
ui = Builder.load_file("main.kv")
def build(self):
return self.ui
def imagePicker(self):
UIImagePickerController = autoclass('UIImagePickerController')
self.picker = UIImagePickerController.alloc().init()
self.picker.delegate = self
self.picker.sourceType = 0
@protocol('UIImagePickerControllerDelegate')
def imagePickerControllerDidFinish(self, image):
print("ABC")
The ui is just a button, which calls the imagePicker function. I have three questions on this code:
- How can I display the imagePicker?
When I'm using imagePicker.delegate = self, the App crashes because
[...] delegate, but there is no @protocol methods declared.
But I declared a protocol with "@protocol('UIImagePickerControllerDelegate')" So why it won't use my declared protocol? (I tried also to add the "UIImagePickerControllerDelegate" in the protocols.py from pyobjus. This didn't solved the problem)
- If the protocol will work, it is the correct way to use the "imagePickerControllerDidFinish(self, image)" method to access the image?