← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #150476]: Testing if something was clicked? (clickable)

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
--1.

At least the action element clickable works with the current version
guide-1.4.2:

from guide import *
clickable("some-image.png")
show()

A clickable element can be named with a second parameter

clickable("some-image.png", "some-image")

and when clicked you can see the effect in the message area (Last
clicked: name). The methods to check the last clicked element are not
yet implemented though in the Sikuli script API.

So this feature is usable with the restriction, that the script is
waiting at the show() for the user to click (without show, the clickable
element will not be activated). On top, even if you say show(5), it will
currently ignore the timing parameter and wait forever (this is true, if
either a dialog() or a clickable() is registered)

--2. this leads to your second question:

In the standard Sikuli API (guide is an extension) currently there is no
feature to get a feedback about a click somewhere. We only can react on
the visual effects a click has.

So if I need it in a script, I use some image, that is visible all the
time in a specific area on the screen. The script stops, when this image
is no longer visible.

keep_running = "some-image.png"

while exists(keep_running, 0):
   # your scripting

to stop the script, I simply hide the image keep_running somehow.

--- You might implement it with an

some_region = Region(...) # or any other approach to define the region
some_region.shouldStop = False

def handler(event):
   event.region.shouldStop = True
   event.region.stopObserver()

some_region.onChange(handler)
some_region.observe(FOREVER, background=True) 

while not some_region.shouldStop:
   # here goes your scripting

I still think, the exists() is a bit easier. observe() is interesting,
if you have more than 2 or 3 events in parallel to observe.

--- if you are interested in more sophistication according parallelism
in Sikuli scripts, have a look at Python modules thread and threading
(http://docs.python.org/library/thread.html#module-thread) which allows
to implement observe()-like features on your own. (do not use subprocess
- it makes problems currently).

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