Last active
October 10, 2020 05:59
-
-
Save tito/6118172 to your computer and use it in GitHub Desktop.
Python-for-android / Pyjnius - test live-creation of native android widget.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Use with Kivy Remote Shell: | |
cat test.py | ssh -p8000 -t -t admin@192.168.x.x | |
''' | |
from jnius import autoclass, cast | |
from android.runnable import Runnable | |
activity = autoclass('org.renpy.android.PythonActivity').mActivity | |
AnalogClock = autoclass('android.widget.AnalogClock') | |
WebView = autoclass('android.webkit.WebView') | |
LinearLayout = autoclass('android.widget.LinearLayout') | |
LayoutParams = autoclass('android.view.ViewGroup$LayoutParams') | |
global clock | |
def create_clock(): | |
# works | |
global clock | |
clock = AnalogClock(activity) | |
activity.addContentView(clock, LayoutParams(-1, -1)) | |
def remove_clock(): | |
global clock | |
cast(LinearLayout, clock.getParent()).removeView(clock) | |
def create_webview(): | |
# works | |
webview = WebView(activity) | |
activity.setContentView(webview) | |
webview.loadData('<html><body>Hello<b>World</b></body></html>', 'text/html', | |
None) | |
def create_clock2(): | |
# failed, sdlview? | |
layout = LinearLayout(activity) | |
layout.addView(activity.mView) | |
clock = AnalogClock(activity) | |
layout.addView(clock) | |
activity.setContentView(layout) | |
def sdl_view(): | |
# failed, "Invalid indirect reference..." | |
activity.setContentView(activity.mView) | |
def run(f, *args, **kwargs): | |
# args/kwargs to runnable was a bug, fixed in master | |
Runnable(f)(args, kwargs) | |
run(create_clock) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello, first sorry for my bad english.
I need help, when I run cat test.py | ssh -p8000 -t -t admin@192.168.50.x, python say :
" Traceback (most recent call last):
File "", line 1, in
File "", line 3, in run
File "/home/....../Android/kivy/kivy-remote-shell-master/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/android/runnable.py", line 29, in call
AttributeError: 'NoneType' object has no attribute 'runOnUiThread' "
can you help me please??
Thanks