Skip to content

Commit

Permalink
Add snippets/mouse_clicks.py (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
cztomczak committed Aug 19, 2018
1 parent 2b78a3e commit 5b51fc3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
46 changes: 46 additions & 0 deletions examples/snippets/mouse_clicks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Perform mouse clicks and mouse movements programmatically.

from cefpython3 import cefpython as cef


def main():
cef.Initialize()
browser = cef.CreateBrowserSync(
url="data:text/html,<h1>Mouse clicks snippet</h1>"
"This text will be selected after one second.<br>"
"This text will be selected after two seconds.",
window_title="Mouse clicks")
browser.SetClientHandler(LifespanHandler())
cef.MessageLoop()
del browser
cef.Shutdown()


def click_after_1_second(browser):
print("Click after 1 second")
browser.SendMouseMoveEvent(0, 70, False, 0)
browser.SendMouseClickEvent(0, 70, cef.MOUSEBUTTON_LEFT, False, 1)
browser.SendMouseMoveEvent(400, 80, False, cef.EVENTFLAG_LEFT_MOUSE_BUTTON)
browser.SendMouseClickEvent(400, 80, cef.MOUSEBUTTON_LEFT, True, 1)
cef.PostDelayedTask(cef.TID_UI, 1000, click_after_2_seconds, browser)


def click_after_2_seconds(browser):
print("Click after 2 seconds")
browser.SendMouseMoveEvent(0, 90, False, 0)
browser.SendMouseClickEvent(0, 90, cef.MOUSEBUTTON_LEFT, False, 1)
browser.SendMouseMoveEvent(400, 100, False, cef.EVENTFLAG_LEFT_MOUSE_BUTTON)
browser.SendMouseClickEvent(400, 100, cef.MOUSEBUTTON_LEFT, True, 1)
cef.PostDelayedTask(cef.TID_UI, 1000, click_after_1_second, browser)


class LifespanHandler(object):
def OnLoadEnd(self, browser, **_):
# Execute function with a delay of 1 second after page
# has completed loading.
print("Page completed loading")
cef.PostDelayedTask(cef.TID_UI, 1000, click_after_1_second, browser)


if __name__ == '__main__':
main()
6 changes: 4 additions & 2 deletions examples/snippets/network_cookies.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Implement RequestHandler.CanGetCookies and CanSetCookie
# to block or allow cookies over network requests.
"""
Implement RequestHandler.CanGetCookies and CanSetCookie
to block or allow cookies over network requests.
"""

from cefpython3 import cefpython as cef

Expand Down
6 changes: 4 additions & 2 deletions examples/snippets/onbeforeclose.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Implement LifespanHandler.OnBeforeClose to execute custom
# code before browser window closes.
"""
Implement LifespanHandler.OnBeforeClose to execute custom
code before browser window closes.
"""

from cefpython3 import cefpython as cef

Expand Down

0 comments on commit 5b51fc3

Please sign in to comment.