Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Scan Wait Rate doesnt set scan rate properly. #189

Open
raider001 opened this issue Jul 12, 2023 · 1 comment
Open

Set Scan Wait Rate doesnt set scan rate properly. #189

raider001 opened this issue Jul 12, 2023 · 1 comment

Comments

@raider001
Copy link

Hey there, thankyou for this library, so far its great!

When playing with the Set Scan Rate key word, I noticed that the set scan rate doesn't seem to apply properly.

I dont have an IDE available, nor do I have a example script to demonstrate this at the moment otherwise I would do a pull request or give the script to demonstate... But the problem is due to the following:

@RobotKeywords
public class ScreenKeywords {

    private static double DEFAULT_TIMEOUT = 3.0;
    private static Screen screen = new Screen();
    private static Region region = new Region(screen);

Note in ScreenKeywords.java, the region is created

and in SettingsKeywords.java

This is good, but this is an issue with how the Region class is then initialised in SikuliApi, which at its initialisation, it only ever calls Settings.WaitScanRate once.

public class Region extends Element {
   ...
  /**
   * set the regions individual WaitScanRate
   *
   * @param waitScanRate decimal number
   */
  public void setWaitScanRate(float waitScanRate) {
    this.waitScanRate = waitScanRate;
  }

  private float waitScanRateDefault = Settings.WaitScanRate;
  private float waitScanRate = waitScanRateDefault;

So the following logic, doesn't quite control the scan rate for the region defined in the region key words.

   @RobotKeyword("Set wait scan rate"   + "\n Specify the number of times actual search operations are performed per second while waiting for a pattern to appear or vanish.")
   @ArgumentNames({"delay"})

   public void setWaitScanRate(float scanRate) {
      Settings.WaitScanRate = scanRate;
    }

So this is where it gets a little tricky because the two classes containing the key words don't effectively work with one-another.

Could always do the lazy option and move the Set wait scan rate into ScreenKeywords.java and then do a
region.setWaitScanRate(float scanRate) instead (I wont complain, this will solve my issue ;) )

or.. if you are looking for a cleaner/ more elegant solution..

Create a settings class service, with an inbuilt observer pattern to notify settings changes made from SettingsKeywords.java to ScreenKeywords.java.

I would normally suggest DI, but being that I'm not super experienced with robot keywords yet and how that impacts keyword registration, A Singleton pattern may be better suited here even though its more of a anti-pattern.

@raider001
Copy link
Author

This all if I interpreted this right. reading through the code in the web browser can be difficult :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant