Hi, a lot of work starting this 2014, but let's start with the first post of the year.
Our producers are always in the rush, calling clients, delivering projects, etc and all the time they are asking us for tools to manage projects on their smart-phones, so we think that some apps could also be useful for the artists when simple functionality is needed. So we did some research and found that is really easy to prototype Python apps in Android, and this post is for this...
Building Android apps with Python and Shotgun
For us, the important one is Python, this because the official Shotgun API is in this language.
So, let's start...
Firs of all you will need to download and install two apk's on your phone, one is the scripting layer for android and the second its the python interpreter, the installation order doesn't matter.
Scripting Layer for Android (SL4A)
Python Interpreter for Android (Py4A)
If you've never installed apk's before you maybe need to set your phone to allow the installation of non market apps (Google Play), this could be different in all the Android versions and distros of all the phones but commonly is like this:
- Go to Settings.
- Open Security.
- Click Unknown sources.
Once you have installed the apps, it's time to install the interpreter itself, this will be performed by the Python for android app, open it and select install. This will download all the Python modules and setup the interpreter.
When this is done, now you can open the SL4A app and see some sample python scripts that uses the Android Python API, very simple to use, here is an example:
All this scripts are located in the following path: /sdcard/sl4a/scripts
Here you can create new ones, and organize them in folders if you want, check the SL4A User Guide
To learn about the commands and all the functionality you can access from the API, the best places are the docs, and also all the examples they have.
Now, we need the Shotgun API to perform what we want, this is really easy, only put the shotgun_api3 folder in the following path: /sdcard/com.googlecode.pythonforandroid/extras/python/
By doing this, you can perform "from shotgun_api3 import Shotgun"
At this point you can create scripts that works like command line or auto scripts but, what if we want an app with a graphical user interface?
Well, Android API has it's own way to do this by XML layouts, and is really easy to use.
Follow this link to check how to use it.
In order to make this more simple, I use Android Studio, where I design the layout in a graphic mode like Qt-Designer, dragging widgets and adjusting properties, then I copied the formatted xml and saved as an xml file to load it into my code as a string:
And that's it, you can start to build python apps for Android that can interact with Shotgun, let me show you an app to Send Support Tickets:
This example is made of three files: The main python script, the xml layout and a banner image
The banner image:
Here the XML Layout:
Here the main python script:
From here, there are a lot more things to review:
By using this approach to build mobile apps for Shotgun you are delivering the source code to the users including the api access to Shotgun and this won't be acceptable for most studios.
Also it's difficult to setup the first time, and not all the users can do it.
And maybe the most important one, this approach works for Android and most (if not all) of the producers use iPhones, and for that, currently I haven't found an easy way to script apps in Python on iOS.
But it's good to know and an interesting and really quickly way to prototype apps you need and make changes really easy, so the users can give you feedback and get all the info needed to build the final app, maybe with Phonegap or Kivy.