mwcraig / ipyevents

A custom widget for returning mouse and keyboard events to Python. Documentation:
https://ipyevents.readthedocs.io/en/latest/index.html
BSD 3-Clause "New" or "Revised" License
115 stars 27 forks source link

How to trigger an event? #73

Open itepifanio opened 2 years ago

itepifanio commented 2 years ago

Let's say we have the following code:

l = Label('Click or type on me!')
l.layout.border = '2px solid red'

h = HTML('Event info')
d = Event(source=l, watched_events=['click', 'keydown', 'mouseenter', 'touchmove'])

def handle_event(event):
    lines = ['{}: {}'.format(k, v) for k, v in event.items()]
    content = '<br>'.join(lines)
    h.value = content

d.on_dom_event(handle_event)

display(l, h)

For test purposes, I would like to trigger the d event by interacting with the label l. How could I do something similar to l.click()?

mwcraig commented 2 years ago

Thanks for the question -- I think the code you wrote should trigger the d event from the browesr when you click, but I gather you want to trigger the d event from python by calling something like l.click()?

Not sure off the top of my head but will look into it this morning.

itepifanio commented 2 years ago

I think the code you wrote should trigger the d event from the browesr when you click

Yes, it does.

but I gather you want to trigger the d event from python by calling something like l.click()

Exactly, it doesn't need to be click exactly, I just need to trigger the event somehow. This will help me to write some UI tests.

Thanks @mwcraig