Using Custom Dialogs

Looking for feedback regarding the use of custom dialogs.

I have recently started looking at using the CustomDialogs. My first dialog was rather simple. It allows the user to input values for an external tool enfuse buttons.

  • Replacing this
  • with this

This is how I implemented it. Does this seem best practice, do you see any issues here? Full script in this thread enfuse buttons.

    var dlg = DOpus.Dlg;
    dlg.window = funcData.func.sourcetab;
    dlg.template = "dialogEnfuse";
    dlg.detach = true;
    
    dlg.Show();
  
    dlg.Control("comboPresets").AddItem("ExposureStackParams");
    dlg.Control("comboPresets").AddItem("FocusStackParams");
    dlg.Control("comboPresets").AddItem("CustomDefaultParams");
    dlg.Control("comboPresets").AddItem("UserDefaultParams");
  
    var closeDialog;
    while (!closeDialog) {
      var msg = dlg.GetMsg();
      if (!msg.result) break;
      
      LogMessage("Msg: " + msg.control + " value: " + msg.value + " event:" + msg.event);

      switch (msg.control) {
        case "comboPresets" :
           PresetSelected(dlg, msg);
           break;
        case "buttonOK" :
           params = DialogClosed(dlg, msg);
           closeDialog = true;
           break;
      } 
    }

    if(!(params))
    {
      LogMessage("Dialog canceled");
      return;
    }

    LogMessage("Return code = " + dlg.result);
    LogMessage("Return value = " + params);

function PresetSelected(dlg, msg) {
  LogMessage("PresetSelected: " + msg.control +":"+ msg.event);
 
  if(msg.control != "comboPresets" || msg.event != "selchange")
    return;
    
  var dialogParams;
  switch (msg.value) {
    case "ExposureStackParams" :
      dialogParams = Script.config.ExposureStackParams;
      break;
    case "FocusStackParams" :
      dialogParams = Script.config.FocusStackParams;
      break;
    case "CustomDefaultParams" :
      dialogParams = Script.config.CustomDefaultParams;
      break;
    case "UserDefaultParams" :
      dialogParams = Script.config.UserDefaultParams;
      break;
  } 

  if(!(dialogParams))
  {
    dialogParams= "--exposure-weight=--saturation-weight=--contrast-weight=--exposure-mu=--soft-mask"
  }

  if(dialogParams)
  {
    var splitParams = dialogParams.split("--");
    for (var i = 0; i < splitParams.length; i++) {
      DOpus.Output(splitParams[i]);
      var splitParam = splitParams[i].split("=");
      switch (splitParam[0]) {
        case "exposure-weight" :
          dlg.Control("exposure").value = splitParam[1];
          break;
        case "saturation-weight" :
          dlg.Control("saturation").value = splitParam[1];
          break;
        case "contrast-weight" :
          dlg.Control("contrast").value = splitParam[1];
          break;
        case "exposure-mu" :
          dlg.Control("gaussion").value = splitParam[1];
          break;
        case "soft-mask" :
          dlg.Control("mask").value = 0;
          break;
        case "hard-mask" :
          dlg.Control("mask").value = 1;
          break;
      } 
    }
  }
}

function DialogClosed(dlg, msg) {
  var result = BuildCommand("exposure-weight", dlg.Control("exposure").value)
             + BuildCommand("saturation-weight", dlg.Control("saturation").value)
             + BuildCommand("contrast-weight", dlg.Control("contrast").value)
             + BuildCommand("exposure-mu", dlg.Control("gaussion").value)
             + ((dlg.Control("mask").value == 1) ? " --hard-mask" : " --soft-mask");
  LogMessage("selected: " + result + " || " + dlg.Control("mask").value);
  return result;
}

My next dialog will be to create a UI for editing custom columns specific to a script. I would like to have something similar to the rename dialog. Where down the left is a list of the columns and to the right are the settings for them. This relates to this thread configuring dynamic-columns.

Feedback appreciated

The code looks fine from a quick look through it.

Couple of things I cant get working. (different script to above).

add icon to DialogListItem
I was not able to set the icon of a DialogListItem.
I tried this:

    var lstItem = dlg.Control("configurationsList");
    for(var i = 0; i < localConfig.tools.length; ++i) {
      var location = lstItem.AddItem(localConfig.tools[i].product);
      var item = lstItem.GetItemAt(location);
      //item.icon = localConfig.tools[i].icon
      //item.icon = "ExternalCompare:Araxis"
      //item.icon = ".txt";
    }

Regardless I get an error of A method was called unexpectedly (0x8000ffff). I want to set it to the icon that I provide in the buttons I.E. ExternalCompare:Araxis.

update static text
I wanted to update the value of a Static Text object.
I tried this

dlg.Control("myStaticTextName").value = "the updated text"

Didnt error but does not work.

Each new question would be better as a separate thread, so people who run into the same problem can find the answer more easily.

Please also post the full script(s). The code fragment looks OK to me but I can't try it out or see which types of dialog resources it is acting on without the full thing.

As admin, you can split this conversation into a separate thread - just so you know this useful feature of Discourse.

Will do, I have created a post specific to adding a images DialogListItem.

I am well aware of that, thank you. But you cannot split a single post in two very easily, and you cannot make extra details like the full script appear from thin air. :slight_smile:

1 Like