Skip to content

Commit

Permalink
fix drag_mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrPanov committed Jun 7, 2020
1 parent c79f76a commit 86f6042
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pywinauto/base_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,8 @@ def move_mouse_input(self, coords=(0, 0), pressed="", absolute=True, duration=0.

if not isinstance(duration, float):
raise TypeError("duration must be float (in seconds)")
if not absolute:
coords = self.client_to_screen(coords) # make coords absolute
minimum_duration = 0.05
if duration >= minimum_duration:
x_start, y_start = _get_cursor_pos()
Expand All @@ -733,9 +735,9 @@ def move_mouse_input(self, coords=(0, 0), pressed="", absolute=True, duration=0.
for step in range(num_steps):
self.click_input(button='move',
coords=(x_start + int(delta_x * step), y_start + int(delta_y * step)),
absolute=absolute, pressed=pressed, fast_move=True)
absolute=True, pressed=pressed, fast_move=True)
sleep(sleep_amount)
self.click_input(button='move', coords=coords, absolute=absolute, pressed=pressed)
self.click_input(button='move', coords=coords, absolute=True, pressed=pressed)

self.wait_for_idle()
return self
Expand Down
4 changes: 4 additions & 0 deletions pywinauto/controls/win_base_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,15 @@ def drag_mouse_input(self,

self.press_mouse_input(button, press_coords, pressed, absolute=absolute)
time.sleep(Timings.before_drag_wait)
for i in range(5):
self.move_mouse_input((press_coords[0] + i, press_coords[1]), pressed=pressed, absolute=absolute) # "left"
time.sleep(Timings.drag_n_drop_move_mouse_wait)

self.move_mouse_input(release_coords, pressed=pressed, absolute=absolute, duration=duration)

self.move_mouse_input(release_coords, pressed=pressed, absolute=absolute) # "left"
time.sleep(Timings.before_drop_wait)

self.release_mouse_input(button, release_coords, pressed, absolute=absolute)
time.sleep(Timings.after_drag_n_drop_wait)
return self
Expand Down
4 changes: 2 additions & 2 deletions pywinauto/mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

if sys.platform == 'win32':

def _get_cursor_pos():
def _get_cursor_pos(): # get global coordinates
return win32api.GetCursorPos()

def _set_cursor_pos(coords):
Expand Down Expand Up @@ -198,7 +198,7 @@ def _perform_click_input(
_display = Display()

# TODO: check this method
def _get_cursor_pos():
def _get_cursor_pos(): # get global coordinate
data = _display.screen().root.query_pointer()._data
return data["root_x"], data["root_y"]

Expand Down

0 comments on commit 86f6042

Please sign in to comment.