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: Progress Bar in Dialog
An example script which shows how to implement a progress bar in a dialog. This is useful where script processes may take a long time. The use of ValidateView() to force updates of the dialog is also demonstrated.
version:20050918, v1.0
D. R. G. Mitchell
Vincent Hou and Douglas Hague are thanked for useful tips on getting this to work.
System Requirements
Should be compatible with all recent versions of DigitalMicrograph.
Known Issues
Included Files
Main script file.
Source Code

// D. R. G. Mitchell, (remove the nospam to make this email address work)

// v1.0, Sept 2005

// Example script which shows how to implement a progress bar within a dialog.

// Essential for processes which take a long time.

// version:20050918


// Demo of Progress bar in dialogs


// Thanks to V. Hou/Douglas Hague for tips on use of the progressbar functions

// note also use of the ValidateView() method, which forces an update of the dialog

// this will also be useful where other dialog elements, such as number fields, require

// updating during a process (from within the main thread)


// variables


object dialog_frame

taggroup firstbutton, secondbutton

number true=1

number false=0



// the class createbuttondialog is of the type user interface frame (UIFrame), and responds to interactions

// with the dialog - in this case pressing buttons


class CreateButtonDialog : uiframe



void button1response(object self)



//this is the response when the Start button is pressed

self.Setelementisenabled("first", false);// these commands set the button as enabled or not enabled

self.Setelementisenabled("second", true);// "second" in this command is the identifier of the button 'secondbutton'

number i=0 // a loop to 'do something' which requires a progress bar

for(i=0; i<1001; i++)


self.validateView() // this forces an update of the dialog








void button2response(object self)



//this is the response when the Clear button is pressed










// this function creates a button taggroup which returns the taggroup 'box' which is added to

// the dialog in the createdialog function.


taggroup MakeButton()



// Creates a box in the dialog which surrounds the button


taggroup box_items

taggroup box=dlgcreatebox(" Buttons ", box_items)




// Creates the first button


firstButton = DLGCreatePushButton("Start Progress Bar", "button1response")

dlgenabled(firstbutton,1) // sets the button as enabled when the dialog is first created

dlgidentifier(firstbutton, "first") // identifiers are strings which identify an element, such as a button

// they are used to change the enabled/disabled status of the element in the button response functions above





// Creates the second button


secondButton = DLGCreatePushButton(" Reset Progress Bar ", "button2response")



dlgidentifier(secondbutton, "second")



// Creates the progress bar


taggroup progbar

taggroup progressb=dlgcreateprogressbar("progbar").dlgfill("X")


return box




// This function creates the dialog, drawing togther the parts (buttons etc) which make it up

// and alloc 'ing' the dialog with the response, so that one responds to the other. It also

// displays the dialog


void CreateDialogExample()



// Configure the positioning in the top right of the application window


TagGroup position;

position = DLGBuildPositionFromApplication()

position.TagGroupSetTagAsTagGroup( "Width", DLGBuildAutoSize() )

position.TagGroupSetTagAsTagGroup( "Height", DLGBuildAutoSize() )

position.TagGroupSetTagAsTagGroup( "X", DLGBuildRelativePosition( "Inside", 1 ) )

position.TagGroupSetTagAsTagGroup( "Y", DLGBuildRelativePosition( "Inside", 1 ) )


TagGroup dialog_items;

TagGroup dialog = DLGCreateDialog("Example Dialog", dialog_items).dlgposition(position);

dialog_items.dlgaddelement( MakeButton() );


dialog_frame = alloc(CreateButtonDialog).init(dialog)

dialog_frame.display("Dialog Template");





// calls the above function which puts it all together