1414import sigima .objects
1515import sigima .params
1616import sigima .proc .image as sigima_image
17- from guidata .qthelpers import exec_dialog , qt_app_context
17+ from guidata .qthelpers import exec_dialog , qt_app_context , qt_wait_until
1818from sigima .tests import vistools
1919from sigima .tests .data import create_noisygauss_image
2020
2121from datalab .env import execenv
2222from datalab .widgets .imagebackground import ImageBackgroundDialog
2323
2424
25+ def wait_for_rect_coords (dlg : ImageBackgroundDialog ) -> bool :
26+ """Condition to wait for rectangle coordinates."""
27+ # Wait for rectangle coordinates to be set. This is necessary because
28+ # when executing the dialog in unattended mode, the rectangle
29+ # coordinates may not be set immediately (Qt events may not be processed).
30+ try :
31+ dlg .get_rect_coords ()
32+ return True
33+ except ValueError :
34+ return False
35+
36+
2537def test_image_background_selection () -> None :
2638 """Image background selection test."""
2739 with qt_app_context ():
@@ -30,6 +42,7 @@ def test_image_background_selection() -> None:
3042 dlg .resize (640 , 480 )
3143 dlg .setObjectName (dlg .objectName () + "_00" ) # to avoid timestamp suffix
3244 exec_dialog (dlg )
45+ qt_wait_until (lambda : wait_for_rect_coords (dlg ))
3346 execenv .print (f"background: { dlg .get_background ()} " )
3447 execenv .print (f"rect coords: { dlg .get_rect_coords ()} " )
3548 # Check background value:
@@ -45,6 +58,7 @@ def test_image_offset_correction_with_background_dialog() -> None:
4558 dlg = ImageBackgroundDialog (i1 )
4659 ok = exec_dialog (dlg )
4760 if ok :
61+ qt_wait_until (lambda : wait_for_rect_coords (dlg ))
4862 param = sigima .objects .ROI2DParam ()
4963 # pylint: disable=unbalanced-tuple-unpacking
5064 ix0 , iy0 , ix1 , iy1 = i1 .physical_to_indices (dlg .get_rect_coords ())
0 commit comments