Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to drag and drop an item? For eg an image on powerpoint slide #58

Closed
kensoh opened this issue Sep 17, 2019 · 5 comments
Closed

How to drag and drop an item? For eg an image on powerpoint slide #58

kensoh opened this issue Sep 17, 2019 · 5 comments
Labels

Comments

@kensoh
Copy link
Member

kensoh commented Sep 17, 2019

raising from user query in #57 (comment)

@kensoh kensoh added the query label Sep 17, 2019
@kensoh
Copy link
Member Author

kensoh commented Sep 17, 2019

There are usually various ways to get to the same outcome. Try to think of how something is done manually, and then map that series of actions to the UI interaction functions in this tool.

In this case, maybe doing a r.click('image.png') and then doing a r.keyboard('[left][left][left][left][left][left][left][left][left][left][left][left]') can give desired outcome.

Or maybe doing something below to drag and drop left by 100 pixels works?

r.click('image.png')
r.mouse('down')
r.hover(r.mouse_x() - 100, r.mouse_y())
r.mouse('up')

If above works but too many lines of code, you can write your own Python function to combine the above steps to do what you need, so that you only need to write 1 line to do this action.

@kensoh
Copy link
Member Author

kensoh commented Sep 18, 2019

Below is an example (for first action, hover will do) -

import rpa as r
r.init(True)

def dragdrop(element_identifier, x_offset, y_offset):
    r.hover(element_identifier)
    r.mouse('down')
    r.hover(r.mouse_x() + x_offset, r.mouse_y() + y_offset)
    r.mouse('up')

dragdrop('a.png', -200, 0)
r.close()

@kensoh
Copy link
Member Author

kensoh commented Sep 19, 2019

Closing issue for now as the implementation should be quite straight forward, the challenge is figuring out the step by step details how a human user manually do the sequence of actions to get it done. Then map to above type of Python code.

@kensoh kensoh closed this as completed Sep 19, 2019
@kensoh kensoh changed the title How to drag an item to the left? For eg an image on powerpoint slide How to drag and drop an item? For eg an image on powerpoint slide Jan 4, 2020
@kensoh
Copy link
Member Author

kensoh commented Jan 4, 2020

Adding on to above sample code which drags and drops by coordinates offset, below sample drags and drops from a source image identifier to a target image identifier using visual automation -

import rpa as r
r.init(True)

def dragdrop(source_identifier, target_identifier):
    r.hover(source_identifier)
    r.mouse('down')
    r.hover(target_identifier)
    r.mouse('up')

dragdrop('a.png', 'b.png')
r.close()

You can also create a function to drag and drop from the source to the target x,y coordinates -

import rpa as r
r.init(True)

def dragdrop(source_x, source_y, target_x, target_y):
    r.hover(source_x, source_y)
    r.mouse('down')
    r.hover(target_x, target_y)
    r.mouse('up')

dragdrop(200, 100, 600, 200)
r.close()

If you prefer to keep syntax consistent as r.dragdrop() you can define and map it as follows -

import rpa as r
r.init(True)

# define the dragdrop() function
def dragdrop(source_x, source_y, target_x, target_y):
    r.hover(source_x, source_y)
    r.mouse('down')
    r.hover(target_x, target_y)
    r.mouse('up')

# map the function to r object
r.dragdrop = dragdrop

# invoke using r.dragdrop()
r.dragdrop(200, 100, 600, 200)
r.close()

@kensoh
Copy link
Member Author

kensoh commented Jan 4, 2020

I'm leaving a dragdrop() or drag() function out from API because it may not be that commonly used and can clutter up the API which contains the essentials plus some pros functions. But if there are users interested and often use something like this I can add a new function into basic functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant