← Back to team overview

sikuli-driver team mailing list archive

[Bug 1201927] [NEW] Extend region methods do not return a complete Region object

 

Public bug reported:

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>

** Affects: sikuli
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Sikuli
Drivers, which is subscribed to Sikuli.
https://bugs.launchpad.net/bugs/1201927

Title:
  Extend region methods do not return a complete Region object

Status in Sikuli:
  New

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>

To manage notifications about this bug go to:
https://bugs.launchpad.net/sikuli/+bug/1201927/+subscriptions


Follow ups

References