Skip to content

[MNT]: Generalize widget mouse testing #22720

Closed

Description

@andrew-fennell

Summary

Mouse testing for RangeSlider widget is not supported in the current widget testing framework. The current mouse testing for widgets is done using the click_and_drag function, but it has no support for widgets without 'press' events.

Proposed fix

The click_and_drag function should be generalized in order to support more widgets. One solution would be adding support for sending events through the canvas.

This potential solution is mentioned here by @ianhi:
#22711 (comment)

Activity

  1. andrew-fennell commented on Mar 28, 2022

    @andrew-fennell
    ContributorAuthor

    The click_and_drag function:

    def click_and_drag(tool, start, end, key=None):

    The click_and_drag function is currently moving the mouse with these function calls:

    do_event(tool, 'press', xdata=start[0], ydata=start[1], button=1)
    do_event(tool, 'onmove', xdata=end[0], ydata=end[1], button=1)
    do_event(tool, 'release', xdata=end[0], ydata=end[1], button=1)

    This is where the current tests will break when using a RangeSlider widget because there is no 'press' event.

    func = getattr(tool, etype)

    The click events are defined in SliderBase:

    self.connect_event("button_press_event", self._update)
    self.connect_event("button_release_event", self._update)
    if dragging:
    self.connect_event("motion_notify_event", self._update)
    self._observers = cbook.CallbackRegistry(signals=["changed"])

  2. ianhi commented on Mar 28, 2022

    @ianhi
    Contributor

    I think the core issue is that do_event calls methods on the widget rather than actually processing events through the canvas.

    So changing:

    event = mock_event(tool.ax, button, xdata, ydata, key, step)
    func = getattr(tool, etype)
    func(event)

    to be something like

    def do_event(ax,...):
        event = mock_event(ax, button, xdata, ydata, key, step)
        ax.figure.canvas.callbacks.process(etype, event)

    would more completely exercise the events mechanism and be more general

  3. added this to the v3.11.0 milestone on Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions