I would like to know whether there is a kind of pup-up dialog that will not block the whole program. In the following simplified example, the standard deviation of a test image is calculated and then pups up in an OK dialog window.
image Img := RealImage("",4,1024,1)
Img = Random()
Img.ShowImage()
number SDev = sqrt(Img.Variance())
OKDialog("Standard deviation =" + SDev)
number Factor
if(!GetNumber("Input the factor that I want:", 5, Factor))
exit(0)
Is it possible to move this window aside (since the info within is needed) so that I can still zoom in or zoom out my image for further evaluation?
OkDialog(), ShowAlert(), and OkCancelDialog() all cannot fit my requirement. As well, I am aware of that printing this value in the result window could be an alternative, but I just want to show this info in a more visible dialog window.
Thanks in advance.
Any dialog derived from UIFrame
and displayed with the Display()
method and not the Pose()
method will do exactly that.
However, when displaying such a modeless dialog your other code will just continue to run. The dialog is on a separate thread.
This is the opposite of a modal dialog which will wait for it to be closed before code execution resumes.
So, if you want a script, that presents a dialog, allow "doing stuff" but then continues when the dialog closes, things are a bit more complicated to do. You can only do this when you script is on a background thread.
Simple, blocking, modal dialog:
clearResults()
Result("I do stuff \n")
OKDialog("Wait for me!")
Result("I continue to do stuff \n")
Simple, modeless dialog. Only works for scripts on a background thread:
// $BACKGROUND$
number ModelessTwoButtonDialog(string prompt, string but1, string but2)
{
number sem = NewSemaphore()
ModelessDialog(prompt,but1,but2,sem)
Try{GrabSemaphore(sem);}
Catch{return 0;}
return 1
}
clearResults()
Result("I do stuff \n")
number res = ModelessTwoButtonDialog("Wait for me!","OK","CANCEL")
Result("I continue to do stuff. You pressed:" + res)
Simple, modeless dialog that will not block your script execution. (But dialog buttons may do stuff).
class myDlg:UIframe{
void OnButtonDoStuff(object self) { result("\n Action!"); }
myDlg(object self)
{
taggroup dlg = DLGCreateDialog("My Dialog")
dlg.DLGAddElement(DLGCreateLabel("just text in this dialog"))
dlg.DLGAddElement(DLGCreatePushButton("DO stuff", "OnButtonDoStuff"))
self.Init( dlg )
}
}
clearResults()
Result("I do stuff \n")
Alloc(myDlg).display("Title")
Result("I continue to do stuff.")
Simple, modal dialog that will block your script execution. (But dialog buttons may do stuff).
class myDlg:UIframe{
void OnButtonDoStuff(object self) { result("\n Action!"); }
myDlg(object self)
{
taggroup dlg = DLGCreateDialog("My Dialog")
dlg.DLGAddElement(DLGCreateLabel("just text in this dialog"))
dlg.DLGAddElement(DLGCreatePushButton("DO stuff", "OnButtonDoStuff"))
self.Init( dlg )
}
}
clearResults()
Result("I do stuff \n")
Alloc(myDlg).pose()
Result("I continue to do stuff.")
Simple, modeless dialog that will block your script execution until closed. (But dialog buttons may do stuff). (The script on the main-thread is constantly telling DM to do other stuff as long as the window is open. A bit ugly.)
class myDlg:UIframe{
void OnButtonDoStuff(object self) { result("\n Action!"); }
myDlg(object self)
{
taggroup dlg = DLGCreateDialog("")
dlg.DLGAddElement(DLGCreateLabel("just text in this dialog"))
dlg.DLGAddElement(DLGCreatePushButton("DO stuff", "OnButtonDoStuff"))
self.Init( dlg )
}
~myDlg(object self){Result("\n Dialog actually removed from memory.");}
}
clearResults()
Result("I do stuff \n")
documentwindow win = Alloc(myDlg).display("Title")
while (win.WindowIsOpen()) doEvents()
Result("I continue to do stuff.")
win = NULL