IDE Offset Button

Asked by Mike

If I press the Offset button I get some code like:

Region(1113,792,254,205).asOffset()

Where is .asOffset documented?

What is the Offset button for?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Mike
Solved:
Last query:
Last reply:
Revision history for this message
masuo (masuo-ohara) said :
#1

Try this codes.

r1 = Region(100,100,300,300)
r1.highlight(2)
r2 = Region(100,100,300,300).asOffset(100,100)
r2.highlight(2)

You can use "Offset" button when you want to create a region with offset.
This document will help you.
https://sikulix-2014.readthedocs.io/en/latest/region.html?highlight=Offset

Revision history for this message
Mike (maestro+++) said :
#2

I can get this to work:

r2 = Region(100,100,300,300).offset(500,500)

However your code gave me:

[error] Error caused by: Traceback (most recent call last): File "C:\SX\OffsetTest.sikuli\OffsetTest.py", line 6, in <module> r3 = Region(100,100,300,300).asOffset(100,100) TypeError: asOffset(): expected 0 args; got 2

Did it run on your environment? I am Windows 10 Sikulix 1.1.4

I can imagine why you might want an offsetted region. However the button a) uses an undocumented method, and b) gives you no visual means of creating the offset.

It's still a bit of a mystery...

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

Region.asOffset() is a not-documented-sorry-for-that;-) function, that simply turns the Region into a Location(w, h), so it can be used as a Region offset:

anOffset = Region(100,100,300,300).asOffset()
newRegion = someRegion.offset(anOffset)

I will remove the mystery by adding it to the docs ;-)

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

BTW: the feature is intended to help in defining regions in a GUI relative to others, if a script should work independently of absolute positions on a screen.

You find one ore more fixed reference images and then the rest is relative to those by offsets.

Revision history for this message
masuo (masuo-ohara) said :
#5

@Mike
I misunderstood. I'm sorry.

Revision history for this message
Mike (maestro+++) said :
#6

OK - I think I've got an idea of what this is. It actually produces a location that you can therefore feed in as an offset to a region. Right now it's not obvious what the sequence of events is but I can experiment.

Revision history for this message
Mike (maestro+++) said :
#7

(Sorry - my response overlapped with yours )

Revision history for this message
Mike (maestro+++) said :
#8

It looks to me as though no matter how you draw the rectangle, it will always produce a top-left to bottom-right offset, so for offsets that are to the left, or above the starting point, you are going to have go in and manually adjust one or both parameters. Prima facie, it will be wrong in 75% of cases.

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

In fact, at time of first implementation, it was just a convenience tool, to measure distances between points.

Now that the result is visible as an Offset(x, y), I agree, that one expects the drawing direction (and hence the end point relative to the start point) should be taken into account.

Thanks for testing and pointing out.

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

revised the implementation, so now the drawing direction is evaluated and shown with respective negative x and/or y.

Please test.

Revision history for this message
Mike (maestro+++) said :
#11

Hi Raiman - completely different: was like:

 Region(1125,501,156,93).asOffset,

now a simple:

Offset(156,93).

I tried a few permutations and it worked spot on (Windows 10 Sikulix vanilla install - no other Python and no environment settings).

For the record:

1) if no rectangle is selected then nothing is entered into the statement text (rather than eg Offset(0,0)
2) if you drag onto another screen the following is output:

Exception in thread "AWT-EventQueue-0" java.awt.image.RasterFormatException: (x + width) is outside raster
at sun.awt.image.IntegerInterleavedRaster.createWritableChild(Unknown Source)
at java.awt.image.BufferedImage.getSubimage(Unknown Source)
at org.sikuli.util.OverlayCapturePrompt.drawSelection(OverlayCapturePrompt.java:334)
at org.sikuli.util.OverlayCapturePrompt.paint(OverlayCapturePrompt.java:384)
at javax.swing.RepaintManager$4.run(Unknown Source)
at javax.swing.RepaintManager$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$1200(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at j

ava.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

[error] OverlayCapturePrompt: cropSelection: RasterFormatException

Many thanks - I think this will be very useful.

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

Yes, both observations already materialised in my mind, while being busy with other things than SikuliX ;-)

