Skip to content

Commit 24c5deb

Browse files
committed
fix: ValueError when removing activated datasets and opening Quick View
1 parent 8bf5710 commit 24c5deb

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- fix: ValueError when filtering all events in Quick View (#37)
44
- fix: TypeError when removing datasets and opening Quick View (#38)
55
- fix: RuntimeError when removing datasets and opening Quick View (#38)
6+
- fix: ValueError when removing activated datasets and opening Quick View
67
2.0.1
78
- fix: correctly distinguish prereleases when checking for new versions
89
- enh: allow loading data via drag&drop

shapeout2/gui/quick_view/qv_main.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,18 @@ def __setstate__(self, state):
178178
self.checkBox_trace_raw.setChecked(event["trace raw"])
179179
self.checkBox_trace_legend.setChecked(event["trace legend"])
180180

181+
def _check_file_open(self, rtdc_ds):
182+
"""Check whether a dataset is still open"""
183+
if isinstance(rtdc_ds, dclab.rtdc_dataset.RTDC_HDF5):
184+
if rtdc_ds._h5:
185+
# the file is open
186+
isopen = True
187+
else:
188+
isopen = False
189+
elif isinstance(rtdc_ds, dclab.rtdc_dataset.RTDC_Hierarchy):
190+
isopen = self._check_file_open(rtdc_ds.hparent)
191+
return isopen
192+
181193
def _set_initial_ui(self):
182194
# Initially, only show the info about how QuickView works
183195
self.widget_tool.setEnabled(False)
@@ -193,10 +205,8 @@ def _set_initial_ui(self):
193205
def rtdc_ds(self):
194206
"""Dataset to plot; set to None initially and if the file is closed"""
195207
if self._rtdc_ds is not None:
196-
if isinstance(self._rtdc_ds, dclab.rtdc_dataset.RTDC_HDF5):
197-
if not self._rtdc_ds._h5:
198-
# the file is closed
199-
self._rtdc_ds = None
208+
if not self._check_file_open(self._rtdc_ds):
209+
self._rtdc_ds = None
200210
# now check again
201211
if self._rtdc_ds is None:
202212
self._set_initial_ui()

tests/test_gui_quickview.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,57 @@ def test_no_events_issue_37(qtbot):
103103
mw.close()
104104

105105

106+
def test_remove_dataset_h5py_error(qtbot):
107+
"""Removing an activated dataset and activating Quick View fails
108+
109+
Unhandled exception in Shape-Out version 2.0.1.post2:
110+
Traceback (most recent call last):
111+
File "/home/paul/repos/ShapeOut2/shapeout2/gui/main.py", line 235,
112+
in adopt_pipeline
113+
self.widget_quick_view.update_feature_choices()
114+
File "/home/paul/repos/ShapeOut2/shapeout2/gui/quick_view/qv_main.py",
115+
line 635, in update_feature_choices
116+
ds_feats = [f for f in self.rtdc_ds.features if f in feats_scalar]
117+
[...]
118+
File "/home/paul/repos/dclab/dclab/rtdc_dataset/fmt_hdf5.py", line 101,
119+
in _is_defective_feature
120+
if attr in self._h5.attrs:
121+
[...]
122+
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
123+
File "h5py/h5o.pyx", line 190, in h5py.h5o.open
124+
ValueError: Not a location (invalid object ID)
125+
"""
126+
mw = ShapeOut2()
127+
qtbot.addWidget(mw)
128+
129+
# add a dataslot
130+
path = pathlib.Path(__file__).parent / "data" / "calibration_beads_47.rtdc"
131+
mw.add_dataslot(paths=[path, path])
132+
133+
assert len(mw.pipeline.slot_ids) == 2, "we added those"
134+
assert len(mw.pipeline.filter_ids) == 1, "automatically added"
135+
136+
# activate a dataslot
137+
slot_id = mw.pipeline.slot_ids[0]
138+
filt_id = mw.pipeline.filter_ids[0]
139+
em = mw.block_matrix.get_widget(slot_id, filt_id)
140+
qtbot.mouseClick(em, QtCore.Qt.LeftButton) # activate
141+
qtbot.mouseClick(em, QtCore.Qt.LeftButton, QtCore.Qt.ShiftModifier)
142+
# did that work?
143+
assert mw.pipeline.is_element_active(slot_id, filt_id)
144+
145+
# close Quick View
146+
qtbot.mouseClick(mw.toolButton_quick_view, QtCore.Qt.LeftButton)
147+
148+
# now remove the dataset
149+
pw = mw.block_matrix.get_widget(slot_id=slot_id)
150+
pw.action_remove()
151+
152+
# open Quick View
153+
qtbot.mouseClick(mw.toolButton_quick_view, QtCore.Qt.LeftButton)
154+
mw.close()
155+
156+
106157
def test_update_polygon_filter_issue_26(qtbot):
107158
"""https://github.com/ZELLMECHANIK-DRESDEN/ShapeOut2/issues/26
108159

0 commit comments

Comments
 (0)