Elffuss BraidHub

kikocis/auto-code-rover public

main · 14.8 KiBRawPermalink
1{
2 "task_id": "matplotlib__matplotlib-25433",
3 "setup_info": {
4 "repo_path": "/home/haifeng/projects/reverse-prompt/SWE-bench/testbed/matplotlib__matplotlib/setup_matplotlib__matplotlib__3.7",
5 "env_name": "setup_matplotlib__matplotlib__3.7",
6 "pre_install": [],
7 "install": "python -m pip install -e .",
8 "test_cmd": "pytest --no-header -rA --tb=no -p no:cacheprovider lib/matplotlib/tests/test_backend_bases.py"
9 },
10 "task_info": {
11 "instance_id": "matplotlib__matplotlib-25433",
12 "base_commit": "7eafdd8af3c523c1c77b027d378fb337dd489f18",
13 "hints_text": "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. \r\n\r\nWhy are you doing this? In your application can you get away with not destroying your slider?\nI think there could be a way to not destroy the slider. But I don't have the time to test that currently.\r\nMy workaround for the problem was using a button to redraw everything. With that everything is working fine.\r\n\r\nThat 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. \r\nThanks for the answer.\nThe 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:\r\n```python\r\ndef redraw():\r\n pyplot.clf()\r\n addElements()\r\n pyplot.draw()\r\n return False\r\n\r\ndef onchanged(values):\r\n print(\"on changed\")\r\n print(values)\r\n pyplot.gcf().canvas.new_timer(redraw)\r\n```\nThanks for the answer. I tried that with the code in the original post.\r\nThe line:\r\n\r\n```python\r\npyplot.gcf().canvas.new_timer(redraw)\r\n```\r\ndoesn't work for me. After having a look at the documentation, I think the line should be:\r\n\r\n```python\r\npyplot.gcf().canvas.new_timer(callbacks=[(redraw, tuple(), dict())])\r\n```\r\n\r\nBut that still didn't work. The redraw callback doesn't seem to trigger.\nSorry, I mean to update that after testing and before posting, but forgot to. That line should be:\r\n```\r\n pyplot.gcf().canvas.new_timer(callbacks=[redraw])\r\n```\nSorry for double posting; now I see that it didn't actually get called!\r\n\r\nThat's because I forgot to call `start` as well, and the timer was garbage collected at the end of the function. It should be called as you've said, but stored globally and started:\r\n```\r\nimport matplotlib.pyplot as pyplot\r\nimport matplotlib.widgets as widgets\r\n\r\n\r\ndef redraw():\r\n print(\"redraw\")\r\n pyplot.clf()\r\n addElements()\r\n pyplot.draw()\r\n return False\r\n\r\n\r\ndef onchanged(values):\r\n print(\"on changed\")\r\n print(values)\r\n global timer\r\n timer = pyplot.gcf().canvas.new_timer(callbacks=[(redraw, (), {})])\r\n timer.start()\r\n\r\n\r\ndef onclick(e):\r\n print(\"on click\")\r\n global timer\r\n timer = pyplot.gcf().canvas.new_timer(callbacks=[(redraw, (), {})])\r\n timer.start()\r\n\r\n\r\ndef addElements():\r\n ax = pyplot.axes([0.1, 0.45, 0.8, 0.1])\r\n global slider\r\n slider = widgets.RangeSlider(ax, \"Test\", valmin=1, valmax=10, valinit=(1, 10))\r\n slider.on_changed(onchanged)\r\n ax = pyplot.axes([0.1, 0.30, 0.8, 0.1])\r\n global button\r\n button = widgets.Button(ax, \"Test\")\r\n button.on_clicked(onclick)\r\n\r\n\r\naddElements()\r\n\r\npyplot.show()\r\n```\nThanks 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.\nAre 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 `valinit=(1, 10)`.\nThe 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.\nI 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 `Slider` object. Replacing the slider object with a new one (correctly) forgets the old value.\r\n\r\n-----\r\n\r\nI 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).\nThe \"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.\r\n\r\nBut 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.",
14 "created_at": "2023-03-11T08:36:32Z",
15 "test_patch": "diff --git a/lib/matplotlib/tests/test_backend_bases.py b/lib/matplotlib/tests/test_backend_bases.py\n--- a/lib/matplotlib/tests/test_backend_bases.py\n+++ b/lib/matplotlib/tests/test_backend_bases.py\n@@ -95,6 +95,16 @@ def test_non_gui_warning(monkeypatch):\n in str(rec[0].message))\n \n \n+def test_grab_clear():\n+ fig, ax = plt.subplots()\n+\n+ fig.canvas.grab_mouse(ax)\n+ assert fig.canvas.mouse_grabber == ax\n+\n+ fig.clear()\n+ assert fig.canvas.mouse_grabber is None\n+\n+\n @pytest.mark.parametrize(\n \"x, y\", [(42, 24), (None, 42), (None, None), (200, 100.01), (205.75, 2.0)])\n def test_location_event_position(x, y):\n",
16 "repo": "matplotlib/matplotlib",
17 "problem_statement": "[Bug]: using clf and pyplot.draw in range slider on_changed callback blocks input to widgets\n### Bug summary\n\nWhen 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.\n\n### Code for reproduction\n\n```python\nimport matplotlib.pyplot as pyplot\r\nimport matplotlib.widgets as widgets\r\n\r\ndef onchanged(values):\r\n print(\"on changed\")\r\n print(values)\r\n pyplot.clf()\r\n addElements()\r\n pyplot.draw()\r\n\r\ndef onclick(e):\r\n print(\"on click\")\r\n pyplot.clf()\r\n addElements()\r\n pyplot.draw()\r\n\r\ndef addElements():\r\n ax = pyplot.axes([0.1, 0.45, 0.8, 0.1])\r\n global slider\r\n slider = widgets.RangeSlider(ax, \"Test\", valmin=1, valmax=10, valinit=(1, 10))\r\n slider.on_changed(onchanged)\r\n ax = pyplot.axes([0.1, 0.30, 0.8, 0.1])\r\n global button\r\n button = widgets.Button(ax, \"Test\")\r\n button.on_clicked(onclick)\r\n\r\naddElements()\r\n\r\npyplot.show()\n```\n\n\n### Actual outcome\n\nThe widgets can't receive any input from a mouse click, when redrawing in the on_changed callback of a range Slider. \r\nWhen using a button, there is no problem.\n\n### Expected outcome\n\nThe range slider callback on_changed behaves the same as the button callback on_clicked.\n\n### Additional information\n\nThe problem also occurred on Manjaro with:\r\n- Python version: 3.10.9\r\n- Matplotlib version: 3.6.2\r\n- Matplotlib backend: QtAgg\r\n- Installation of matplotlib via Linux package manager\r\n\n\n### Operating system\n\nWindows 10\n\n### Matplotlib Version\n\n3.6.2\n\n### Matplotlib Backend\n\nTkAgg\n\n### Python version\n\n3.11.0\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip\n",
18 "version": "3.7",
19 "FAIL_TO_PASS": [
20 "lib/matplotlib/tests/test_backend_bases.py::test_grab_clear"
21 ],
22 "PASS_TO_PASS": [
23 "lib/matplotlib/tests/test_backend_bases.py::test_canvas_change",
24 "lib/matplotlib/tests/test_backend_bases.py::test_canvas_ctor",
25 "lib/matplotlib/tests/test_backend_bases.py::test_draw[pdf]",
26 "lib/matplotlib/tests/test_backend_bases.py::test_draw[pgf]",
27 "lib/matplotlib/tests/test_backend_bases.py::test_draw[ps]",
28 "lib/matplotlib/tests/test_backend_bases.py::test_draw[svg]",
29 "lib/matplotlib/tests/test_backend_bases.py::test_get_default_filename",
30 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_colorbar[pan-1-expected2-horizontal-contourf]",
31 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_colorbar[pan-1-expected2-horizontal-imshow]",
32 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_colorbar[pan-1-expected2-vertical-contourf]",
33 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_colorbar[pan-1-expected2-vertical-imshow]",
34 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_colorbar[pan-3-expected3-horizontal-contourf]",
35 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_colorbar[pan-3-expected3-horizontal-imshow]",
36 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_colorbar[pan-3-expected3-vertical-contourf]",
37 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_colorbar[pan-3-expected3-vertical-imshow]",
38 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_colorbar[zoom-1-expected0-horizontal-contourf]",
39 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_colorbar[zoom-1-expected0-horizontal-imshow]",
40 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_colorbar[zoom-1-expected0-vertical-contourf]",
41 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_colorbar[zoom-1-expected0-vertical-imshow]",
42 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_colorbar[zoom-3-expected1-horizontal-contourf]",
43 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_colorbar[zoom-3-expected1-horizontal-imshow]",
44 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_colorbar[zoom-3-expected1-vertical-contourf]",
45 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_colorbar[zoom-3-expected1-vertical-imshow]",
46 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[None-mouseend0-expectedxlim0-expectedylim0]",
47 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[None-mouseend1-expectedxlim1-expectedylim1]",
48 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[None-mouseend2-expectedxlim2-expectedylim2]",
49 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[None-mouseend3-expectedxlim3-expectedylim3]",
50 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[None-mouseend4-expectedxlim4-expectedylim4]",
51 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[None-mouseend5-expectedxlim5-expectedylim5]",
52 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[None-mouseend6-expectedxlim6-expectedylim6]",
53 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[None-mouseend7-expectedxlim7-expectedylim7]",
54 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[control-mouseend16-expectedxlim16-expectedylim16]",
55 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[control-mouseend17-expectedxlim17-expectedylim17]",
56 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[shift-mouseend10-expectedxlim10-expectedylim10]",
57 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[shift-mouseend11-expectedxlim11-expectedylim11]",
58 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[shift-mouseend12-expectedxlim12-expectedylim12]",
59 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[shift-mouseend13-expectedxlim13-expectedylim13]",
60 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[shift-mouseend8-expectedxlim8-expectedylim8]",
61 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[shift-mouseend9-expectedxlim9-expectedylim9]",
62 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[x-mouseend14-expectedxlim14-expectedylim14]",
63 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_pan[y-mouseend15-expectedxlim15-expectedylim15]",
64 "lib/matplotlib/tests/test_backend_bases.py::test_interactive_zoom",
65 "lib/matplotlib/tests/test_backend_bases.py::test_location_event_position[200-100.01]",
66 "lib/matplotlib/tests/test_backend_bases.py::test_location_event_position[205.75-2.0]",
67 "lib/matplotlib/tests/test_backend_bases.py::test_location_event_position[42-24]",
68 "lib/matplotlib/tests/test_backend_bases.py::test_location_event_position[None-42]",
69 "lib/matplotlib/tests/test_backend_bases.py::test_location_event_position[None-None]",
70 "lib/matplotlib/tests/test_backend_bases.py::test_non_gui_warning",
71 "lib/matplotlib/tests/test_backend_bases.py::test_pick",
72 "lib/matplotlib/tests/test_backend_bases.py::test_toolbar_zoompan",
73 "lib/matplotlib/tests/test_backend_bases.py::test_toolmanager_get_tool",
74 "lib/matplotlib/tests/test_backend_bases.py::test_toolmanager_remove",
75 "lib/matplotlib/tests/test_backend_bases.py::test_toolmanager_update_keymap",
76 "lib/matplotlib/tests/test_backend_bases.py::test_uses_per_path",
77 "lib/matplotlib/tests/test_backend_bases.py::test_widgetlock_zoompan"
78 ],
79 "environment_setup_commit": "0849036fd992a2dd133a0cffc3f84f58ccf1840f",
80 "patch": "diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py\n--- a/lib/matplotlib/figure.py\n+++ b/lib/matplotlib/figure.py\n@@ -931,6 +931,7 @@ def _break_share_link(ax, grouper):\n self._axobservers.process(\"_axes_change_event\", self)\n self.stale = True\n self._localaxes.remove(ax)\n+ self.canvas.release_mouse(ax)\n \n # Break link between any shared axes\n for name in ax._axis_names:\n",
81 "pr_link": "https://github.com/matplotlib/matplotlib/pull/25433"
82 }
83}