Passing a Region as a arguement

Asked by William Elmer

I would like to pass a region in order to verify some data.
An example might be:
Value = f.readline().strip() #read in from data file.
def MyTest(Region, value) #my function.
if exists(Region.inside(value)) # If my value read in from my data file exists in the region found through OCR then test passed
Test = "passed" #write this to log file.
else
Test = Region.Text() #else log what we found instead

#end function here

MyTest(RegionScreenShot, Value)

Is this possible within the Sikuli IDE. I have tried the above code and it did not work. So maybe I have to assign a region to a variable first?

I am Raimans #1 fan by the way :P

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
William Elmer
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Hi, fan #1 ;-)

Don't know if it is a typo: mind indentation !
Do not use Region as variable name!
We are talking Python!
to avoid clashes: start variable names with lower case letters!

def myTest(reg, value):
    if reg.exists(value):
        test = "passed"
    else:
        test = reg.text()
    return test
#end function here

val = f.readline().strip()

print val, myTest(someRegion, val)

Revision history for this message
William Elmer (william-elmer) said :
#2

Yes, But Tabing does not work via these question posts. Just tabs out of the textbox control :$

So in lamens terms, To let a function know I want to use a region as an arguement, syntactically I use the keyword reg? or is that just a variable name your defining? Im still new to python coding(c# fan boy here :P) and very new to sikuli coding.

But the exact way I would do it would be

def myTest(reg, value): ?

Also another question, I understand that python is not a strongly typed language, So if I push something through to test whether or not it is a matching region and if not a region do math is that possible?

ex:

def myTest(reg, value):
if reg==screenshot
else
#add value to region each region coords.

Revision history for this message
j (j-the-k) said :
#3

You don't need any keyword, because Python does not require typedefinitions like e.g. c# does.
All you need is a name, and Python will determine its type when it is used at runtime.
So "reg" and "value" are just variable names that could contain any kind of object.

You could check if a variable has a certain type e.g. by using
if (instance(reg, Region)):
    #do sth. with region
else:
    # do sth else

But normally you should know which type of variable you're going to get.

So if you write
def myTest(reg, value):
the only thing "Python knows" it that there are two objects which can be anything.
If you now use
reg.exists(value)
Python will look up if the reg-object has a method with the name "exists" that takes one parameter, it doesn't care about the type of reg, only about the methods it has.

Revision history for this message
William Elmer (william-elmer) said :
#4

Ah. That makes sense. Ok

Thanks J!

Unfortunately I am Still Raimans Number one fan :P
But thanks for all the help!!!