Skip to content

Commit

Permalink
Enrich Click and ClickInput methods for Toolbar buttons.
Browse files Browse the repository at this point in the history
  • Loading branch information
vasily-v-ryabov committed Apr 15, 2015
1 parent 1efd952 commit ae32d13
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
27 changes: 21 additions & 6 deletions pywinauto/controls/HwndWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def VerifyVisible(self):

#-----------------------------------------------------------
def Click(
self, button = "left", pressed = "", coords = (0, 0), double = False, timeout=0.5):
self, button = "left", pressed = "", coords = (0, 0), double = False, timeout=0.5, absolute = False):
"""Simulates a mouse click on the control
This method sends WM_* messages to the control, to do a more
Expand All @@ -813,7 +813,7 @@ def Click(

if timeout:
time.sleep(timeout)
_perform_click(self, button, pressed, coords, double)
_perform_click(self, button, pressed, coords, double, absolute=absolute)
return self


Expand Down Expand Up @@ -1679,7 +1679,7 @@ def _perform_click_input(
ctrl_text = ctrl.WindowText()

if isinstance(coords, win32structures.RECT):
coords = (coords.left, coords.top)
coords = [coords.left, coords.top]

# # allow points objects to be passed as the coords
if isinstance(coords, win32structures.POINT):
Expand Down Expand Up @@ -1772,14 +1772,29 @@ def _perform_click(
coords = (0, 0),
double = False,
button_down = True,
button_up = True):
button_up = True,
absolute = False,
):
"Low level method for performing click operations"

ctrl.VerifyActionable()
ctrl_text = ctrl.WindowText()

if isinstance(coords, win32structures.RECT):
coords = (coords.left, coords.top)
coords = [coords.left, coords.top]
# allow points objects to be passed as the coords
if isinstance(coords, win32structures.POINT):
coords = [coords.x, coords.y]
#else:
coords = list(coords)

if not absolute:
screen_coords = win32structures.POINT()
screen_coords.x = coords[0]
screen_coords.y = coords[1]
ctrl.ClientToScreen(screen_coords)
coords[0] = screen_coords.x
coords[1] = screen_coords.y

# figure out the messages for click/press
msgs = []
Expand Down Expand Up @@ -1832,7 +1847,7 @@ def _perform_click(

# send each message
for msg in msgs:
ctrl.PostMessage(msg, flags, click_point)
win32functions.PostMessage(ctrl, msg, win32structures.WPARAM(flags), win32structures.LPARAM(click_point))
#ctrl.PostMessage(msg, flags, click_point)
#flags = 0

Expand Down
19 changes: 11 additions & 8 deletions pywinauto/controls/common_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,14 +624,15 @@ def Click(self, button = "left", double = False, where = "text", pressed = ""):
button,
coords = (point_to_click.x, point_to_click.y),
double = double,
pressed = pressed)
pressed = pressed,
absolute = absolute)

# if we use click instead of clickInput - then we need to tell the
# treeview to update itself
#self.tree_ctrl.

#----------------------------------------------------------------
def ClickInput(self, button = "left", double = False, where = "text", pressed = ""):
def ClickInput(self, button = "left", double = False, wheel_dist = 0, where = "text", pressed = ""):
"""Click on the treeview item
where can be any one of "text", "icon", "button", "check"
Expand Down Expand Up @@ -682,6 +683,7 @@ def ClickInput(self, button = "left", double = False, where = "text", pressed =
button,
coords = (point_to_click.x, point_to_click.y),
double = double,
wheel_dist = wheel_dist,
pressed = pressed)

#----------------------------------------------------------------
Expand Down Expand Up @@ -1782,15 +1784,16 @@ def IsEnabled(self):
return self.State() & win32defines.TBSTATE_ENABLED

#----------------------------------------------------------------
def Click(self):
"Left click on the Toolbar button"
self.toolbar_ctrl.Click(button='left', coords = self.Rectangle())
def Click(self, button = "left", pressed = ""):
"Click on the Toolbar button"
self.toolbar_ctrl.Click(button=button, coords = self.Rectangle(), pressed=pressed)
time.sleep(Timings.after_toobarpressbutton_wait)

#----------------------------------------------------------------
def ClickInput(self, double = False):
"Left click on the Toolbar button"
self.toolbar_ctrl.ClickInput(button='left', coords = self.Rectangle().mid_point(), double=double)
def ClickInput(self, button = "left", double = False, wheel_dist = 0, pressed = ""):
"Click on the Toolbar button"
self.toolbar_ctrl.ClickInput(button=button, coords = self.Rectangle().mid_point(),
double=double, wheel_dist=wheel_dist, pressed=pressed)
time.sleep(Timings.after_toobarpressbutton_wait)

#====================================================================
Expand Down

0 comments on commit ae32d13

Please sign in to comment.