Search code examples
drop-down-menudialogrefreshitemsdm-script

Digitalmicrograph DM script - updating pulldown items from another dialog


I am working on a DM script that creates a technique which contains a few dialogs. In this script I am trying to update the pulldown menu items in one dialog from inside another dialog.

I currently have a button inside the dialog with the pulldown menu called "update" which calls a function inside the dialog class that is called "updateDialog". This function removes all pulldown menu items and then inserts all the items stored in a taglist. It also changes the state of a few buttons in that dialog.

This update button works perfectly.

Now if I call this updateDialog function from inside the other dialog, the button states change as they should, but the pulldown menu does not update.

Does anyone know why this happens and/or if there is a way to make this work?

Thanks!

Example code:

taggroup menuitems = newtaglist()
object firstdialog, seconddialog

interface I_seconddialog{
    void updatedropdowndialog(object self);
}

class firstdialog : uiframe{
    void additemresponse (object self){
        number items = menuitems.taggroupcounttags()+1
        menuitems.taggroupinserttagasstring(infinity(), "Created item #"+items)
        menuitems.taggroupopenbrowserwindow(0)
        seconddialog.updatedropdowndialog()
    }

    taggroup createdialog (object self){
        taggroup dialog, dialogitems, additembutton
        dialog = DLGCreateDialog("first_dialog", dialogItems)
        additembutton = DLGCreatePushButton("Add pulldown item", "additemresponse")
        
        dialogitems.dlgaddelement(additembutton)
        return dialog
    }   

    object init (object self){
        return self.super.init( self.createdialog() )
    }
}

class seconddialog : uiframe{
    number isbuttonenabled
    void updatedropdowndialog (object self){
        // Change the state of the state button to show that that does work
        isbuttonenabled = abs(isbuttonenabled-1)
        self.Setelementisenabled("statebutton",isbuttonenabled);
    
        // Empty the dropdown as the menuitems list might be completely different
        taggroup dropdown = self.lookupelement("dropdown")
        taggroup dropdown_items
        dropdown.taggroupgettagastaggroup("Items",dropdown_items)
        dropdown_items.taggroupdeletealltags()  

        // Add the current tags in menuitems to the dropdown
        for(number i=0;i<menuitems.taggroupcounttags();i++){
            string item_name
            menuitems.taggroupgetindexedtagasstring(i,item_name)
            dropdown.dlgaddchoiceitementry(item_name)   
        }
    }

    taggroup createdialog (object self){
        taggroup dialog, dialogitems, dropdown, updatebutton, statebutton
        dialog = DLGCreateDialog("second_dialog", dialogItems)
        taggroup initial_items
        dropdown = DLGCreateChoice(initial_items,0,"dropdownchange").dlgidentifier("dropdown")
        dropdown.dlgaddchoiceitementry("Initial item")
        updatebutton = DLGCreatePushButton("Update dropdown", "updatedropdowndialog")
        statebutton = DLGCreatePushButton("state changes", "stateresponse").dlgidentifier("statebutton")
        
        dialogitems.dlgaddelement(dropdown)
        dialogitems.dlgaddelement(updatebutton)
        dialogitems.dlgaddelement(statebutton)
        return dialog
    }   

    object init (object self){
        isbuttonenabled = 1
        return self.super.init( self.createdialog() )
    }
}

void main(){
    String techniqueName = "Example"
    Image techniqueIcon := RGBImage( "Test icon", 4, 75, 75 )
    techniqueIcon = RGB( icol, irow, iradius )
    object technique = CreateTechnique( techniqueName, techniqueIcon )
    firstdialog = Alloc( firstdialog ).Init()

    String taskName = "First dialog"
    Number taskID = RegisterWorkflowTask( firstdialog, taskName )
    Number bOpenByDefault = 1
    Number bEssential = 0                
    AddWorkflowTask( technique, taskID, bEssential, bOpenByDefault )
    seconddialog = Alloc( seconddialog ).Init()
    
    taskName = "Second dialog"
    taskID = RegisterWorkflowTask( seconddialog, taskName )
    bOpenByDefault = 1
    bEssential = 0                
    AddWorkflowTask( technique, taskID, bEssential, bOpenByDefault )

    AddCustomTechnique( technique )
}

main()

Solution

  • Not an answer (yet), but a longer clarification comment

    I'm testing your script code on GMS 3.4.2 and this is the behavior I see, running the script (once) right after GMS start:

    1. Custom technique is added:
      enter image description
here

    2. It shows two dialogs initially as:
      enter image description
here

    3. Pressing "Update dropdown" on the Second dialog toggles the "state changes" button enabled/disabled:
      enter image description
here

    4. Pressing the "Add pulldown item" button on the First dialog each time adds to the drop-down and toggles the "state changes" button in the Second dialog (and displays the tagList of entries):
      enter
image description here

    Isn't that exactly the intended behavior ?