Will check and repair asap.
Thanks.

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

at 1: by intention (what other makes sense?)

at 2: I cannot test multi monitor situations currently. But I will setup a bug.

Could you please check, what happens, if you do that with the normal capture or the selectRegion button?

Revision history for this message
Mike (maestro+++) said :
#14

If I start a region capture on Screen(0) and drag the mouse onto Screen(1) I get:

Exception in thread "AWT-EventQueue-0" java.awt.image.RasterFormatException: (x + width) is outside raster
at sun.awt.image.IntegerInterleavedRaster.createWritableChild(Unknown Source)
at java.awt.image.BufferedImage.getSubimage(Unknown Source)
at org.sikuli.util.OverlayCapturePrompt.drawSelection(OverlayCapturePrompt.java:334)
at org.sikuli.util.OverlayCapturePrompt.paint(OverlayCapturePrompt.java:384)
at javax.swing.RepaintManager$4.run(Unknown Source)
at javax.swing.RepaintManager$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$1200(Unknown Source)

at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at j

ava.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Exception in thread "AWT-EventQueue-0" java.awt.image.RasterFormatException: (x + width) is outside raster
at sun.awt.image.IntegerInterleavedRaster.createWritableChild(Unknown Source)
at java.awt.image.BufferedImage.getSubimage(Unknown Source)
at org.sikuli.util.OverlayCapturePrompt.drawSelection(OverlayCapturePrompt.java:334)
at org.sikuli.util.OverlayCapturePrompt.paint(OverlayCapturePrompt.java:384)
at javax.swing.RepaintManager$4.run(Unknown Source)
at javax.swing.RepaintManager$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$1200(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at j

ava.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.awt.image.RasterFormatException: (x + width) is outside raster
at sun.awt.image.IntegerInterleavedRaster.cr

eateWritableChild(Unknown Source)
at java.awt.image.BufferedImage.getSubimage(Unknown Source)
at org.sikuli.util.OverlayCapturePrompt.drawSelection(OverlayCapturePrompt.java:334)
at org.sikuli.util.OverlayCapturePrompt.paint(OverlayCapturePrompt.java:384)
at javax.swing.RepaintManager$4.run(Unknown Source)
at javax.swing.RepaintManager$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$1200(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unk

nown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

[error] OverlayCapturePrompt: cropSelection: RasterFormatException

If I start a take screenshot on Screen(0) and drag the mouse onto Screen(1) I get:

Exception in thread "AWT-EventQueue-0" java.awt.image.RasterFormatException: (x + width) is outside raster
at sun.awt.image.IntegerInterleavedRaster.createWritableChild(Unknown Source)
at java.awt.image.BufferedImage.getSubimage(Unknown Source)
at org.sikuli.util.OverlayCapturePrompt.drawSelection(OverlayCapturePrompt.java:334)
at org.sikuli.util.OverlayCapturePrompt.paint(OverlayCapturePrompt.java:384)
at javax.swing.RepaintManager$4.run(Unknown Source)
at javax.swing.RepaintManager$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$1200(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at j

ava.awt.event.InvocationEvent.dispatch(Unknown Source)

at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.awt.image.RasterFormatException: (x + width) is outside raster
at sun.awt.image.IntegerInterleavedRaster.createWritableChild(Unknown Source)
at java.awt.image.Bu

fferedImage.getSubimage(Unknown Source)
at org.sikuli.util.OverlayCapturePrompt.drawSelection(OverlayCapturePrompt.java:334)
at org.sikuli.util.OverlayCapturePrompt.paint(OverlayCapturePrompt.java:384)
at javax.swing.RepaintManager$4.run(Unknown Source)
at javax.swing.RepaintManager$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$1200(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Sour

[error] OverlayCapturePrompt: cropSelection: RasterFormatException

ce)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

With regard to 1): I agree

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

thanks for testing.

please see related bug.