New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: using clf and pyplot.draw in range slider on_changed callback blocks input to widgets #25345
Comments
|
A can confirm this behavior, but removing and recreating the objects that host the callbacks in the callbacks is definitely on the edge of the intended usage. Why are you doing this? In your application can you get away with not destroying your slider? |
|
I think there could be a way to not destroy the slider. But I don't have the time to test that currently. That was the weird part for me as they are both callbacks, but in one everything works fine and in the other one all inputs are blocked. If what I'm trying doing is not the intended usage, that's fine for me. |
|
The idiomatic way to destructively work on widgets that triggered an event in a UI toolkit is to do the destructive work in an idle callback: def redraw():
pyplot.clf()
addElements()
pyplot.draw()
return False
def onchanged(values):
print("on changed")
print(values)
pyplot.gcf().canvas.new_timer(redraw) |
|
Thanks for the answer. I tried that with the code in the original post. pyplot.gcf().canvas.new_timer(redraw)doesn't work for me. After having a look at the documentation, I think the line should be: pyplot.gcf().canvas.new_timer(callbacks=[(redraw, tuple(), dict())])But that still didn't work. The redraw callback doesn't seem to trigger. |
|
Sorry, I mean to update that after testing and before posting, but forgot to. That line should be: |
|
Sorry for double posting; now I see that it didn't actually get called! That's because I forgot to call |
|
Thanks for the answer, the code works without errors, but I'm still able to break it when using the range slider. Then it results in the same problem as my original post. It seems like that happens when triggering the onchanged callback at the same time the timer callback gets called. |
|
Are you sure it's not working, or is it just that it got replaced by a new one that is using the same initial value again? For me, it moves, but once the callback runs, it's reset because the slider is created with |
|
The code redraws everything fine, but when the onchanged callback of the range slider gets called at the same time as the redraw callback of the timer, I'm not able to give any new inputs to the widgets. You can maybe reproduce that with changing the value of the slider the whole time, while waiting for the redraw. |
|
I think what is happening is that because you are destroying the slider every time the you are also destroying the state of what value you changed it to. When you create it you re-create it at the default value which produces the effect that you can not seem to change it. Put another way, the state of what the current value of the slider is is in the I agree it fails in surprising ways, but I think that this is best case "undefined behavior" and worst case incorrect usage of the tools. In either case there is not much we can do upstream to address this (as if the user did want to get fresh sliders that is not a case we should prevent from happening or warn on). |
|
The "forgetting the value" is not the problem. My problem is, that the input just blocks for every widget in the figure. When that happens, you can click on any widget, but no callback gets triggered. That problem seems to happen when a callback of an object gets called that is/has been destroyed, but I don't know for sure. But if that is from the incorrect usage of the tools, that's fine for me. I got a decent workaround that works currently, so I just have to keep that in my code for now. |
|
Ah I see, I can reproduce if I press and hold the mouse, and the I would think that you'd want to disabling the callback when the mouse is in use: and then only do a clear when a final value is chosen. |
Otherwise, _nothing_ will remove the grab, and no other Axes can grab the mouse (either raising the `RuntimeError` exception, or in the case of widgets, ignoring mouse events altogether.) Fixes matplotlib#25345
|
Thanks, the piece of code you provided works as expected. |


Bug summary
When using clear figure, adding new widgets and then redrawing the current figure in the on_changed callback of a range slider the inputs to all the widgets in the figure are blocked. When doing the same in the button callback on_clicked, everything works fine.
Code for reproduction
Actual outcome
The widgets can't receive any input from a mouse click, when redrawing in the on_changed callback of a range Slider.
When using a button, there is no problem.
Expected outcome
The range slider callback on_changed behaves the same as the button callback on_clicked.
Additional information
The problem also occurred on Manjaro with:
Operating system
Windows 10
Matplotlib Version
3.6.2
Matplotlib Backend
TkAgg
Python version
3.11.0
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: