org.sikuli.script.Pattern Java Examples

The following examples show how to use org.sikuli.script.Pattern. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Guide.java    From SikuliX1 with MIT License 6 votes vote down vote up
public void addTracker(Pattern pattern, Region r, Visual c) {
  Tracker tracker = null;

  // find a tracker already assigned to this pattern
  for (Tracker t : trackers) {
    if (t.isAlreadyTracking(pattern, r)) {
      tracker = t;
      break;
    }
  }

  if (tracker == null) {
    tracker = new Tracker(this, pattern, r);
    trackers.add(tracker);
  }

  tracker.setAnchor(c);
}
 
Example #2
Source File: JythonCodeGenerator.java    From SikuliX1 with MIT License 6 votes vote down vote up
private String mouse(String type, Pattern pattern, String[] modifiersOrButtons) {
  String code = type + "(";

  if (pattern != null) {
    code += pattern(pattern);
  }

  if(modifiersOrButtons.length > 0) {
    if (pattern != null) {
      code += ", ";
    }

    code += String.join(" + ", modifiersOrButtons);
  }
  code += ")";
  return code;
}
 
Example #3
Source File: JythonCodeGenerator.java    From SikuliX1 with MIT License 6 votes vote down vote up
@Override
public String wait(Pattern pattern, Integer seconds, IRecordedAction matchAction) {
  String code = "wait(";

  if (pattern != null) {
    code += pattern(pattern);
  }

  if (seconds != null) {
    if (pattern != null) {
      code += ", ";
    }
    code += seconds;
  }

  code += ")";

  if (matchAction != null) {
    code += "." + matchAction.generate(this);
  }

  return code;
}
 
