MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _update

Method _update

lib/matplotlib/widgets.py:916–948  ·  view source on GitHub ↗

Update the slider position.

(self, event)

Source from the content-addressed store, hash-verified

914
915 @_call_with_reparented_event
916 def _update(self, event):
917 """Update the slider position."""
918 if self.ignore(event) or event.button != 1:
919 return
920
921 if event.name == "button_press_event" and self.ax.contains(event)[0]:
922 self.drag_active = True
923 event.canvas.grab_mouse(self.ax)
924
925 if not self.drag_active:
926 return
927
928 if (event.name == "button_release_event"
929 or event.name == "button_press_event" and not self.ax.contains(event)[0]):
930 self.drag_active = False
931 event.canvas.release_mouse(self.ax)
932 self._active_handle = None
933 return
934
935 # determine which handle was grabbed
936 handle_index = np.argmin(np.abs(
937 [h.get_xdata()[0] - event.xdata for h in self._handles]
938 if self.orientation == "horizontal" else
939 [h.get_ydata()[0] - event.ydata for h in self._handles]))
940 handle = self._handles[handle_index]
941
942 # these checks ensure smooth behavior if the handles swap which one
943 # has a higher value. i.e. if one is dragged over and past the other.
944 if handle is not self._active_handle:
945 self._active_handle = handle
946
947 self._update_val_from_pos(
948 event.xdata if self.orientation == "horizontal" else event.ydata)
949
950 def _format(self, val):
951 """Pretty-print *val*."""

Callers

nothing calls this directly

Calls 7

_update_val_from_posMethod · 0.95
grab_mouseMethod · 0.80
release_mouseMethod · 0.80
ignoreMethod · 0.45
containsMethod · 0.45
get_xdataMethod · 0.45
get_ydataMethod · 0.45

Tested by

no test coverage detected