Scripting Resources for DigitalMicrograph™

banner

Dave Mitchell's DigitalMicrograph™ Scripting Website

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

 

Example: Single Button Dialog
Function
An example script which shows the basic elements which go to make up a dialog. In this case the dialog has a single button which tells you when it has been pressed.
Version
version:20091003, v1.0
Author
D. R. G. Mitchell
Acknowledgements
-
Comments
Just run the script. It does not need any images displayed. Note dialogs require a lot of extra code, so the effort for a simple script is significant. However, if your script needs lots of data inputs or prompts, then it is worth wrapping it up in a dialog.
System Requirements
Dialog scripts are only generally compatible with PC-based versions of DigitalMicrograph - GMS 1.6 and later.
Known Issues
-
Supported
Yes
Included Files
Single script file.
Source Code

 

 

// the class createbuttondialog is of the type user interface frame, and responds to interaction

// with the dialog

// version20091003, v1.0

// D. R. G. Mitchell, Oct 2009

// adminnospam@dmscripting.com (remove the nospam to make this email address work)

 

class CreateButtonDialog : uiframe

{

void buttonresponse(object self)

{

//this is the response when the button is pressed


Beep()

okdialog("You pressed my button!")

return

}

}

// 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(" Parameters ", box_items)

box.dlgexternalpadding(5,5)

box.dlginternalpadding(25,25)

 

// Creates the button

TagGroup ExampleButton = DLGCreatePushButton("Push Me", "buttonresponse")

examplebutton.dlgexternalpadding(5,0)

box_items.dlgaddelement(examplebutton)

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() );

object dialog_frame = alloc(CreateButtonDialog).init(dialog)

dialog_frame.display("Dialog Template");

}

// calls the above function which puts it all together

createdialogexample()