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: Bevel Buttons Dialog
Function
An example script to show how to use Bevel Buttons in a dialog. These change appearance when pressed. Enabling/disabling buttons and use of hard coded graphic elements is also shown.
Version
version:20050303, v1.0
Author
D. R. G. Mitchell
Acknowledgements
-
Comments
See the Thumbnail Creator script to create hard code for graphics elements you wish to use inside a script.
System Requirements
Should be compatible with all recent versions of DigitalMicrograph.
Known Issues
-
Supported
Yes
Included Files
Main script file.
Source Code

// An example which shows how to create buttons which change appearance when pressed.

// In the upper box pressing an enabled button makes the other (disabled) button become

// enabled, and disabled itself. In the lower box, buttons are a plain blue,

// but change to a graphic (a tem image) when pressed. The image is contained within the script

// and the format thereof is shown. I have created a little utility script to convert an image

// into this format. Contact me if you'd like a copy.

 

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


// version:20050303


// v1.0, March 2005

 

 

// variables

 

taggroup firstbutton, secondbutton

number true=1

number false=0

 

 

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

// the dialog

 

 

class CreateButtonDialog : uiframe

{

 

void button1response(object self)

{

 

//this is the response when the button is pressed

Beep()

self.Setelementisenabled("first", false);

self.Setelementisenabled("second", true);

okdialog("You pressed the First Button")

}

 

void button2response(object self)

{

 

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

Beep()

self.Setelementisenabled("first",true);

self.Setelementisenabled("second",false);

okdialog("You pressed the Second Button")

}

 

 

void tvbuttonresponse(object self)

{

 

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

 

okdialog("You pressed the TV button")

}

 

void slitbuttonresponse(object self)

{

 

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

okdialog("You pressed the Slit button")

}

 

}

 

 

// 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)

 

 

// Creates the first button

 

firstButton = DLGCreatePushButton("First Button", "button1response")

dlgenabled(firstbutton,1)

dlgidentifier(firstbutton, "first")

firstbutton.dlgexternalpadding(8,5)

firstbutton.dlginternalpadding(8,0)

box_items.dlgaddelement(firstbutton)

 

// Creates the second button

 

secondButton = DLGCreatePushButton("Second Button", "button2response")

dlgenabled(secondbutton,0)

secondbutton.dlgexternalpadding(8,5)

dlgidentifier(secondbutton, "second")

 

box_items.dlgaddelement(secondbutton)

return box

 

}

 

 

TagGroup MakemoreButtons()

