![](/profiles/wavemetrics/themes/wavemetrics/logo.png)
Stop Button (Again)
![](/sites/default/files/styles/thumbnail/public/default_images/Artboard%201_1.png?itok=jeHOCIXy)
hegedus
I asked this ~10 years ago, but have forgotten what I did back then.
I have a panel interface where the user set some directories and starts the loop with a button. Since the process can be long (1 hour +), there is a request for a stop button. I would like to exit the loop after an image is processed and then continue to write a log file with the status of each image processed. I have the function and loop below.
Question: What do I need to do to read the button push once this function starts?
Function Run_Image_workflow()
wave/T Images_to_Process
string basepath,QP
Pathinfo QuantPath
QP = s_path
NVAR ImagesLeft
Nvar Halt =root:halt
variable i,imax
imax = dimsize(Images_to_process,0)
for(i=0;i<imax;i+=1)
//should image be run
if (Stringmatch(Images_to_Process[i][%status], "not run")) //done and mask missing are skipped
//summary
Newpath/C/Q/O Pathsummary, (QP+Images_to_Process[i]+ ":summary")
//image
NewPath/C/Q/O PathImageOut, (QP+Images_to_Process[i]+ ":OutputImages")
//sizes
NewPath/C/Q/O Pathsizes, (QP+Images_to_Process[i]+ ":size")
//textures
NewPath/C/Q/O Pathtexture, (QP+Images_to_Process[i]+ ":texture")
process_image(i)
ImagesLeft -=1
Images_To_process[i][%Status] ="done"
if(halt)
break
endif
endif
endfor
Save_log_file()
end
Function StopButton(ba) : ButtonControl
STRUCT WMButtonAction &ba
switch( ba.eventCode )
case 2: // mouse up
// click code here
nvar halt =root:halt
halt =1
break
case -1: // control being killed
break
endswitch
return 0
End
wave/T Images_to_Process
string basepath,QP
Pathinfo QuantPath
QP = s_path
NVAR ImagesLeft
Nvar Halt =root:halt
variable i,imax
imax = dimsize(Images_to_process,0)
for(i=0;i<imax;i+=1)
//should image be run
if (Stringmatch(Images_to_Process[i][%status], "not run")) //done and mask missing are skipped
//summary
Newpath/C/Q/O Pathsummary, (QP+Images_to_Process[i]+ ":summary")
//image
NewPath/C/Q/O PathImageOut, (QP+Images_to_Process[i]+ ":OutputImages")
//sizes
NewPath/C/Q/O Pathsizes, (QP+Images_to_Process[i]+ ":size")
//textures
NewPath/C/Q/O Pathtexture, (QP+Images_to_Process[i]+ ":texture")
process_image(i)
ImagesLeft -=1
Images_To_process[i][%Status] ="done"
if(halt)
break
endif
endif
endfor
Save_log_file()
end
Function StopButton(ba) : ButtonControl
STRUCT WMButtonAction &ba
switch( ba.eventCode )
case 2: // mouse up
// click code here
nvar halt =root:halt
halt =1
break
case -1: // control being killed
break
endswitch
return 0
End
Andy
Set up your panel as a "progress window" using DoUpdate/W=<panel>/E=1.
DisplayHelpTopic "Progress Windows"
July 1, 2024 at 01:28 pm - Permalink
Hi,
Thank you. Also I put the do update in the loop just before I check.
This is what I ended up with
Andy
wave/T Images_to_Process
string QP
Pathinfo QuantPath
QP = s_path
NVAR ImagesLeft
variable i,imax
imax = dimsize(Images_to_process,0)
for(i=0;i<imax;i+=1)
//should image be run
if (Stringmatch(Images_to_Process[i][%status], "not run")) //done and mask missing are skipped
//summary
Newpath/C/Q/O Pathsummary, (QP+Images_to_Process[i]+ ":summary")
//image
NewPath/C/Q/O PathImageOut, (QP+Images_to_Process[i]+ ":OutputImages")
//sizes
NewPath/C/Q/O Pathsizes, (QP+Images_to_Process[i]+ ":size")
//textures
NewPath/C/Q/O Pathtexture, (QP+Images_to_Process[i]+ ":texture")
process_image(i)
ImagesLeft -=1
DoUpdate/W=setup /E=1
Nvar Halt =root:halt
Images_To_process[i][%Status] ="done"
if(halt)
break
endif
endif
endfor
Save_log_file()
end
July 1, 2024 at 01:43 pm - Permalink
Looks good!
July 1, 2024 at 04:19 pm - Permalink