android python scripting: GUI?

foosion picture foosion · Sep 11, 2011 · Viewed 24k times · Source

Are there basic GUI functions in SL4A? I'd like to run a python program on Android and would need a listbox and simple dialogs (display info and get input).

There seem to be simple dialogs, but I haven't found a listbox. If there isn't a listbox, I should be able to create one if there's the ability to write text and highlight rectangles to specified parts of the screen and react to the user touching the screen or typing (including knowing where the user touched or where the cursor is).

Answer

ProfSmiles picture ProfSmiles · Oct 13, 2011

Essentially there are three things you can do:

  1. If you just want simple Android lists and inputs, such as getting a user's input (e.g., a username and password) or showing a list of option to choose from, then there are some tutorials here: http://code.google.com/p/android-scripting/wiki/UiExamples

  2. If you want to show information (i.e., not have the user select it), you could try showing HTML in a WebView and respond via events: http://code.google.com/p/android-scripting/wiki/UsingWebView

    Doing this, you get limited functionality via events by using droid.eventPost(eventName,eventData); in JavaScript and droid.eventWaitFor(eventName).result in Python. You can then do whatever you want with the received data.

  3. If you're feeling brave, the latest unofficial release contains support for full Android layouts (ones made in XML, like those found in a native Android app). You can find a guide for that here: http://code.google.com/p/android-scripting/wiki/FullScreenUI