← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #186195]: Using text() to get text in dragDrog area

 

Question #186195 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/186195

    Status: Open => Answered

RaiMan proposed the following answer:
--- I am sorry to use wrong way in asking question
Never ever be sorry about wrong ways to ask questions. It is my responsibility, to clarify things and ask back if I think things are not clear enough to really help someone.

--- May I know is there any way to make dragDrog be set as a Region directly?
dragDrop() currently does not return a region, since it is a mouse action, that does not really know about an appropriate area.
If I understand right, you are using dragDrop to select some text on the screen, that is the copied to the clipboard using ctrl-c.
If this is right, than it is a rather complex coding to get an appropriate region for the usage with the text() feature.
But you might put it in def(), so it can be used throughout the script as a one liner.

e.g. an idea for a helper function
# based on dragDrop(pic1, pic2)
# supposing dragging goes to the right
def dragDropRegion(pic1, pic2, reg = SCREEN):
    m1 = reg.find(pic1)
    m2 = Region(m1.nearby().right()).find(pic2)
    x = m1.x + m1.w
    y = min(m1.y, m2.y)
    w = m2.x - x
    h = min(m1.h, m2.h)
    return Region(x, y, w, h)

# usage (pic1 searched on whole screen)
txt = dragDropRegion(pic1, pic2).text()

# or (pic1 searched in a restricted region)
txt = dragDropRegion(pic1, pic2, some_region_evaluated_before).text()

--- comments
- before investing in this approach, you should check, wether Region.text() works with your text (see bug )
- there might be a need to optimize the region calculation, to assure, that only text is inside the target region. A way might be to be careful with capturing pic1 and pic2.Another possibility: say, the optimal text region height is 20 pixel, the you might adjust your def accordingly based on the centers of the 2 matches.

Come back if you decide for this way and need more help.

--- But it sometimes encounters I/O error for Env.getClipboard 
Might be a timing problem (clipboard not yet ready after the type()).
Try to add a wait(1) (or some lower time value that might be sufficient)
type("c",KEY_CTRL); wait(1); txt = Env.getClipboard()

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.