0

I started with importing GTK, and monkeyrunner:

from com.android.monkeyrunner import MonkeyRunner
import gtk
...

when I run this with monkeyrunner in the SDK tools, it says ImportError: No module named gtk. When I run this with Python, it says ImportError: No module named com.android.monkeyrunner.

Is there any way to set up a program that uses both modules?

NoBugs
  • 9,310
  • 13
  • 80
  • 146

1 Answers1

1

MonkeyRunner is built with Jython and it only has a small subset of the standard modules compiled in. If you would like to use MonkeyRunner with other python packages then you will need to use os.system or something like that in your MonkeyRunner program to call a separate python instance.

n8schloss
  • 2,723
  • 2
  • 19
  • 27
  • That's what I suspected, though I was looking for a way that I could make a pyGTK app to connect using monkeyrunner. I could use os.system or something, but that would seem to be messy, require waitForConnection() at each command sent, and making an adb shell request might be just as good. – NoBugs Jul 23 '12 at 23:08
  • Yeah, but doing it the other way (calling python from monkeyrunner) has way less overhead. Unfortunately there isn't really a perfect solution here. – n8schloss Jul 23 '12 at 23:20
  • Do you know of an example where monkeyrunner might call a Python GUI script and receive commands from it? – NoBugs Jul 24 '12 at 00:03
  • Not right off hand, but as a side note what do you need from python GUI, because MonkeyRunner does have some very simple GUI elements of it's own. See http://developer.android.com/tools/help/MonkeyRunner.html#alert and http://developer.android.com/tools/help/MonkeyRunner.html#choice – n8schloss Jul 24 '12 at 00:04
  • Looks like it IS possible to import it from Java code: https://groups.google.com/forum/?fromgroups#!topic/android-developers/rwXy22QBxOs – NoBugs Jul 25 '12 at 03:28
  • Oh, well if you are trying to run MonkeyRunner from Java, then just use ChimpChat. See http://dtmilano.blogspot.com/2011/11/android-using-monkey-from-java.html for an intro to ChimpChat. – n8schloss Jul 25 '12 at 17:42