These are my notes from the sprint Saturday night:
# Define a callback that shows the output of a print
out = ipyw.Output()
def show_event(viewer, event, datax, datay):
with out:
# print(dir(event))
print(event.data_x, event.data_y)
display(out)
# This would work for adding markers with the appropriate callback
gvc = w._viewer.get_canvas()
gvc.add_callback('cursor-down', show_event)
# Changing binds for pan/zoom
bind_map = w._viewer.get_bindmap()
# ms is click-drag
# kp is keypress
# sc is scroll
# map_event args: mode, modifiers (usually empty), trigger, event_name (last two as strings)
bind_map.map_event(None, (), 'ms_left', 'pan')
# contrast with right mouse
bind_map.map_event(None, (), 'ms_right', 'contrast')
# zoom by scrolling
bind_map.map_event(None, (), 'pa_pan', 'zoom')
# pan by scrolling
bind_map.map_event(None, (), 'pa_pan', 'pan')
# restore contrast with ctrl-right-click... NOTE TUPLE FOR MODIFIER
bind_map.map_event(None, ('ctrl',), 'ms_right', 'contrast_restore')
# click to center
bind_map.map_event(None, ('shift',), 'ms_left', 'panset')
# to bind a custom event to a function of your choosing
bind_map.map_event(None, (), 'kp_w', 'my_custom_event')
# Signature of callback_function is
def callback_function(viewer, event, data_x, data_y, *args):
with out:
print('The magic key was pressed')
pass
# prefix for keypress is keydown-
# suffix for ms_... is -down
# suffix for sc_... is -scroll
w._viewer.set_callback('keydown-my_custom_event', callback_function)
These are my notes from the sprint Saturday night: