Current summary of the mixin
(Note that this mixin is for now just private code, but can be added
to a branch obviously)
InteractiveArtistMixin:
Mixin class to make any generic object that is drawn on a matplotlib
canvas moveable and possibly resizeable. The Powerpoint model is
followed as closely as possible; not because I'm enamoured with
Powerpoint, but because that's what most people understand. An artist
can also be selectable, which means that the artist will receive the
on_activated() callback when double clicked. Finally, an artist can
be highlightable, which means that a highlight is drawn on the artist
whenever the mouse passes over. Typically, highlightable artists will
also be selectable, but that is left up to the user. So, basically
there are four attributes that can be set by the user on a per-artist
basis:
highlightable
selectable
moveable
resizeable
To be moveable (draggable) or resizeable, the object that is the
target of the mixin must support the following protocols:
get_pixel_position_ll(self)
get_pixel_size(self)
set_pixel_position_and_size(self,x,y,sx,sy)
Note that nonresizeable objects are free to ignore the sx and sy
parameters. To be highlightable, the object that is the target of the
mixin must also support the following protocol:
Which returns a list of artists that will be used to draw the highlight.
If the object that is the target of the mixin is not an matplotlib
artist, the following protocols must also be implemented. Doing so is
usually fairly trivial, as there has to be an artist somewhere that
is being drawn. Typically your object would just route these calls to
that artist.
get_figure(self)
get_axes(self)
contains(self,event)
set_animated(self,flag)
draw(self,renderer)
get_visible(self)
The following notifications are called on the artist, and the artist
can optionally implement these.
on_select_begin(self)
on_select_end(self)
on_drag_begin(self)
on_drag_end(self)
on_activated(self)
on_highlight(self)
on_right_click(self,event)
on_left_click(self,event)
on_middle_click(self,event)
on_context_click(self,event)
on_key_up(self,event)
on_key_down(self,event)
The following notifications are called on the canvas, if no
interactive artist handles the event:
on_press(self,event)
on_left_click(self,event)
on_middle_click(self,event)
on_right_click(self,event)
on_context_click(self,event)
on_key_up(self,event)
on_key_down(self,event)
The following functions, if present, can be used to modify the
behavior of the interactive object:
press_filter(self,event) # determines if the object wants to have
the press event routed to it
handle_unpicked_cursor() # can be used by the object to set a cursor
as the cursor passes over the object when it is unpicked.
Supports multiple canvases, maintaining a drag lock, motion notifier,
and a global "enabled" flag per canvas. Supports fixed aspect ratio
resizings by holding the shift key during the resize.
Known problems:
Zorder is not obeyed during the selection/drag operations. Because
of the blit technique used, I do not believe this can be fixed. The
only way I can think of is to search for all artists that have a
zorder greater then me, set them all to animated, and then redraw
them all on top during each drag refresh. This might be very slow;
need to try.
the mixin only works for wx backends because of two things: 1) the
cursors are hardcoded, and 2) there is a call to
wx.GetMousePosition() Both of these shortcomings are reasonably
fixed by having each backend supply these things.