[check] Extend region methods do not return a complete Region object

Bug #1201927 reported by Brian Redmond
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SikuliX
In Progress
Medium
RaiMan

Bug Description

Sikuli 1.0.0 Win7-64

I have a number of methods that I have monkey patched on the Region and Match objects to extend the API in python and it generally works great. The one issue is that above(), below(), left(), right(), nearby() and offset() do not return a proper Region object. I think example code is the easiest way to explain, let me know if you have questions:

<pre>
# define function to be added to Region object as a new method
def monkey_patch(self):
    popup(str(self))
    return self

# Add the method to the Region object
Region.monkey_patch = monkey_patch

# Create a region object at the center of the screen
regionCenterScreen = Region(SCREEN.w/2, SCREEN.h/2, 5, 5)

# printing the class name shows that this is a Region object
print "regionCenterScreen: %s" % regionCenterScreen.__class__.__name__

# printing the class name of the object returned by the left method is also a Region so it should have the same methods and
# attributes as the original object
print "regionCenterScreen.left(5): %s" % regionCenterScreen.left(5).__class__.__name__

# print the difference between the method/attributes of the two objects
# This should be an empty set, but instead it's actually pretty long
print set(dir(regionCenterScreen)) - set(dir(regionCenterScreen.nearby(5)))

# This works
regionCenterScreen.monkey_patch()

# This throws AttributeError
regionCenterScreen.left(5).monkey_patch()

# This works
Region(regionCenterScreen.left(5)).monkey_patch()
</pre>

Tags: fkt-region
Revision history for this message
RaiMan (raimund-hocke) wrote :

This is a general known (admitted: ugly ;-) problem with the API implementation, which for Region is to 98% is on the Java level.

The only chance, tobe sure, to always get a Jython level region object returned is to cast:

jReg = Region(some_region_created_before)

I am working on a solution for version 1.1, that assures, that every Region created in a Jython environment is always a Jython level region object.

Changed in sikuli:
status: New → In Progress
importance: Undecided → High
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → 1.1.0
summary: - Extend region methods do not return a complete Region object
+ [1.0] Extend region methods do not return a complete Region object
RaiMan (raimund-hocke)
tags: added: fkt-region
RaiMan (raimund-hocke)
Changed in sikuli:
milestone: 1.1.0 → 1.2.0
RaiMan (raimund-hocke)
Changed in sikuli:
milestone: 2.0.0 → 2.1.0
importance: High → Medium
summary: - [1.0] Extend region methods do not return a complete Region object
+ [check] Extend region methods do not return a complete Region object
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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