[sugar] Injecting Code into main Sugar GUI routine
Erik Garrison
erik
Mon Jul 7 12:37:26 EDT 2008
On Sun, Jul 06, 2008 at 05:20:33PM -0500, Zach Riggle wrote:
> I am a student working on a Google Summer of Code project, sugarbot
> (more information here: http://code.google.com/p/sugarbot/). I am
> currently at a stage where I need to be able to hook into the Sugar
> GUI, to automate the process of launching Activities (e.g. simulate a
> mouse-click on the activity list, scroll down, click on the Activity
> name). The process of automating the GUI is straightforward and
> should not be a problem, however I do not know where the best location
> would be to inject my code, or if there would be a way to create a
> launcher that, in turn, launched the Sugar interface inside of its own
> process.
>
> Additionally, if anyone can point me in the direction of any materials
> related to the Sugar startup procedures/process, it would be greatly
> appreciated.
Zach,
I assume you will use the X windows XTest extension:
e.g. http://linux.die.net/man/3/xtestfakekeyevent
These functions can be used to completely simulate user input.
There are a variety of methods which could be used to initiate an xtest
test script. One option which seems interesting is hooking the script
into a keypress chord such as '<alt>F8'. Then you could cleanly
initiate the test script in a given interface without having to add
significant features to the UI. This can be done in
sugar/src/view/keyhandler.py.
First define a method on KeyHandler which launches your test script:
def handle_test_script(self):
# ... here you can put the GUI in a known pre-test state
import subprocess
subprocess.Popen(['/path/to/script', 'arg1', 'arg2'])
# ... alternatively you could import the required XTest functions
# and run the script within this method
The function name should be prefixed with 'handle_'.
Now add an entry to the _actions_table:
'<alt>F8' : 'test_script',
When the KeyHandler object is instantiated, it grabs all the keypresses
in this table and registers a callback function for keypress and
kerelease events. When hit, the keypress callback will call
KeyHandler.handle_value for whatever value is recorded in the
_actions_table (e.g. 'test_script').
This is very unsophisticated, but I hope it helps.
I am unsure of how you plan to verify the test without hooks throughout
the Sugar GUI and tested activities. The most obvious first step is to
visually verify the progress of the test. Any ideas?
Erik
More information about the Sugar-devel
mailing list