Skip to content

Commit 50e2482

Browse files
committed
fix: IndexError when removing a plot (close #36)
1 parent 3346cf4 commit 50e2482

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2.0.2
2+
- fix: IndexError when removing a plot (#36)
13
2.0.1
24
- fix: correctly distinguish prereleases when checking for new versions
35
- enh: allow loading data via drag&drop

shapeout2/gui/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ def adopt_pipeline(self, pipeline_state):
186186
try:
187187
new_ncol, new_nrow = self.pipeline.get_plot_col_row_count(
188188
plot_id, pipeline_state)
189-
except KeyError:
189+
lay = pipeline_state["plots"][plot_index]["layout"]
190+
except (KeyError, IndexError):
190191
# the plot was removed
191192
continue
192193
else:
193-
lay = pipeline_state["plots"][plot_index]["layout"]
194194
lay["size x"] += 200*(new_ncol-old_ncol)
195195
lay["size y"] += 200*(new_nrow-old_nrow)
196196
# set the new state of the pipeline

tests/test_gui_plotting.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,34 @@ def test_handle_empty_plots_issue_27(qtbot):
6868
with pytest.warns(pipeline.core.EmptyDatasetWarning):
6969
# this now only throws a warning
7070
qtbot.mouseClick(pe, QtCore.Qt.LeftButton) # activate (raises #27)
71+
72+
73+
def test_remove_plots_issue_36(qtbot):
74+
"""Correctly handle empty plots
75+
76+
https://github.com/ZELLMECHANIK-DRESDEN/ShapeOut2/issues/36
77+
78+
Traceback (most recent call last):
79+
File "/home/paul/repos/ShapeOut2/shapeout2/gui/main.py",
80+
line 193, in adopt_pipeline
81+
lay = pipeline_state["plots"][plot_index]["layout"]
82+
IndexError: list index out of range
83+
"""
84+
mw = ShapeOut2()
85+
qtbot.addWidget(mw)
86+
87+
# add a dataslots
88+
path = pathlib.Path(__file__).parent / "data" / "calibration_beads_47.rtdc"
89+
mw.add_dataslot(paths=[path, path, path])
90+
91+
assert len(mw.pipeline.slot_ids) == 3, "we added those"
92+
assert len(mw.pipeline.filter_ids) == 1, "automatically added"
93+
94+
# now create a plot window
95+
plot_id = mw.add_plot()
96+
# and another one
97+
mw.add_plot()
98+
99+
# remove a plot
100+
pw = mw.block_matrix.get_widget(filt_plot_id=plot_id)
101+
pw.action_remove()

0 commit comments

Comments
 (0)