How to draw a circle or some shape using sikuli?

Asked by balakrishnan

Dear Sir,

I started to use sikuli for automation.I am really satisfied with the sikuli.
I need to draw a circle , ellipsoid or some image using mouse. I dont know how to do this .

Please provide me the sample code. it will be really useful to us.

Thanks
Balakrishnan.A.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
TestMechanic
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
RaiMan (raimund-hocke) said :
#1

Sikuli itself has no support for drawing something on the screen.

Have a look at the guide extension (see https://answers.launchpad.net/sikuli/+question/171313).

Revision history for this message
RaiMan (raimund-hocke) said :
#2

Forgot to mention Region.highlight() (see docs), which might already be sufficient for your purposes.

Revision history for this message
balakrishnan (abkblr) said :
#3

Thanks Raiman.

If possible can you tell me how Region.highlight() might be useful .I have read the doc but i could not understand.
I know i am troubling you a lot. But i dont have other alternative.

If possible provide some sample code.

Revision history for this message
RaiMan (raimund-hocke) said :
#4

m = find("some-image.png") # get the match Region
a = Region(m).nearby(10) # leave a margin of 10 pixel around
a.highlight(2) # shows a red frame for 2 seconds

you might even use
a.highlight() # switches frame on
# do something else, while frame stays present
a.highlight() # switches frame off again

Revision history for this message
TestMechanic (ndinev) said :
#5

Below is some sample code to draw rectangle and triangle in paint
Hope this help.

--------------------------------------------------------------------

start_point= "start_point.png"

def drawRect():
    mLoc=Env.getMouseLocation().offset(100,100)
    mouseMove(mLoc)
    mouseDown(Button.LEFT)
    mouseMove(mLoc.offset(200,0))
    mouseMove(mLoc.offset(200,100))
    mouseMove(mLoc.offset(0,100))
    mouseMove(mLoc.offset(0,0))
    mouseUp()

def drawTriang():
    mLoc=Env.getMouseLocation().offset(300,300)
    mouseMove(mLoc)
    mouseDown(Button.LEFT)
    mouseMove(mLoc.offset(200,0))
    mouseMove(mLoc.offset(100,100))
    mouseMove(mLoc.offset(0,0))
    mouseUp()

sleep(1)
switchApp("Paint")
mouseMove(start_point)
drawTriang()
mouseMove(start_point)
drawRect()

Revision history for this message
balakrishnan (abkblr) said :
#6

Thanks Dinev , thats solved my problem . It was really useful ....Thanks a lot....Great work !!!!!!

Revision history for this message
TestMechanic (ndinev) said :
#7

Just for fun I done the circle thing :-)
Here it is(add this function to the above test):

----------------------------------------------------------
def drawCircle():
    mLoc=Env.getMouseLocation().offset(250,250)
    radius=100
    for i in range(37):
        degInRad = i*math.pi/18
        pointX=int(math.cos(degInRad)*radius)
        pointY=int(math.sin(degInRad)*radius)
        mouseMove(mLoc.offset(pointX,pointY))
        if i==0: mouseDown(Button.LEFT)
    mouseUp()

Revision history for this message
balakrishnan (abkblr) said :
#8

It gives an error message as " File "C:\DOCUME~1\OMSRIR~1\LOCALS~1\Temp\sikuli-tmp6127344632977781805.py", line 23, in drawCircle
 degInRad = i*math.pi/18
NameError: global name 'math' is not defined"

Revision history for this message
TestMechanic (ndinev) said :
#9

add "import math" on top of your script

Revision history for this message
balakrishnan (abkblr) said :
#10

Hi i have tried this code ...There will be mouse movements however it is not writing anything for circle.

Revision history for this message
Best TestMechanic (ndinev) said :
#11

Did you run successfully the first example? You need paint open.
Here is the video of the working script: http://screencast.com/t/39GPFv1ILTvw
Here is the full script(triangle and rectangle draw are commented):
-------------------------------------------
import math

start_point= "start_point-1.png"

def drawRect():
    mLoc=Env.getMouseLocation().offset(100,100)
    mouseMove(mLoc)
    mouseDown(Button.LEFT)
    mouseMove(mLoc.offset(200,0))
    mouseMove(mLoc.offset(200,100))
    mouseMove(mLoc.offset(0,100))
    mouseMove(mLoc.offset(0,0))
    mouseUp()

def drawTriang():
    mLoc=Env.getMouseLocation().offset(300,300)
    mouseMove(mLoc)
    mouseDown(Button.LEFT)
    mouseMove(mLoc.offset(200,0))
    mouseMove(mLoc.offset(100,100))
    mouseMove(mLoc.offset(0,0))
    mouseUp()

def drawCircle():
    mLoc=Env.getMouseLocation().offset(250,250)
    radius=100
    for i in range(37):
        degInRad = i*math.pi/18
        pointX=int(math.cos(degInRad)*radius)
        pointY=int(math.sin(degInRad)*radius)
        mouseMove(mLoc.offset(pointX,pointY))
        if i==0: mouseDown(Button.LEFT)
    mouseUp()

sleep(1)
switchApp("Paint")
mouseMove(start_point)
#drawTriang()
#mouseMove(start_point)
#drawRect()
drawCircle()

Revision history for this message
balakrishnan (abkblr) said :
#12

Thanks This solved my question