Update UI

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
MehdiZangenehBar
Posts: 50
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Update UI

Post by MehdiZangenehBar »

is it possible to add item to the toolbar, outside DoLayout event? on UpdateWidget?
User avatar
synthsin75
Posts: 10007
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Update UI

Post by synthsin75 »

You have to get it to reevaluate the DoLayout function.
I do this in my switch icons script by jumping to/from frame zero.
User avatar
MehdiZangenehBar
Posts: 50
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Re: Update UI

Post by MehdiZangenehBar »

Are you sure changing frame to zero will trigger DoLayout?

Code: Select all

-- **************************************************
-- General information about this script
-- **************************************************

ScriptName = "Test_Script"

Test_Script = {}

function Test_Script:Name()
	return 'Test Script'
end

function Test_Script:Version()
	return '1.0'
end

function Test_Script:UILabel()
	return 'Test Script'
end

function Test_Script:Creator()
	return 'Test'
end

function Test_Script:Description()
	return 'Test'
end


-- **************************************************
-- Is Relevant / Is Enabled
-- **************************************************

function Test_Script:IsRelevant(moho)
	print('IsRelevant')
	return true
end

function Test_Script:IsEnabled(moho)
	print('IsEnabled')
	return true
end

-- **************************************************
-- Events
-- **************************************************

function Test_Script:OnMouseDown(moho, mouseEvent)
	print('OnMouseDown')
end

function Test_Script:UpdateWidgets(moho)
	print('UpdateWidgets')
end

function Test_Script:HandleMessage(msg)
	print('HandleMessage')
end

function Test_Script:DoLayout(moho, layout)
	print('DoLayout')

	local simple_dialog = LM.GUI.SimpleDialog('', {})
	local popup_dialog = LM.GUI.PopupDialog('Test', true, 0)
	popup_dialog:SetDialog(simple_dialog)
	layout:AddChild(popup_dialog, LM.GUI.ALIGN_LEFT, 0)

end
User avatar
MehdiZangenehBar
Posts: 50
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Re: Update UI

Post by MehdiZangenehBar »

And I don't know where is your script.
User avatar
synthsin75
Posts: 10007
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Update UI

Post by synthsin75 »

Here's the script: viewtopic.php?t=34078

At line 596, in the HandleMessage function, I do this:

Code: Select all

	if (msg == self.UPDATE or msg == self.ALT_UPDATE or msg == self.DELETE) then
		local frame = moho.frame
		if (frame == 0) then
			moho:SetCurFrame(1)
		else
			moho:SetCurFrame(0)
		end
		moho:SetCurFrame(frame)
	end
User avatar
MehdiZangenehBar
Posts: 50
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Re: Update UI

Post by MehdiZangenehBar »

I run your script and still changing layer selection will not update the UI.
However your solution works in updatewidgets for me. nice trick, thanks!
User avatar
MehdiZangenehBar
Posts: 50
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Re: Update UI

Post by MehdiZangenehBar »

I did some other test and realized your code dosn't work when we change from group to another group. So I mixed with the layer creation and deletion:

Code: Select all

			local current_frame = moho.frame
			moho:SetCurFrame(0)
			local temp_layer = moho:CreateNewLayer(MOHO.LT_SWITCH, false)
			moho:SetCurFrame(1)
			moho:SetCurFrame(0)
			moho:DeleteLayer(temp_layer)
			moho:SetCurFrame(current_frame)
User avatar
synthsin75
Posts: 10007
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Update UI

Post by synthsin75 »

Yeah, I have a note in the code about group layer selections. I believe that problem was introduced in a later version of Moho, after I initially wrote the script.
I'll have to see about incorporating your layer creation hack.

Thanks.
User avatar
MehdiZangenehBar
Posts: 50
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Re: Update UI

Post by MehdiZangenehBar »

Yea, and I created a boolean flag to prevent dependency loop and prevent UpdateWidget- DoLayout events call himself multiple times.
Another improvement would be to check the layer type and create different layer type to force the update.
Post Reply