[1.0.1] Allow click() to accept and ignore 'None' as a modifier --- fixed 2015-05-02+

Bug #1450805 reported by Ryan
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SikuliX
Fix Committed
Critical
RaiMan

Bug Description

Currently the click() method accepts key modifiers as optional arguments. We have created a wrapper function on the click to ensure a little extra stability with the click method and have it available across all scripts.
ex:

def myClickFun(region, image, modifier=None):
    # Do some things for stability
    region.click(image, modifier)

We ran into an issue when we needed to introduce the key modifier argument. If we provide the modifier it works as expected, however this breaks all other instances where no modifier is provided giving the following error:

TypeError: click(): 2nd arg can't be coerced to int

I was expecting the None to be ignored since that is usually the default behavior of an optional argument. Then I remembered that you can supply an integer with the click() method (A quick test revealed that no integer and a value of 60 timed out at about the same time). It seems that the click method could accept keyword arguments (and ignore none as a modifier) to allow for greater flexibility in the method call. Maybe just a single keyword for the modifier in case an integer is not supplied?

I realize the great chance that I'm doing something wrong here... if so please let me know.

RaiMan (raimund-hocke)
summary: - Allow click() to accept and ignore 'None' as a modifier
+ [1.0.1] Allow click() to accept and ignore 'None' as a modifier ---
+ fixed 2015-05-02+
Changed in sikuli:
status: New → Fix Committed
importance: Undecided → Critical
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → 1.1.0
Revision history for this message
RaiMan (raimund-hocke) wrote :

good point, since the modifiers in future (already available with type()) should be strings anyway.
So I just changed the API at the Java level from int to Integer, which now allows to use None at the script level.

BTW:
--- since that is usually the default behavior of an optional argument
... might be true for the Jython scripting level, but since the Region API is completely implemented at the Java level, this is not really true here (Java does not have keyword nor optional args yet.

--- since you have a wrapper anyway, this would have been your private solution ;-)

def myClickFun(region, image, modifier=None):
    # Do some things for stability
    region.click(image, modifier ? modifier : 0)

Revision history for this message
Ryan (ryan-pisano) wrote :

That makes sense, I didn't think about how that would look in Java, though I did initially check to see if any of the click() code was in Jython.

I was hesitant to split the call with an if statement (if modifier or not) since the logic is more complex than my trivial example, and the click is part of an if statement. I overlooked assigning the result of the click to a variable and splitting out the assignment calls based on the modifier parameter.

Thanks!

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.