Scripting Resources for DigitalMicrograph™ |
Example: Panel Functions in Dialogs |
|
Function |
Example code demonstrating the use of panel functions in dialogs. |
Version |
version:20090917, v1.0 |
Author |
D. R. G. Mitchell |
Acknowledgements |
- |
Comments |
Panel functions are useful for modifying the appearance of dialogs on the fly. Think of a panel as one of those ever changing signs you see at sports grounds. Individual layers in panels can hold different fields, buttons etc, and so depending on the dialog context, you can show or hide these objects. Dialogs can be made more compact and intuitive using panels. |
System Requirements |
Should be compatible with all recent versions of DigitalMicrograph. |
Known Issues |
- |
Supported |
Yes |
Included Files |
Main script file. |
Source Code |
// Example script to show how to panels to change the displayed content of dialogs // D. R. G. Mitchell, adminnospam@dmscripting.com (remove the nospam to make this email address work)
// version:20090917, v1.0, Sept 2009
// Panels can be used to change the content of dialogs. Panels can contain multiple layers. // Simply set the content of each layer to contain dialog functions or display information. // Then change which layer of the panel is displayed to change the content of the dialog. // In this example, a push button is used to cycle through a three layer panel, which displays // 'panel 1' , 'panel 2' and 'Panel 3'. Panels can contain dialog objects such as fields, buttons etc. // Here layer 1 contains a an integer field, layer 2 a button which reports the content of that field // and layer 3 a button which displays layer 1.
class CreateButtonDialog : uiframe { void mainbuttonresponse(object self) {
//this is the response when the button is pressed
// Look up the panel and see which value is currently displayed
taggroup panellist=self.lookupelement("panellist") number panelvalue=dlggetvalue(panellist)
// There are three layers so values run from 0-2. Repeated // pushes of the button cycle through the panels 0-1-2-0-1-2 etc
if(panelvalue<2) panelvalue=panelvalue+1 else panelvalue=0 panellist.dlgvalue(panelvalue) return
}
// This is the response from the button on panel 2
void panel2buttonresponse(object self) { // The button on panel 2 gets the value of the field in panel 1
taggroup intfield=self.lookupelement("intfield") number fieldval=dlggetvalue(intfield) okdialog("The value in the field in Panel 1 is : "+fieldval) }
// This is the response from the button on panel 3
void panel3buttonresponse(object self) {
// The button on panel 3 sets the displayed panel layer to panel 1
taggroup panellist=self.lookupelement("panellist") panellist.dlgvalue(0) } }
// this function creates the main 'Change Panel' button. The button's function is to to cycle // through the panels 1-2-3-1-2-3 etc.
taggroup Makebutton() {
// Create the button
TagGroup ExampleButton = DLGCreatePushButton("Change Panel", "mainbuttonresponse") examplebutton.dlgexternalpadding(10,10)
return examplebutton }
// this function creates a panel consisting of three layers, labelled panel 1, 2 and 3.
taggroup makepanel() {
taggroup panellist=dlgcreatepanellist().dlgidentifier("panellist").dlgexternalpadding(10,10)
// The first layer of the panel contains an integer field and a label (Panel 1)
taggroup panel1=dlgcreatepanel() taggroup field=dlgcreateintegerfield(42,5).dlgidentifier("intfield") panel1.dlgaddelement(field)
// The second layer of the panel contains a button, which sources the value // from the integer field in panel 1, and a label panel 2. It is also labelled 'panel 2'.
taggroup panel2=dlgcreatepanel() TagGroup Panel2Button = DLGCreatePushButton("Get Field", "panel2buttonresponse") panel2.dlgaddelement(panel2button)
// Add a button and label to panel 3
taggroup panel3=dlgcreatepanel() TagGroup Panel3Button = DLGCreatePushButton("Go to 1", "panel3buttonresponse") panel3.dlgaddelement(panel3button)
panel1.dlgaddelement(dlgcreatelabel("Panel 1")) panel2.dlgaddelement(dlgcreatelabel("Panel 2")) panel3.dlgaddelement(dlgcreatelabel("Panel 3"))
panellist.dlgaddpanel(panel1) panellist.dlgaddpanel(panel2) panellist.dlgaddpanel(panel3)
panellist.dlgvalue(0)
return panellist }
// 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_items.dlgaddelement( Makepanel() );
object dialog_frame = alloc(CreateButtonDialog).init(dialog) dialog_frame.display("Dialog Template");
}
// calls the above function which puts it all together
createdialogexample()
|