Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run_on_ui_thread crash #1908

Closed
FranciscoCarbonell opened this issue Jul 4, 2019 · 9 comments
Closed

run_on_ui_thread crash #1908

FranciscoCarbonell opened this issue Jul 4, 2019 · 9 comments

Comments

@FranciscoCarbonell
Copy link

error output:

AttributeError : 'Wv' object has no attribute 'f2'

runable.py

def run_on_ui_thread(f):
    '''Decorator to create automatically a :class:`Runnable` object with the
    function. The function will be delayed and call into the Activity thread.
    '''
    def f2(*args, **kwargs):
        Runnable(f)(*args, **kwargs)
    return f2

python : 3.7.1
cyrhon: 0.28.6
Kivy: 1.10

@ocobacho
Copy link

ocobacho commented Jul 10, 2019

Having the same problem. Solved by not using the decorator and just using a function.

def run_ui_thread(f, *args, **kwargs):
    # args/kwargs to runnable was a bug, fixed in master
    Runnable(f)(args, kwargs)

@inclement
Copy link
Member

Closing as insufficiently reported. Please post a full runnable example if you're still having this issue.

@shashi278
Copy link
Contributor

@ocobacho
Get that create_webview out of the class instead of changing the decorator implementation and it'll work fine. Since you're using the decorator on a class method, it's searching for f2 within the class itself.

@lucasargento
Copy link

@ocobacho
Could you please explain further?
having the same issue and i didnt get your solution.
im importing the ScreenWebView class from my main.py
thanks!

@lucasargento
Copy link

Having the same problem. Solved by not using the decorator and just using a function.

def run_ui_thread(f, *args, **kwargs):
    # args/kwargs to runnable was a bug, fixed in master
    Runnable(f)(args, kwargs)

i know this issue is closed and its been a while, but could you please post your whole code on the solution? been tryng to implement it without success. thanks!

@onodnawij
Copy link

onodnawij commented May 10, 2020

Having the same problem. Solved by not using the decorator and just using a function.

def run_ui_thread(f, *args, **kwargs):
    # args/kwargs to runnable was a bug, fixed in master
    Runnable(f)(args, kwargs)

i know this issue is closed and its been a while, but could you please post your whole code on the solution? been tryng to implement it without success. thanks!

Another solution is putting create_webview function outside the class. Because it likely trying to find the 'f2' inside Wv class.

from kivy.app import App
from jnius import autoclass
from kivy.clock import Clock
from android.runnable import run_on_ui_thread
from kivy.uix.widget import Widget

WebView = autoclass('android.webkit.WebView')
WebViewClient = autoclass('android.webkit.WebViewClient')
activity = autoclass('org.kivy.android.PythonActivity').mActivity

@run_on_ui_thread
def create_webview(*args):
	webview = WebView(activity)
	webview.getSettings().setJavaScriptEnabled(True)
	wvc = WebViewClient();
	webview.setWebViewClient(wvc);
	activity.setContentView(webview)
	webview.loadUrl('https://google.com')


class Wv(Widget):
	def __init__(self, **kwargs):
		super().__init__(**kwargs)
		self.__functionstable__ = {}
		Clock.schedule_once(create_webview, 0)
	

class ServiceApp(App):
	def build(self):
		return Wv()

@JuditNugroho
Copy link

JuditNugroho commented May 19, 2020

Having the same problem. Solved by not using the decorator and just using a function.

def run_ui_thread(f, *args, **kwargs):
    # args/kwargs to runnable was a bug, fixed in master
    Runnable(f)(args, kwargs)

i know this issue is closed and its been a while, but could you please post your whole code on the solution? been tryng to implement it without success. thanks!

Another solution is putting create_webview function outside the class. Because it likely trying to find the 'f2' inside Wv class.

from kivy.app import App
from jnius import autoclass
from kivy.clock import Clock
from android.runnable import run_on_ui_thread
from kivy.uix.widget import Widget

WebView = autoclass('android.webkit.WebView')
WebViewClient = autoclass('android.webkit.WebViewClient')
activity = autoclass('org.kivy.android.PythonActivity').mActivity

@run_on_ui_thread
def create_webview(*args):
	webview = WebView(activity)
	webview.getSettings().setJavaScriptEnabled(True)
	wvc = WebViewClient();
	webview.setWebViewClient(wvc);
	activity.setContentView(webview)
	webview.loadUrl('https://google.com')


class Wv(Widget):
	def __init__(self, **kwargs):
		super().__init__(**kwargs)
		self.__functionstable__ = {}
		Clock.schedule_once(create_webview, 0)
	

class ServiceApp(App):
	def build(self):
		return Wv()

hi i can run this but i cant click back button in android. How can i detach this webview with this solution?. Thanks

@5developer
Copy link

5developer commented Oct 16, 2020

Runnable(f)(args, kwargs)

May I see your code?

@5developer
Copy link

whithout using decorator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants