mismatched input 's' expecting NEWLINE error is raised when I tried to find a region.

Asked by Atul Desai

Hi,

When I run the following code "mismatched input 's' expecting NEWLINE" error is raised.

from sikuli import *
activity = "1395933560122.png"
ScreenRegion s = new DesktopScreenRegion();
ScreenRegion ActivityNametext = s.find(new ImageTarget(new File("activity"));
ScreenRegion right = Relative.to(ActivityNametext).right(150).getScreenRegion();

Canvas canvas = new DesktopCanvas();
canvas.addBox(ActivityNametext);
canvas.addBox(right);
canvas.display(3);

can someone help me to resolve this issue.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

it should be Python, but your statements are Java syntax.

Revision history for this message
Atul Desai (atuld) said :
#2

Oh! How can I ask Sikuli to look at a region relative to a target?

Revision history for this message
RaiMan (raimund-hocke) said :
#3

The above snippet is from a Java program working with Sikuli Java API (from https://code.google.com/p/sikuli-api/), which of course does only have a Java level API, which is to some extent feature compatible, but not on the function level (API level).

the SikuliX equivalent to the first code block:

from sikuli import *
activity = "1395933560122.png"
# ScreenRegion s = new DesktopScreenRegion();
#ScreenRegion ActivityNametext = s.find(new ImageTarget(new File("activity"));
#ScreenRegion right = Relative.to(ActivityNametext).right(150).getScreenRegion();
activityNametext = find(activity);
right = activityNametext.right(150)

the Canvas feature is not yet available in SikuliX, so this cannot be transcripted:
Canvas canvas = new DesktopCanvas();
canvas.addBox(ActivityNametext);
canvas.addBox(right);
canvas.display(3);

... but we have highlight:
activityNametext.highlight(1)
right.highlight(1)

Revision history for this message
Atul Desai (atuld) said :
#4

Hi I made slight modification in code as I want to search a an object in that specific region which is as follows, but the script is failing at line 8 and raise error stating "[error] script [ regiontest ] stopped with error in line 8
[error] AttributeError ( 'int' object has no attribute 'right' )"

from sikuli import *
activityRegion = Region(225,489,191,370)
activity = "1395933560122.png"
# ScreenRegion s = new DesktopScreenRegion();
#ScreenRegion ActivityNametext = s.find(new ImageTarget(new File("activity"));
#ScreenRegion right = Relative.to(ActivityNametext).right(150).getScreenRegion();
activityNametext = hover(activityRegion.find(activity));
right = activityNametext.right(500)

activityNametext.highlight(1)
right.highlight(1)

Revision history for this message
Eugene S (shragovich) said :
#5

Hi,

You get this error because, in your case, "activityNametext" is integer and not an object. Please read carefully the documentation regarding what "hover" method returns (http://doc.sikuli.org/region.html):

The number 1 if the mousepointer could be moved to the click point. A 0 (integer null) returned means that because of some reason, no move could be performed (in case of PS may be not Found).

I am trying to understand what you are trying to achive. So if what you want is to highlight the area on the rightside of the "activity", do:

activityRegion = Region(225,489,191,370)
activity = activityRegion.find("<pattern.png>).highlight(1) # Will find and highlight activity inside activityRegion
activity.right().highlight(1) #Will highlight everything to the right of "activity".

Cheers,
Eugene

Can you help with this problem?

Provide an answer of your own, or ask Atul Desai for more information if necessary.

To post a message you must log in.