Home > GSOC2015, kivy, matplotlib > Connecting events between kivy and matplotlib

Connecting events between kivy and matplotlib

Matplotlib provides a list of events that can be connected to an external backend. This list of events can be found in backend_bases.py, the events are:


events = [
'resize_event',
'draw_event',
'key_press_event',
'key_release_event',
'button_press_event',
'button_release_event',
'scroll_event',
'motion_notify_event',
'pick_event',
'idle_event',
'figure_enter_event',
'figure_leave_event',
'axes_enter_event',
'axes_leave_event',
'close_event'
]

In order to connect these events to kivy events, we first need to know the corresponding kivy events that can be match with the ones in the previous list:


widget_events = [

'on_touch_down',
'on_touch_up',

]

keyboard_events = [

'on_key_down',
'on_key_up',

]

window_events = [

'on_close',

]

attribute_events = [
'mouse_pos', #from Window
'size',

]

The definition for each mpl event and how it is connected to each kivy event will be explained below:

– ‘button_press_event’ :
On FigureCanvasKivy ‘on_touch_down’ will be triggered when a user touches the widget. A call to FigureCanvasBase will be performed on ‘button_press_event’ with the corresponding touch.x and touch.y arguments.

– ‘button_release_event’ :
On FigureCanvasKivy ‘on_touch_up’ will be triggered when a user release a touch. A call to FigureCanvasBase will be performed on ‘button_release_event’ with the corresponding touch.x and touch.y arguments.

– ‘draw_event’ :
Internally dispatched by matplotlib.

– ‘key_press_event’ :
On FigureCanvasKivy a keyboard will be requested and ‘on_key_down’ will be bound to an internal function ‘on_keyboard_down’. On this function a call to FigureCanvasBase will be performed on ‘key_press_event’ with the corresponding keycode argument.

– ‘key_release_event’ :
On FigureCanvasKivy a keyboard will be requested and ‘on_key_up’ will be bound to an internal function ‘on_keyboard_up’. On this function a call to FigureCanvasBase will be performed on ‘key_release_event’ with the corresponding keycode argument.

– ‘motion_notify_event’ :
I need to import Window and on FigureCanvasKivy will be bound ‘mouse_pos’ with an internal function ‘_on_mouse_move’. On this function a call to FigureCanvasBase will be performed on  ‘motion_notify_event’ with the corresponding position of the mouse in x and y coordinates.

– ‘pick_event’ :
Event dispatched by matplotlib internally called by Artist.

– ‘resize_event’ :
On FigureCanvasKivy will be bound ‘size’ with an internal function ‘_on_size_changed’. On this function a call to FigureCanvasBase will be performed on ‘resize_event’ with the corresponding arguments.

– ‘scroll_event’ :
On FigureCanvasKivy ‘on_touch_down’ will be triggered then on this event a call to FigureCanvasBase will be performed on ‘scroll_event’ with the values for touch (if touch.button is scrollup or scrolldown step would be possitive or negative accordingly).

– ‘figure_enter_event’ :
I need to import Window and on FigureCanvasKivy will be bound ‘mouse_pos’ with an internal function ‘_on_mouse_move’. On this function a call to FigureCanvasBase on ‘enter_notify_event’ will be performed (if the mouse position collides with the canvas) with the respective arguments.

– ‘figure_leave_event’ :
I need to import Window and on FigureCanvasKivy will be bound ‘mouse_pos’ with an internal function ‘_on_mouse_move’. On this function a call to FigureCanvasBase on ‘leave_notify_event’ will be performed (if the mouse position does not collides with the canvas and it was before) with the respective arguments.

– ‘axes_enter_event’ :
Event dispatched by matplotlib.

– ‘axes_leave_event’ :
Event dispatched by matplotlib.

– ‘close_event’ :
I need to import Window and on FigureCanvasKivy will be bound ‘window.on_close’ with an internal function ‘on_close’. On this function a call to FigureCanvasKivy on ‘close_event’ will be performed with the respective arguments.

This can be seen in my last commit on mpl_kivy branch –> https://github.com/andnovar/kivy/tree/mpl_kivy

Advertisements
Categories: GSOC2015, kivy, matplotlib Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: