← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #140946]: How to multi thread

 

Question #140946 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/140946

    Status: Open => Answered

RaiMan proposed the following answer:
You already decided to wait for a bug free observe feature ;-)

observe might be the best solution in many cases, where you want to wait
for different visual events may be in different regions and then do some
actions. it is really some kind of a dispatcher feature.

But you always have to be aware, that too many observations in parallel
might produce a chaos, since we only have one mouse and one keyboard.
And you have to take care, that one action does not mislead another
observation (e.g. opening some windows, that overlap observed regions).

so: it is a powerful feature and will even be more powerful with rc2
(the docs are already talking about ;-), but  ....

--- If you really want to "multi tread": all the standard Python
features like thread and threading work fine in Sikuli and have many
more options to synchronize the usage of mouse, keyboard and other
assets.

simple example:

def stopSelect(t): # this will be threaded
	wait(t)
	mouseDown(Button.RIGHT)
	mouseUp()

def myAlarm(text, t=2):
	import thread
	thread.start_new_thread(stopSelect, (t, ))
	selectRegion(text)

using
myAlarm("the text to be displayed")
would display the capture overlay with the message for 2 seconds and then automatically vanish, because of the right mouse click in the thread setup with stopSelect().

--- I have experimented with another thing:
running a thread, that constantly tracks mouse location and is able to recognize simple gestures (e.g. going to the screen borders and corners) to e.g. support measuring visual objects and in a popup shows a "Region(x,y,w,h)" that can be used in a script.

--- Another option for limited "parallel processing" is to use the XMLRPC feature.
If interested: https://answers.launchpad.net/sikuli/+faq/1331

You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.