F.A.O. Paddy?: pi3d android kivy dialogs: request for hints on kivy py4a event handling

65 views
Skip to first unread message

mung kie

unread,
Aug 23, 2016, 5:18:49 PM8/23/16
to pi3d
I have got back to looking at my pi3d android app and now have problems with filechooser and other kivy widgets.

Basically seems as if kivy goes crazy and does not map widgets to screen if trying to 'Popup' a kivy window from within the pi3dloop.

I can just get
        self._popup = Popup(title="Enter text here",
               content
=TextInput(focus=True),
               size_hint
=(0.6, 0.6),
               on_dismiss
=self.text_popup).open()
to show up onscreen but without some other widgets to pop down when complete I am lost.

I tried putting some locks in

 
def pi3dloop(self, dt):
   
self.DISPLAY.loop_running()

i.e. stopping redraws, but that did not help, I assume kivy is setup to not draw its graphics surfaces?

Would it be possible to let kivy have its own gles context on a higher layer with a transparent background so pi3d could be seen where widgets were not mapped?

Unfortunately I never looked at how you handled the event handlers and kivy drawing loops, so am hoping you could give me some hints before I start diving into the code.

I am as always lazy and busy so this is not the best description or even an effort at rubber ducking, but its always most efficient to get someone else to do the work for me (lol :D )

Anyways if you have hints that my help speed up understanding it will maybe encourage me to put some more effort in.

As always thanks for your excellent (past) help.

I will add more detail and maybe some example code as necessary as I get time.

Paddy

unread,
Aug 23, 2016, 6:18:21 PM8/23/16
to pi3d
I really need to get py4a sorted (in its later incarnation) I started to do things ages ago and got diverted. I imagine the issue is something to do with the kivy loop and pi3d having to coexist.. It's a while since I looked at it but I seem to remember that from before. I will have a look as soon as possible.

Paddy

