Scripting Resources for DigitalMicrograph™


Dave Mitchell's DigitalMicrograph™ Scripting Website

Home | Scripts | Examples | Functions | Recent Updates | Tutorials | Resources | Publications | Consulting | Projects | Contact & Bio | Private | Search


Example: Triggering an Image Event Listener with a Background Thread
Shows how to add an event listener to an image. This image is subsequently updated by a background thread - which repeatedly triggers the event listener.
version: 150127, v1.0
D. R. G. Mitchell
Vincent Hou - created some nice demo code on the DMSUG archive.

Example code which shows how to use an ImageEventListener. In this case, the listener code is combined with a thread which simply increments the value of a displayed image. An event listener has been added to this image and so it is triggered when the image data value is changed by the thread. The Listener reports the mean value of the image and some info on the event in the Output window. When the event listener is acted upon by a background thread changing the image, it results in the DataChanged function being called two times for each change in the image intensity. This uses up a lot of processing and so here, the DataChanged function only acts on every second cycle. However, if the image is subsequently changed manually by executing a script which addresses it (using the image letter variable), only one data change is registered for each external change. Depending on the context in which event listening is used, (eg listening for updates on a live image), the number of cycles listened to (and ignored) may need to be changed. If the live processing triggered by an event is minimal then it may be acceptable to act on every change, to keep the response universal. However, if intensive processing is enacted, then things may get very slow.


System Requirements
Should be compatible with all recent versions of DigitalMicrograph.
Known Issues
Included Files
Main script file.
Source Code
See attached script