Scripting Resources for DigitalMicrograph™ |
Example: Thread and Dialog Interaction |
|
Function |
Example code which shows how to get a dialog to start and stop a thread, and how to have that thread communicate with the dialog - to source information, such as values in fields and to reset buttons, LEDs etc. In this example the dialog and thread are separate classes. In a second example, the thread is run from within the dialog class |
Version |
version:20201223, v2.0 |
Author |
D. R. G. Mitchell |
Acknowledgements |
Pavel Potapov and Bernhard Schaffer are thanked for providing advice on use of the Script Object ID by which the thread can access the dialog and thence items within the dialog. |
Comments |
This script asks for a counting interval and a duration. When the Start button is pressed the thread counts out n intervals until the duration has elapsed. The time and interval information are printed in the Output window. The thread stops when the Stop button is pressed, the duration has elapsed or the dialog is closed. Updated in this version to deal with the fact that previously, the dialog did not go out of scope until the thread had finished. As such, any attempts to source information from the dialog (after closing it) remained possible and no exception was thrown - the exception being the signal to terminate the thread. The solution implemented here is to test for the dialog closed condition by attempting to get the dialog's frame position. This function call is only valid if the dialog is still displayed. If the dialog has been closed an exception is generated and this can be used to terminate the thread. |
System Requirements |
Should be compatible with all recent versions of DigitalMicrograph, but only tested on GMS 2.32. |
Known Issues |
- |
Supported |
Yes |
Included Files |
Main script file. |
Source Code |
See attached script
|