X-1.0rc3: Region.onChange(handler, Integer) should give an error, instead of silently ignoring the Integer
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SikuliX |
Fix Released
|
Critical
|
RaiMan |
Bug Description
***** problem
using onChange(handler, integer) seems to work, but it is a wrong usage according to the API docs. In fact the second parameter is simply ignored in this case.
This usage should give an error.
-------
The other observations here are due to the fact, that in some cases, a Match object does not work like a Region, which is a known problem.
*** workaround
cast the Match to a Region:
matchRegion = Region(some_match)
-------
Problem: The Match.onChange() method does not reflect the same behavior as Region.onChange()
--
from sikuli.Sikuli import Match
def test(event):
print event
region = Match(100,
region.
region.observe()
####
Traceback (most recent call last):
File "C:\work\
region.
TypeError: onChange(): 1st arg can't be coerced to int
---
Swapping, onChange arguments as follows:
region.onChange(50, test)
####
Traceback (most recent call last):
File "C:\work\
region.
TypeError: onChange(): 2nd arg can't be coerced to org.sikuli.
--
However, the following code does work:
--
from sikuli.Sikuli import Region
def test(event):
print event
region = Region(
region.
region.observe()
####
ChangeEvent on Region[100,100 200x200]@Screen(0) E:Y, T:3.0 | 1 changes
ChangeEvent on Region[100,100 200x200]@Screen(0) E:Y, T:3.0 | 1 changes
---
However this does not reflect the documentation which states the minChangedSize as the 1st argument and the handler as the 2nd argument. In reality it is flipped around.
http://
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
summary: |
- Region.onChange(handler, Integer) should give an error, instead of - silently ignoring the Integer + X-1.0rc3: Region.onChange(handler, Integer) should give an error, + instead of silently ignoring the Integer |
Changed in sikuli: | |
status: | New → Fix Committed |
assignee: | nobody → RaiMan (raimund-hocke) |
milestone: | none → x1.0 |
tags: | added: fkt-observe |
Changed in sikuli: | |
importance: | Undecided → Critical |
Changed in sikuli: | |
status: | Fix Committed → Fix Released |
--- from sikuli.Sikuli import Match/Region
does not make sense, because all classes needed by Sikuli are internally imported, when running a Sikuli script with the means of Sikuli
--- region = Match(100, 100,200, 200, 2.5) 100,100, 200,200)
does not make sense, because it is simply a region and setting a similarity value for a region does not make sense either. So in this case it would be better to say:
region = Region(
The only thing that might make sense, if you want to duplicate an existing match, because you want to have different target offsets: image.png" )
m1 = find("some-
m2 = Match(m1)
now you have two different match objects.
--- region. onChange( test, 50) works onChange( test)
yes it works (and this is a bug), but it simply ignores the 50 in this case (or whatever the second parameter contains). So it is the same as:
region.
--- documentation bug - no!
the documentation reflects exactly how it should be:
if there are two parameters, then the first one has to be an integer and the second one is taken as the handler. All other combinations of two parameters are wrong and should lead to an error.
--- Match does not behave like a Region
Yes, there are still some problems with the Region behavior of Match objects in some cases (observe is one of them). This is a known problem (a Region class exists on both levels Jython and Java, which mixes things up in some cases) with an easy workaround: cast the Match to a Region and it works as expected:
m1 = Region( find("some- image.png" ))
m1.onChange(50, handler)
--- so what's left
I will reduce your bug report to the fact, that onChange(test, 50) should give an error instead of silently ignoring the second parameter.