unread,
Aug 25, 2016, 10:28:57 AM8/25/16
to pi3d
@mung kie, gradually making my way through the quagmire of setting up p4a again on a new linux installation (moved from ubuntu 14LTS to 16LTS and ended up with a new install on an empty partition (don't ask! Fortunately all the data is accessible on the old partition so not bad actually)) I am trying to keep a note of every step so I can write it up for the docs but quite hard as I'm not really sure which actions have any real effect! I've managed to make a couple of apk files that have installed but not run on phone, not yet advanced to running on android emulator and checking for errors.

Rather than install vmware and have to swap to and from windows all the time, would you be able to send me copies of your recipes/pi3d/__init__.py and any patch files and any other tweaks you can remember making to the  standard p4a setup? Otherwise the chances of ending up with anything reproducible are quite slim.

Paddy

PS I tried putting a 'private' recipe in ~/.local/share/python-for-android/build/p4a-recipes/pi3d but it failed to be picked up and had to add it to /usr/local/lib/python2.7/dist-packages/pythonforandroid/recipes/pi3d/ which doesn't seem satisfactory

Paddy

unread,
Aug 25, 2016, 5:44:29 PM8/25/16
to pi3d
Tried running on emulator, with bootstrap sdl2 then pygame and get basically the same error either way:

V/python  ( 3137): extracting lib/python2.7/lib-dynload/_csv.so
V/PythonActivity( 3137): About to do super onCreate
V/SDL     ( 3137): Device: generic_x86
V/SDL     ( 3137): Model: Android SDK built for x86
V/SDL     ( 3137): onCreate():null
W/System.err( 3137): Couldn't load SDL2 from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/org.example.myapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/org.example.myapp-1, /vendor/lib, /system/lib]]]: findLibrary returned null
D/dalvikvm( 3137): GC_FOR_ALLOC freed 1333K, 33% free 3595K/5320K, paused 2ms, total 2ms
D/dalvikvm( 3137): GC_FOR_ALLOC freed 2K, 30% free 3764K/5320K, paused 2ms, total 2ms
I/dalvikvm-heap( 3137): Grow heap (frag case) to 5.705MB for 1939932-byte allocation
D/dalvikvm( 3137): GC_FOR_ALLOC freed <1K, 22% free 5659K/7216K, paused 4ms, total 4ms
D/dalvikvm( 3137): GC_CONCURRENT freed 0K, 22% free 5659K/7216K, paused 1ms+1ms, total 3ms
D/dalvikvm( 3137): GC_CONCURRENT freed 3K, 11% free 6425K/7216K, paused 1ms+0ms, total 3ms
V/PythonActivity( 3137): Did super onCreate
V/PythonActivity( 3137): Setting env vars for start.c and Python to use
W/dalvikvm( 3137): No implementation found for native Lorg/libsdl/app/SDLActivity;.nativeSetEnv:(Ljava/lang/String;Ljava/lang/String;)V
D/AndroidRuntime( 3137): Shutting down VM


(or sdl with pygame) not entirely sure what causes this. Tried various other things such as adding pysdl2 as a requirement but still get the same error.

Paddy

unread,
Aug 25, 2016, 6:56:44 PM8/25/16
to pi3d
OK that error was because I had set up an emulator that used x86 atom. I did think it was much, much faster than I remembered. arm emulation on laptop is pretty slow. Now fails at import pi3d - no module named pi3d. And indeed pi3d doesn't seem to be in the apk site-packages so that's obviously not going to work. Not clear why it's not included as it's added to the distribution ok and packages that pi3d depends on (numpy and PIL) are added fine. Oh well, maybe it needs something else in the recipe, I'll wait and see what you tried.

mung kie

unread,
Aug 26, 2016, 4:58:15 PM8/26/16
to pi3d
I am afraid I gave up on the new pythonised recipe version of kivy/py4a though I don't think the problem was due to bad recipes, I get the feeling the way kivy is initialised has changed?

Anyways I should have attached a tgz of the last version of the scripts I used(unfortunately I may have a newer better python recipes but I cannot find them yet)

I will have a check tomorrow and see if I find anything newer and also post some example code that shows some stuff I was messing with that I hoped would allow more of a cross platform write and run on any supported system type thing.

Sorry for poking you with requests and not responding sooner, I should have a quick look at things tonight and follow up tomorrow. I should sort out the android dialog popup example if you need to look at how I am trying to call kivy popups. If you want me to hack/experiment on stuff in the pi3d code let me know what you think relevant sections of code are and how they fit in with kivy.

cheers :)
recipes.tgz

mung kie

unread,
Aug 26, 2016, 5:52:26 PM8/26/16
to pi3d

Also I used this attached script to create .apk but I think that was not using the buildozer system?

I am not sure what I did about getting ctypes installed in the new kivy build system, I get the feeling it maybe included by default now as I cannot see a ctypes recipe. Of course I may find something for ctypes and will let you know if I do, but as said I have only been using the old bash script build system for building pi3d apks as it worked well and I had no problems until now when I started to try integrating kivy widgets with pi3d.

Unfortunately it's so many months since I looked at the new pythonised android build system I have totally forgotten what I did, though I think I moved on to trying buildozer which was also not successful and seemed to have problems with including jar files in builds.

I definitely remember creating a few builds that seemed to show no errors in my logcat(adb logcat | grep -e python > errors.txt)
 and loaded pi3d but then just showed a black screen without crashing, so I guessed kivy was doing something weird in its gles configuration (maybe handling layers differently?).

I was too lazy to start hacking into kivys codebase as I never looked at it before and felt it would be too steep a learning curve.
.


make_apk.sh

mung kie

unread,
Aug 29, 2016, 6:52:50 PM8/29/16
to pi3d
I did not find any more recent kivy android python build scripts although I think there could be some more recent on a hard drive from the last laptop I had that seemed to get cpu overheat problems(seems nothing lasts more than a year thesedays :( )

Anyways I thought maybe I should post a more full version of the code that is causing me problems so others can run it and try testing.

I am hoping to have some wrapper code to import different 'backends' for pi3d that handle the input methods and drawing for different platforms, although this is partially in place in pi3d already there is no code in the 'pi3d_demos' that seems to run on android and gtk and terminal without lots of 'if platform==android: get alternative input' type stuff.

I wanted to have standard methods to 'get pointer position' 'get click/tap/etc'.

Also I wanted to have code that would call standard backend widgets such as filechooser/text dialog/alert message etc without need to write them in pi3d widgets.

The attached code is very basic hacked attempt that is by no means useful, but I sort of got stumped by the problems with kivy/android popup dialogs.

I have attached the code if you want to see what problems I am having(I have comment out the full dialog code for android and it just uses a keyboard popup), the tgz should simply build with the old bash script version of kivy buildozer.



pi3d_crossplatform.tgz

Paddy

unread,
Aug 31, 2016, 1:16:43 PM8/31/16
to pi3d
Hi, I've not had chance to look at this yet but I have made some progress (in some sense) with getting pi3d working on android again. see https://groups.google.com/forum/#!topic/kivy-users/XchfXbc0KpU The code needs a few tweaks in order to get it to run without PIL. Which is surprisingly feasible now but means that images have to be converted and saved as compressed numpy arrays, i.e. by doing
    im = np.array(Image.open('{}/{}.{}'.format(dirctry, f[0], f[1])))
    np
.savez_compressed('{}/{}'.format(dirctry, f[0]), im)
There are a couple of things not quite working yet, when I've sorted them out I will look at the problems with integrating the kivy U which is something that would be very nice to have, especially on android.



Paddy

unread,
Sep 3, 2016, 7:14:32 AM9/3/16
to pi3d
No joy getting kivy to coexist with pi3d. I suspect there is something low level in Android, certainly earlier versions, that will restrict running two display surfaces. I used the pi3d.Gui after adding an option to not show the pointer, there is probably a bit of tidying needed with this as there is potential conflict of double-click interpretation. I will be away for two weeks now so won't do any more till I get back.

Reply all
Reply to author
Forward
0 new messages