How to reload the dialog or the script itself after using the SimpleDialog

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
570295535
Posts: 12
Joined: Sat Feb 04, 2023 9:32 am

How to reload the dialog or the script itself after using the SimpleDialog

Post by 570295535 »

I use SimpleDialog and DoModeless () to create the modeless dialog box, and then when I append or delete a button, I have to manually close script and reopen script .

Is there a function to reload SimpleDialog?Alternatively, there are other ways to reload the script itself?

Using XXX:Run(moho) causes multiple dialog boxes, and the old dialog box does not close.
User avatar
SimplSam
Posts: 1048
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: How to reload the dialog or the script itself after using the SimpleDialog

Post by SimplSam »

There is currently no built-in function to dynamically update the structure of open dialogs - like adding or removing widgets, so a work-around would be to close and reopen the dialog. However - there is currently no built-in mechanism to close dialogs, so ...

Something derived from @Rai Lopez

Add a textlist which sends Cancel when an item is selected.

Code: Select all

  d.cancelTextList = LM.GUI.ImageTextList(0, 1, LM.GUI.MSG_CANCEL)
  d.cancelTextList:AddItem("", false)
  l:AddChild(d.cancelTextList, LM.GUI.ALIGN_LEFT, 0)
Then in your HandleMessage code, you will trigger the cancelTextList by selecting an item to close the dialog, then open a new one.

Code: Select all

  self.cancelTextList:SetSelItem(self.cancelTextList:GetItem(0), false) -- Close
  
  myScript.myDlog = myScriptDialog:new(moho) -- ReCreate
  myScript.myDlog:DoModeless() -- ReOpen
Also ensure that you are using moho 14.1 (latest) as it is a lot more stable with modeless dialogs that 14.0
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
570295535
Posts: 12
Joined: Sat Feb 04, 2023 9:32 am

Re: How to reload the dialog or the script itself after using the SimpleDialog

Post by 570295535 »

SimplSam wrote: Wed Nov 08, 2023 6:10 pm

Code: Select all

  d.close = LM.GUI.ImageTextList(0, 1, LM.GUI.MSG_CANCEL)
  l:AddChild(d.close, LM.GUI.ALIGN_LEFT, 0)

Code: Select all

  self.close:SetSelItem(false) -- Close
  myScript.dlog = nil
  myScript.dlog = myScript:new(moho) -- ReCreate
  myScript.dlog:DoModeless() -- ReOpen
Thank you SimplSam, I have referenced Lukas' LK_LayerFinder script, combined with the code you provided, successfully added new buttons to the control dynamically, but the window coordinates after reloading the script are always in the middle of the screen. I hope the official can add the API for saving the location coordinates of the modeless dialog box, as well as other APIs such as delayed execution.
Post Reply