X-1.0rc3: IDE: "with Region" doesn't work after first run - uses whole screen --- workaround

Bug #850520 reported by Keith Wissing
24
This bug affects 4 people
Affects Status Importance Assigned to Milestone
SikuliX
Fix Released
Critical
RaiMan

Bug Description

--- workaround

put the code block (no indentation !) between

setROI(some_region)
#...
# code
#...
setROI(SCREEN)

----------------------------------------------------

# According to http://sikuli.org/docx/region.html#grouping-method-calls-with-region
# "All methods inside the with block that have the region omitted are redirected to the region object specified at the with statement."
# Based on this statement, I would expect the following code to only highlight the bottom three icons.
# Tested on both 64 bit Windows 7 and OSX Lion with identical results.

# Version: Sikuli X 1.0rc2 "Maltese" Released on 2011/02/10

# Expected results:
# * The script should highlight the test image, the bottom half of the test image, and the bottom three icons in the test image.

# Actual results:
# * All 6 icons are highlighted.

# Steps to reproduce:
# 1. Close all running copies of the Sikuli IDE.
# 2. Open TestImage.png in an image viewer at 1:1 zoom level. (Possibly by viewing the .html file)
# 3. Open the Sikuli IDE and load this script.
# 4. Run the script. During the first run you will see the expected behavior. It will only highlight the bottom three icons.
# 5. Run the script again. This time and any time after, it will highlight all 6 icons. This is not the expected behavior.

testimage = find()
testimage.highlight(1)

bottomhalf = Region(testimage)
bottomhalf.setY(bottomhalf.getCenter().y)
bottomhalf.setH(bottomhalf.getH()/2)
bottomhalf.highlight(1)

with bottomhalf:
        icons = findAll()
        sorted_icons = sorted(icons, key=lambda m:m.y)
        for icon in sorted_icons:
                icon.highlight(1)

Tags: idererun
Revision history for this message
Keith Wissing (hitiek) wrote :
RaiMan (raimund-hocke)
summary: - "with Region" doesn't work after first run in IDE
+ X-1.0rc3: IDE: "with Region" doesn't work after first run - uses whole
+ screen
Changed in sikuli:
status: New → Confirmed
description: updated
Revision history for this message
RaiMan (raimund-hocke) wrote : Re: X-1.0rc3: IDE: "with Region" doesn't work after first run - uses whole screen

@Keith

- a general solution, to get the content region of an app window (this is for Mac ;-)
- the app must be running in this case

ap = App("Preview")
top = 55
ap.focus()
win = ap.window()
content = win.above(1).below(top).below(win.h-top)
content.highlight(2)

so no need to capture/find the whole content.

Revision history for this message
Ben Turner (ben-turner) wrote :

Darn, I've just converted quite a few blocks of my code to use the "with Region" paradigm, such as :

 with Region(find(Pattern("ALLIEI.png").similar(0.98))):
  rightClick(Pattern("ALLIEI-1.png").similar(0.80).targetOffset(-1,29))
  click("createItem.png")
  type(Pattern("1324945448304.png").similar(0.80), "Baldrick")

In this case, the type command is hitting a single blank line - which matches hundreds of places, but within the region it only matches one. And, of course, it's not working as it's not respecting the "with Region" command.

The workaround for now appears to be:

 r = Region(find(Pattern("ALLIEI.png").similar(0.98)))
 r.rightClick(Pattern("ALLIEI-1.png").similar(0.80).targetOffset(-1,29))
 r.click("createItem.png")
 r.type(Pattern("1324945448304.png").similar(0.80), "Baldrick")

Would be great to see this working, as the blend of the "with Region" command and Sikuli Syntax would be really quite powerful.

RaiMan (raimund-hocke)
summary: X-1.0rc3: IDE: "with Region" doesn't work after first run - uses whole
- screen
+ screen --- workaround
description: updated
RaiMan (raimund-hocke)
Changed in sikuli:
status: Confirmed → Fix Committed
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → x1.0
RaiMan (raimund-hocke)
tags: added: idererun
RaiMan (raimund-hocke)
Changed in sikuli:
importance: Undecided → High
RaiMan (raimund-hocke)
Changed in sikuli:
importance: High → Critical
RaiMan (raimund-hocke)
Changed in sikuli:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.