Example #4
Source File: Guide.java    From SikuliX1 with MIT License 6 votes vote down vote up
public void addTracker(Pattern pattern, SxAnchor anchor) {
  Tracker tracker = null;

  //      // find a tracker already assigned to this pattern
  //      for (Tracker t : trackers){
  //         if (t.isAlreadyTracking(pattern,r)){
  //            tracker = t;
  //            break;
  //         }
  //      }

  //      if (tracker == null){
  tracker = new Tracker(this, pattern, null);
  trackers.add(tracker);
  //      }
  BufferedImage img;
  try {
    img = pattern.getBImage();
    anchor.setActualSize(img.getWidth(), img.getHeight());
    tracker.setAnchor(anchor);
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
Example #5
Source File: Tracker.java    From SikuliX1 with MIT License 6 votes vote down vote up
public Tracker(Guide guide, Pattern pattern, Region match){
   this.guide = guide;
   //this.match = match;
   screen = new Screen();
   BufferedImage image;
   BufferedImage center;
   this.pattern = pattern;
   try {
      image = pattern.getBImage();
      int w = image.getWidth();
      int h = image.getHeight();
      center = image.getSubimage(w/4,h/4,w/2,h/2);
      centerPattern = new Pattern(center);
   } catch (Exception e) {
      e.printStackTrace();
   }
}
 
Example #6
Source File: SxMagnet.java    From SikuliX1 with MIT License 5 votes vote down vote up
public void addTarget(final Pattern pattern) {

    final SxAnchor a = new SxAnchor(pattern);
    guide.addToFront(a);

    targets.add(a);

    SxFlag f = new SxFlag("Flag");
    f.setLocationRelativeToComponent(a, Layout.LEFT);
    guide.addToFront(f);

    a.addListener(new AnchorListener() {
      @Override
      public void anchored() {
        Debug.info("[Magnet] pattern anchored");

        anchoredCount += 1;

        if (anchoredCount == targets.size()) {
          allTargetAnchored();
        }
      }

      @Override
      public void found(SxAnchor source) {
        // TODO Auto-generated method stub
      }
    });

  }
 
Example #7
Source File: PatternPaneScreenshot.java    From SikuliX1 with MIT License 5 votes vote down vote up
public void setParameters(final String patFilename,
        final boolean exact, final double similarity,
        final int numMatches) {
  if (!_runFind) {
    _showMatches = null;
    _fullMatches.clear();
    repaint();
    _runFind = true;
    patternFileName = patFilename;
    new Thread(() -> {
      try {
        Finder f = new Finder(_simg);
        f.findAll(new Pattern(patFilename).similar(0.00001));

        int count = 0;
        while (f.hasNext()) {
          if (++count > MAX_NUM_MATCHING) {
            break;
          }
          Match m = f.next();
          Debug.log(4, me + "f.next(%d): " + m.toString(), count);

          _fullMatches.add(m);
        }

        EventQueue.invokeLater(() -> {
          setParameters(exact, similarity, numMatches);
        });
      } catch (Exception e) {
        Debug.error(me + "Problems searching image in ScreenUnion\n%s", e.getMessage());
      }
    }).start();
  } else {
    setParameters(exact, similarity, numMatches);
  }
}
 
Example #8
Source File: JythonCodeGenerator.java    From SikuliX1 with MIT License 5 votes vote down vote up
@Override
public String dragDrop(Pattern sourcePattern, Pattern targetPattern) {
  String code = "dragDrop(";

  if (sourcePattern != null) {
    code += pattern(sourcePattern) + ", ";
  }

  code += pattern(targetPattern);
  code += ")";

  return code;
}
 
Example #9
Source File: MouseWheelAction.java    From SikuliX1 with MIT License 5 votes vote down vote up
public MouseWheelAction(Pattern pattern, int direction, int steps, String[] modifiers, long stepDelay) {
  super(pattern);
  this.direction = direction;
  this.steps = steps;
  this.modifiers = modifiers;
  this.stepDelay = stepDelay;
}
 
Example #10
Source File: JythonCodeGenerator.java    From SikuliX1 with MIT License 5 votes vote down vote up
@Override
public String wheel(Pattern pattern, int direction, int steps, String[] modifiers, long stepDelay) {
  String code = "wheel(";

  if (pattern != null) {
    code += pattern(pattern);
    code += ", ";
  }

  code += direction > 0 ? "WHEEL_DOWN" : "WHEEL_UP";
  code += ", ";
  code += steps;

  if(modifiers.length > 0) {
    code += ", ";
    code += String.join(" + ", modifiers);
  }

  if (stepDelay != Mouse.WHEEL_STEP_DELAY) {
    if(modifiers.length == 0) {
      code += ", 0";
    }

    code += ", ";
    code += stepDelay;
  }

  code += ")";
  return code;
}
 
Example #11
Source File: SxAnchor.java    From SikuliX1 with MIT License 5 votes vote down vote up
public void setTracker(Pattern pattern) {
  setOpacity(0f);
  tracker = new Tracker(pattern);
  BufferedImage img;
  try {
    img = pattern.getBImage();
    setActualSize(img.getWidth(), img.getHeight());
    tracker.setAnchor(this);
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
Example #12
Source File: ImageCommand.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
Object getPattern(ImageORObject obj, Flag... flag) throws UnCaughtException {
    String location = obj.getRepLocation() + File.separator + obj.getImageLocation();
    tmp = new File(location);
    iflag = Flag.IMAGE_AND_TEXT;
    if (flag.length > 0) {
        iflag = flag[0];
    }
    boolean validfile = tmp.exists() && tmp.isFile();

    if (iflag == Flag.TEXT_ONLY) {
        if (!"".equals(obj.getText())) {
            return obj.getText();
        } else {
            throw new UnCaughtException("Empty Text is Given",
                    "The Object '" + obj.getName() + "' contains Empty Text!!!");
        }
    } else if (iflag == Flag.IMAGE_ONLY) {
        if (validfile) {
            return new Pattern(location).targetOffset(obj.getOffset().x,
                    obj.getOffset().y);
        } else {
            throw new UnCaughtException("File Not Found", location
                    + " is Missing!!!");
        }
    } else if (validfile) {
        return new Pattern(location).targetOffset(obj.getOffset().x,
                obj.getOffset().y);
    } else if (!"".equals(obj.getText())) {
        return obj.getText();
    } else {
        throw new UnCaughtException("Empty Text is Given",
                "The Object '" + obj.getName() + "' contains Empty Text!!!");
    }
}
 
Example #13
Source File: AndroidRegion.java    From sikuli-monkey with MIT License 5 votes vote down vote up
private float extractPatternSimilarity(Pattern pattern) { // tricky
    // Pattern("/path/to/image.png").similar(0.7)
    Matcher matcher = java.util.regex.Pattern.compile(
            "\\.similar\\((.+?)\\)").matcher(pattern.toString());
    boolean found = matcher.find();
    assert found : pattern.toString();

    return Float.valueOf(matcher.group(1));
}
 
Example #14
Source File: Guide.java    From SikuliX1 with MIT License 5 votes vote down vote up
public void addTracker(Pattern pattern, Region r, ArrayList<Visual> components) {
  Tracker tracker = new Tracker(this, pattern, r);
  for (Visual c : components) {
    tracker.setAnchor(c);
  }
  trackers.add(tracker);
}
 
Example #15
Source File: AndroidRegion.java    From sikuli-monkey with MIT License 5 votes vote down vote up
@Override
public <PSRML> Location getLocationFromPSRML(PSRML target) throws FindFailed {
    Location loc = super.getLocationFromPSRML(getAlternativePS(target));
    if (target instanceof Pattern) {
        Location offset = ((Pattern)target).getTargetOffset();
        loc.translate(offset.x, offset.y);
    }
    return loc;
}
 
Example #16
Source File: Tracker.java    From SikuliX1 with MIT License 5 votes vote down vote up
public boolean isAlreadyTracking(Pattern pattern, Region match) {
   try {
      boolean sameMatch = this.match == match;
      boolean sameBufferedImage = this.pattern.getBImage() == pattern.getBImage();
      boolean sameFilename = (this.pattern.getFilename() != null &&
            (this.pattern.getFilename().compareTo(pattern.getFilename()) == 0));
      return sameMatch || sameBufferedImage || sameFilename;
   } catch (Exception e) {
      return false;
   }
}
 
Example #17
Source File: ElementBasicsTest.java    From SikuliX1 with MIT License 5 votes vote down vote up
@Test
public void test025_PatternImageFilename() {
  testIntro();
  String imageName = testName;
  Pattern pattern = new Pattern(imageName);
  testOutro("%s (%s)", pattern, imageName);
  assertTrue("NotValid: " + pattern.toString(), pattern.isValid());
}
 
Example #18
Source File: PropertyEditor.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private Iterator<?> getMatches() throws FindFailed, IOException {
    if (refImageLocation.exists()) {
        Finder localFinder;
        localFinder = new Finder(refImageLocation.getAbsolutePath());
        localFinder.findAll(new Pattern(imageLocation.getAbsolutePath()).similar(tempObject.getPrecision()));
        return localFinder;
    } else {
        return null;
    }

}
 
Example #19
Source File: RightClickAction.java    From SikuliX1 with MIT License 4 votes vote down vote up
public RightClickAction(Pattern pattern, String[] modifiers) {
  super(pattern, modifiers);
}
 
Example #20
Source File: SxMagnet.java    From SikuliX1 with MIT License 4 votes vote down vote up
void attractTarget(SxAnchor a, Point targetLocation) {

    try {
      Pattern pattern = a.getPattern();
      SxImage img = new SxImage(pattern.getBImage());

      SxClickable clickable = new SxClickable();
      clickable.setLocationRelativeToComponent(img, Layout.OVER);
      guide.addToFront(clickable);

      clickable.clickPoint = a.getCenter();

      Link link = new Link();
      link.image = img;
      link.anchor = a;
      links.add(link);

      img.setShadowDefault();
      img.setActualLocation(a.getActualLocation());

      Dimension currentSize = a.getActualSize();
      Dimension targetSize = new Dimension(currentSize);
      targetSize.width *= 1.5;
      targetSize.height *= 1.5;

      img.addResizeAnimation(currentSize, targetSize);

      Point currentLocation = new Point(a.getActualLocation());

      targetLocation.x -= targetSize.width / 2;
      targetLocation.y -= targetSize.height / 2;

      img.addMoveAnimation(currentLocation, targetLocation);
      guide.addToFront(img);
      img.startAnimation();

      guide.repaint();

    } catch (Exception e) {
      e.printStackTrace();
    }

  }
 
Example #21
Source File: SxAnchor.java    From SikuliX1 with MIT License 4 votes vote down vote up
public Pattern getPattern() {
  return pattern;
}
 
Example #22
Source File: SxAnchor.java    From SikuliX1 with MIT License 4 votes vote down vote up
public SxAnchor(Pattern pattern) {
  super();
  this.pattern = pattern;
  setTracker(pattern);
}
 
Example #23
Source File: JythonCodeGenerator.java    From SikuliX1 with MIT License 4 votes vote down vote up
@Override
public String rightClick(Pattern pattern, String[] modifiers) {
  return mouse("rightClick", pattern, modifiers);
}
 
Example #24
Source File: ClickAction.java    From SikuliX1 with MIT License 4 votes vote down vote up
public ClickAction(Pattern pattern, String[] modifiers) {
  super(pattern);
  this.modifiers = modifiers;
}
 
Example #25
Source File: MouseMoveAction.java    From SikuliX1 with MIT License 4 votes vote down vote up
public MouseMoveAction(Pattern pattern) {
  super(pattern);
}
 
Example #26
Source File: WaitAction.java    From SikuliX1 with MIT License 4 votes vote down vote up
public WaitAction(Pattern pattern, Integer seconds, IRecordedAction matchAction) {
  super(pattern);
  this.seconds = seconds;
  this.matchAction = matchAction;
}
 
Example #27
Source File: PatternAction.java    From SikuliX1 with MIT License 4 votes vote down vote up
public PatternAction(Pattern pattern) {
  super();
  this.pattern = pattern;
}
 
Example #28
Source File: PatternAction.java    From SikuliX1 with MIT License 4 votes vote down vote up
public Pattern getPattern() {
  return pattern;
}
 
Example #29
Source File: PatternAction.java    From SikuliX1 with MIT License 4 votes vote down vote up
public void setPattern(Pattern pattern) {
  this.pattern = pattern;
}
 
Example #30
Source File: DragDropAction.java    From SikuliX1 with MIT License 4 votes vote down vote up
public DragDropAction(Pattern sourcePattern, Pattern targetPattern) {
  this.sourcePattern = sourcePattern;
  this.targetPattern = targetPattern;
}