← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #247496]: Defined Region is getting corrupted if I enter it into a While loop

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
--- supposing you are using version 1.0.1 (since you are new to Sikuli)

Some general comments first.

--- This is how I would write these functions:

public static Region GetRegionOfImage(String strImage) {
  try{
  Match computerScreenshot = sikuliObj.find(strImage);
  Debug.user("The co-ordinate of the image %s is %s", strImage, computerScreenshot); // import org.sikuli.basics.Debug;
  // usage like String.format()
  computerScreenshot.highlight(4);
  }catch (Exception e) {
   Debug.user("Some error in getting the region of the Image %s - entered in Catch block\n%s",  strImage,   e.getMessage());
  }
  return computerScreenshot;
 }

A Match is a Region as well (Match extends Region) and can be used as
such.

---   @SuppressWarnings("deprecation")
   Region rd=new Region(x1+x,y1+y,w1+w,h1+h);

This is generally not recommended - deprecations are not there for fun.

on the Java level you should use Region.create()
   Region rd = Region.create(x1+x,y1+y,w1+w,h1+h);

--- the loop:

ImgStrtWin1= Location for Image of the arrow Icon;
while(true)
   {
     if ( IsImagePresent(Directory where the Image is kept for Heading)) {
      //Settings.MinSimilarity=.9;
      Region rd10=GetRegion(Directory where the Image is kept for Heading,2,59,-3,-2);
      rd10.highlight(4);
      sikuliObj.click(rd10);
      System.out.println("Clicked the image of room type "+Directory where the Image is kept for Heading+" in one go- all good..");
      break;
      }
     else {
      ClickImage(ImgStrtWin1);
      System.out.println("It took some loops to click the image of room type "+ImgStrtWin48+" all good..");
      wait(1); // give the GUI some time to scroll
     }
   }

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