Skip to content

Commit 32b0b63

Browse files
committed
Fix duplicate Creation tab issue by removing existing tab before applying parameters; add test to verify single tab presence
1 parent 68ceb82 commit 32b0b63

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

datalab/gui/panel/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,12 @@ def setup_creation_tab(self, obj: SignalObj | ImageObj) -> bool:
483483
self.creation_param_editor = editor
484484
self.current_creation_obj = obj
485485

486+
# Remove existing Creation tab if it exists
487+
if self.creation_scroll is not None:
488+
index = self.indexOf(self.creation_scroll)
489+
if index >= 0:
490+
self.removeTab(index)
491+
486492
# Set the parameter editor as the scroll area widget
487493
# Creation tab is always at index 0 (before all other tabs)
488494
self.creation_scroll = QW.QScrollArea()

datalab/tests/features/common/interactive_processing_test.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,67 @@ def test_apply_creation_parameters_image():
256256
assert not np.array_equal(updated_image.data, original_data)
257257

258258

259+
def test_no_duplicate_creation_tabs():
260+
"""Test that applying creation parameters multiple times doesn't create
261+
duplicate tabs.
262+
263+
This test verifies the fix for the bug where clicking "Apply" in the
264+
Creation tab would create a new Creation tab instead of reusing the
265+
existing one.
266+
"""
267+
with qt_app_context():
268+
with datalab_test_app_context() as win:
269+
panel = win.imagepanel
270+
objprop = panel.objprop
271+
272+
# Create an image with creation parameters
273+
param = Gauss2DParam.create(x0=50.0, y0=50.0, sigma=10.0, a=100.0)
274+
panel.new_object(param=param, edit=False)
275+
image = panel.objview.get_current_object()
276+
assert image is not None
277+
278+
# Verify Creation tab was set up
279+
assert objprop.creation_param_editor is not None
280+
assert objprop.creation_scroll is not None
281+
282+
# Count how many Creation tabs exist initially using the widget reference
283+
initial_index = objprop.indexOf(objprop.creation_scroll)
284+
assert initial_index >= 0, "Creation tab should be present"
285+
286+
# Count tabs by checking if they reference the same scroll widget
287+
initial_count = sum(
288+
1
289+
for i in range(objprop.count())
290+
if objprop.widget(i) is objprop.creation_scroll
291+
)
292+
assert initial_count == 1, "Should have exactly one Creation tab initially"
293+
294+
# Apply creation parameters multiple times
295+
editor = objprop.creation_param_editor
296+
for amplitude in [150.0, 200.0, 250.0]:
297+
editor.dataset.a = amplitude
298+
objprop.apply_creation_parameters()
299+
300+
# Wait for the deferred setup_creation_tab to complete
301+
from qtpy.QtTest import QTest
302+
303+
QTest.qWait(100)
304+
305+
# Verify that creation_scroll reference still exists
306+
assert objprop.creation_scroll is not None
307+
308+
# Count Creation tabs again - should still be just one
309+
creation_count = sum(
310+
1
311+
for i in range(objprop.count())
312+
if objprop.widget(i) is objprop.creation_scroll
313+
)
314+
assert creation_count == 1, (
315+
f"Should still have exactly one Creation tab after "
316+
f"applying amplitude={amplitude}"
317+
)
318+
319+
259320
def test_no_creation_parameters_for_base_classes():
260321
"""Test that creation parameters are NOT stored for base classes
261322
@@ -809,6 +870,7 @@ def test_select_source_objects_deleted_source():
809870
test_recompute()
810871
test_apply_creation_parameters_signal()
811872
test_apply_creation_parameters_image()
873+
test_no_duplicate_creation_tabs()
812874
test_no_creation_parameters_for_base_classes()
813875
test_apply_processing_parameters_signal()
814876
test_apply_processing_parameters_image()

0 commit comments

Comments
 (0)