Add new on_drag_leave Enum trait to DragTool#712
Conversation
…e. Make end end and cancel cancel
jwiggins
left a comment
There was a problem hiding this comment.
I'm glad you pushed this as a WIP, because I think we perhaps should change nothing and instead add better documentation above the trait and in the docstring for drag_end (and maybe drag_cancel too).
I'll start by saying end_drag_on_leave is a bad name. #naming-things-is-hard, right? So a new trait with clear meaning might be a good long term fix. But would better documentation work too?
At least from my reading the DragTool code, drag_cancel is the callback for drags which end prematurely and drag_end is for drags which end normally. That's not at all clear just from reading the docstrings, so we should fix that. But I think if we start using drag_end for drags which ended prematurely that it's just as bad. We would have to introduce yet another callback method drag_finished (or something like that; naming things is hard).
|
I agree with John here - poorly named trait, documentation could be better (but it is explicitly called out in the My intuition is that the "ending" a drag normally when the mouse is still down will lead to an odd UX, but I could be convinced by a concrete example where the behaviour is desirable. |
A concrete example use case, coming straight from the horse's mouth, would be "trying to enclose something with a bounding box near the border of an image". |
| # NOTE: This behavior depends on "mouse_leave" events, which in general | ||
| # are not fired when `capture_mouse` is True (default). |
There was a problem hiding this comment.
I dont think this note is correct? If I leave capture_mouse as true, but set end_drag_on_leave to true and mess around with examples, I am seeing mouse_leave events fired and the drags cancelled on leave?
Maybe I am missing something
There was a problem hiding this comment.
It might be different between Qt and Wx.
There was a problem hiding this comment.
Completely orthogonal, but this just made me remember that chaco no longer lists wx as being supported in its ci/edmtool.py / wx is not exercised on its CI ...
|
Okay, I've taken a new stab at this given the feedback. Basically, the current implementation is: If a user does not explicitly set finally, if neither trait is set, behavior is preserved as the I've added unit tests to check the Note that this means if users want the new feature to end on leave not cancel after having perviously had |
| # Do nothing, cancel or end the drag operation if the mouse leaves the | ||
| # associated component? | ||
| # NOTE: This behavior depends on "mouse_leave" events, which in general | ||
| # are not fired when `capture_mouse` is True (default). |
There was a problem hiding this comment.
maybe I should make it more clear here that on_drag_leave = 'cancel' is equivalent to end_drag_on_leave = True not on_drag_leave = 'end'? That confusion is sort of the root problem at hand
jwiggins
left a comment
There was a problem hiding this comment.
Could you please add some more details to the drag_end callback like you did for drag_cancel?
fixes #551
It seems like this fix is going to require a change in behavior and may potentially "break" existing code.
Currently the
end_drag_on_leaveflag does not actually lead to a drag being "ended" on a mouse leave. Instead it is canceled. My thoughts were to either add acancel_drag_on_leavetrait to do whatend_drag_on_leavecurrently does (ie cancel the drag) and changeend_drag_on_leaveto actually end (see first commit). However, this requires one of these having preference over the other if both are True, and in actuality you would only ever want one behavior, so I removedend_drag_on_leaveand made a newon_drag_leaveenum trait.This however is a change in the public api so we need to tread very carefully. I am unsure what exactly we want to go with here, and thus am leaving this as a WIP for now awaiting further discussion.
I have tested manually using this example https://github.com/enthought/chaco/blob/master/examples/demo/edit_line.py.
I will write unit test(s) once the approach has been decided. CI will fail as I have not yet updated the existing tests. Opened the PR early so other could see and discuss