Digitalmicrograph DM脚本-从另一个对话框更新下拉菜单项

问题描述

我正在研究DM脚本,该脚本创建了一种包含一些对话框的技术。 在此脚本中,我试图从另一个对话框中更新一个对话框中的下拉菜单项。

我目前在对话框中有一个按钮,其下拉菜单名为“ update”,它在对话框类中调用了一个名为“ updateDialog”的函数。 此功能删除所有下拉菜单项,然后插入存储在标记列表中的所有项。 它还会更改该对话框中几个按钮的状态。

此更新按钮效果很好。

现在,如果我从另一个对话框中调用此updateDialog函数,则按钮状态将按其应有的方式更改,但下拉菜单不会更新。

有人知道为什么会这样和/或是否有办法使它起作用吗?

谢谢!

示例代码:

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,dropdown,updatebutton,statebutton
        dialog = DLGCreateDialog("second_dialog",dialogItems)
        taggroup initial_items
        dropdown = DLGCreateChoice(initial_items,"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,bOpenByDefault )

    AddCustomTechnique( technique )
}

main()

解决方法

(尚未回答),但需要更长的澄清评论

我正在GMS 3.4.2上测试您的脚本代码,这是我看到的行为,在GMS启动后立即运行脚本(一次):

  1. 添加了自定义技术:
    enter image description
here

  2. 最初显示两个对话框为:
    enter image description
here

  3. 在第二个对话框上单击“更新”下拉列表可切换“状态” 更改”按钮启用/禁用:
    enter image description
here

  4. 分别在第一个对话框中按下“添加下拉项”按钮 时间会添加到下拉中,并且会在以下位置切换“状态更改”按钮 第二个对话框(并显示条目的tagList):
    enter
image description here

这不是预期的行为吗?

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...