{

 

number true=1

number false=0

 

taggroup gifboxitems

 

TagGroup gifbox = dlgcreatebox(" GIF ", gifboxitems)

gifbox.dlginternalpadding(5,5)

 

rgbimage imgoff := rgbimage("",4,32,32)

rgbnumber vrgb=rgb(10,100,255)

imgoff=vrgb

 

imgoff=dlgmakeraised(imgoff)

 

rgbimage imgon := [32,32]: // the following defines the TEM image

{

 

{53,54,48,45,36,24,31,22,18,21,27,26,31,33,22,50,65,88,116,124,100,107,137,200,244,245,244,236,242,246,246,243},

{40,42,42,44,41,31,33,21,21,18,26,33,66,51,30,40,57,47,80,96,112,128,194,237,244,246,246,242,234,239,241,236},

{40,36,30,36,37,38,31,19,20,22,58,168,102,43,25,39,44,43,60,108,136,124,175,216,244,246,246,246,238,231,233,239},

{20,26,28,30,34,34,28,22,22,33,139,163,109,40,24,29,79,88,122,130,110,115,138,189,242,244,246,246,244,235,236,247},

{21,18,28,24,20,29,54,39,50,162,213,157,78,27,22,40,75,107,150,137,112,152,178,178,231,243,246,246,244,236,242,248},

{21,22,18,26,38,115,184,155,166,226,236,175,62,30,25,54,64,56,97,133,154,188,131,117,152,233,244,246,242,236,247,248},

{19,20,18,33,79,76,86,124,156,224,237,143,61,44,42,60,58,51,44,86,183,156,106,106,131,170,236,245,239,238,248,248},

{18,20,23,63,53,57,75,126,202,240,230,116,80,78,85,94,73,51,52,50,131,136,113,123,149,166,192,236,236,240,248,248},

{16,19,46,104,88,82,108,202,240,242,242,208,148,154,196,216,141,72,55,53,67,112,142,151,168,189,204,234,235,245,248,248},

{16,31,92,159,101,133,182,228,242,245,244,243,241,241,241,241,235,177,116,62,66,87,172,210,216,226,236,239,236,248,248,248},

{24,70,164,208,161,198,204,230,241,246,247,246,246,246,244,244,243,240,228,174,120,98,107,228,242,245,246,236,240,248,249,248},

{71,122,202,227,206,230,230,232,238,247,247,247,248,246,246,246,246,244,237,164,163,152,152,172,243,246,246,236,243,248,249,249},

{126,154,212,197,202,231,235,235,235,244,247,248,248,247,248,247,246,237,208,126,190,144,119,140,238,246,242,235,245,248,249,249},

{192,201,202,204,220,232,236,240,235,237,248,248,248,248,248,247,246,241,198,160,132,113,122,176,244,247,239,237,246,249,249,250},

{225,234,228,228,231,234,236,236,236,235,239,248,248,248,249,248,248,246,214,154,129,118,120,208,246,247,237,239,248,250,250,250},

{206,238,202,196,231,235,237,236,236,234,235,240,248,249,248,248,246,245,229,152,129,122,169,238,244,240,236,242,249,250,250,250},

{207,160,170,190,232,245,247,248,246,239,235,236,236,239,239,238,238,238,235,204,219,227,235,238,237,236,236,242,249,250,250,250},

{161,125,219,227,234,247,248,248,249,248,241,236,236,248,248,248,248,248,248,247,246,247,247,248,248,243,236,240,249,250,250,251},

{98,129,203,211,232,246,247,248,248,248,249,237,236,247,249,249,249,249,249,248,248,249,249,249,249,248,238,239,249,250,250,251},

{168,222,148,87,117,238,247,249,250,250,249,246,236,240,250,249,249,249,250,249,249,248,249,249,250,249,238,238,248,250,251,251},

{156,154,75,59,84,214,247,249,250,250,250,249,239,236,242,246,248,250,250,250,250,250,250,250,250,250,238,238,247,251,251,251},

{118,144,127,107,126,207,247,249,249,250,250,249,240,235,235,235,235,236,237,237,240,239,239,240,240,238,236,236,242,251,251,252},

{106,124,109,125,152,239,248,249,250,250,250,244,236,238,243,243,242,243,243,242,240,240,240,240,240,237,236,237,238,246,251,252},

{95,112,115,174,222,246,248,250,250,250,243,238,243,248,247,247,246,245,242,247,248,249,250,250,250,250,249,242,237,237,247,252},

{97,121,165,216,236,248,249,249,250,241,238,245,247,246,245,237,224,162,122,169,244,248,250,250,251,251,251,251,248,238,238,248},

{95,120,150,201,238,249,249,249,240,238,246,246,244,220,182,122,77,56,84,111,230,248,249,250,251,252,252,252,252,250,240,237},

{98,110,130,184,234,247,246,237,238,244,243,209,168,84,46,31,33,41,76,136,228,246,248,250,251,252,251,253,253,252,252,242},

{81,104,130,168,234,234,234,237,240,202,137,60,28,17,14,21,28,48,86,135,177,239,246,248,250,251,252,252,252,252,252,252},

{102,91,112,215,232,233,236,220,129,53,21,10,6,6,10,20,31,56,82,91,65,74,136,228,249,252,253,253,252,254,253,253},

{127,78,98,199,230,228,170,59,21,10,5,2,2,5,9,18,30,55,81,70,35,30,69,206,248,252,252,253,253,254,254,253},

{124,107,112,186,191,112,43,17,8,4,2,1,2,5,12,22,32,62,81,44,28,30,58,223,248,252,253,253,254,253,254,254},

{74,174,148,141,70,41,24,13,6,4,2,0,1,8,14,29,48,73,86,42,26,33,45,196,249,252,253,254,253,254,254,254}

 

}

 

imgon=dlgmakeraised(imgon)

TagGroup dsbevelbuttonslabel = DLGCreateLabel("TV").DLGAnchor("Center");

 

// This button changes its graphic only while pressed

 

TagGroup dsbevel1 = DLGCreateBevelButton(imgon,imgOff, "tvbuttonresponse");

taggroup button1group=dlggroupitems(dsbevel1,dsbevelbuttonslabel)

 

button1group.dlgtablelayout(1,2,0)

button1group.dlgexternalpadding(10,5)

 

TagGroup dsbevelbuttons2label = DLGCreateLabel("Slit").DLGAnchor("Center");

 

// This button toggles images between on and off states

 

TagGroup dsbevel2 = DLGCreateDualStateBevelButton("dsimage2", imgOn, imgOff, "slitbuttonresponse");

taggroup button2group=dlggroupitems(dsbevel2,dsbevelbuttons2label)

button2group.dlgtablelayout(1,2,0)

button2group.dlgexternalpadding(10,5)

 

taggroup groupedbuttons=dlggroupitems(button1group,button2group)

groupedbuttons.dlgtablelayout(2,1,1)

 

gifboxitems.DLGAddElement(groupedbuttons);

 

return gifbox

}

 

 

// 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 bottom left 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_items.dlgaddelement( MakemoreButtons() );

 

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

dialog_frame.display("Dialog Template");

 

}

 

 

// calls the above function which puts it all together

 

createdialogexample()