I also tried programs like:
class WebView(ui.View):
def __init__(self):
self.create_webview()
@objc_util.on_main_thread
def create_webview(self):
self.webview = objc_util.ObjCClass("WKWebView").alloc().initWithFrame_(...)
self.objc_instance.addSubview_(self.webview)
class View(ui.View):
def __init__(self):
self.webview = WebView()
self.add_subview(self.webview)
observer_cls = objc_util.create_objc_class("observer_cls", methods=[self.observeValueForKeyPath_ofObject_change_context_])
observer = objc_util.ObjCClass("observer_cls").alloc()
self.webview.webview.addObserver_forKeyPath_options_context_(observer, "canGoBack", 0, None)
self.webview.webview.addObserver_forKeyPath_options_context_(observer, "canGoForward", 0, None)
...
def observeValueForKeyPath_ofObject_change_context_(_self, _cmd, _path, _obj, _change, _context):
...
observer
is used as an instance of observer_cls
.
But in this case an error occurs. _objc_exception.py looks like this:
Exception ignored on calling ctypes callback function: <bound method View.observeValueForKeyPath_ofObject_change_context_ of <__main__.View object at 0x116bbc180>>
TypeError: View.observeValueForKeyPath_ofObject_change_context_() takes 6 positional arguments but 7 were given