<jupyter_start><jupyter_text>Mouse and Keyboard Eventsipyevents documentation: https://github.com/mwcraig/ipyevents/blob/master/doc/Widget%20DOM%20Events.ipynbEvent handling is not yet incorported into the image widget class.  This is a work in progress.<jupyter_code>import pathlib
import time

import numpy as np
import ipywidgets
import IPython
import image_attendant as ia

import ipyevents
import numpy_image_widget as niw<jupyter_output><empty_output><jupyter_text>Load image data<jupyter_code>folder = pathlib.Path('./images/').resolve()
files = list(folder.glob('*_small.jpg'))
files = sorted(files)
files = files + files[::-1]

images = []
for f in files:

    images.append(ia.read(f))<jupyter_output><empty_output><jupyter_text>Display<jupyter_code>wid_img = niw.NumpyImage(images[0])

wid_lab = ipywidgets.Text(description='info:')

wid_box = ipywidgets.VBox(children=[wid_img, wid_lab])

wid_box<jupyter_output><empty_output><jupyter_text>Event Handler<jupyter_code>def handle(ev):
    xy = ev['arrayX'], ev['arrayY'], ev['type']
    wid_lab.value = str(xy)
    
events = ipyevents.Event(source=wid_img, 
                         prevent_default_action=True,
                         watched_events=['click', 'contextmenu', 'mousemove'])

events.on_dom_event(handle)

_no_drag = ipyevents.Event(source=wid_img, watched_events=['dragstart'], prevent_default_action=True)
events.supported_key_events
events.supported_mouse_events<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11768707482993197, 'fraction_numerical': 0.004081632653061225, 'mean_word_length': 6.004761904761905, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '145489', 'license': 'MIT', 'n_tokens_mistral': 514, 'n_tokens_neox': 500, 'n_words': 87, 'path': 'notebooks/02 - events.ipynb', 'repo_name': 'Who8MyLunch/Numpy_Image_Widget', 'size': '1470'}