DoLayout event
Posted: Sat Apr 27, 2024 7:45 am
Changing selected layer should fire DoLayout event in the tool script, right? But sometimes this is not happening, anyone knows why?
Code: Select all
local drawingToolsNonZero = MOHO.MohoGlobals.DisableDrawingToolsNonZero
if not drawingToolsNonZero then
MOHO.MohoGlobals.DisableDrawingToolsNonZero = true
end
local frame = moho.frame
if frame == 0 then
moho:SetCurFrame(1)
moho:SetCurFrame(0)
elseif frame ~= 0 then
moho:SetCurFrame(0)
moho:SetCurFrame(frame)
end
if not drawingToolsNonZero then
MOHO.MohoGlobals.DisableDrawingToolsNonZero = drawingToolsNonZero
end
Code: Select all
-- **************************************************
-- General information about this script
-- **************************************************
ScriptName = "TestScript"
TestScript = {}
function TestScript:Name()
return 'Name'
end
function TestScript:Version()
return 'Version'
end
function TestScript:UILabel()
return 'UILabel'
end
function TestScript:Creator()
return 'Creator'
end
function TestScript:Description()
return 'Description'
end
-- **************************************************
-- Is Relevant / Is Enabled
-- **************************************************
function TestScript:IsRelevant(moho)
print('TestScript:IsRelevant')
return true
end
function TestScript:IsEnabled(moho)
print('TestScript:IsEnabled')
return true
end
-- **************************************************
-- Variables
-- **************************************************
local dialog_table = {}
-- **************************************************
-- Events
-- **************************************************
function TestScript:OnMouseDown(moho, mouseEvent)
print('TestScript:OnMouseDown')
end
function TestScript:DoLayout(moho, layout)
print('TestScript:DoLayout')
local dialog = LM.GUI.SimpleDialog('Dialog', dialog_table)
local dialog_layout = dialog:GetLayout()
local button = LM.GUI.Button('DoLayout', MOHO.MSG_BASE)
dialog_layout:AddChild(button, LM.GUI.ALIGN_FILL, 0)
local popup = LM.GUI.PopupDialog('Popup', true, 0)
popup:SetDialog(dialog)
layout:AddChild(popup, LM.GUI.ALIGN_LEFT, 0)
end
function TestScript:UpdateWidgets(moho)
print('TestScript:UpdateWidgets')
end
function dialog_table:HandleMessage(msg)
print('dialog_table:HandleMessage')
local helper = MOHO.ScriptInterfaceHelper:new_local()
local moho = helper:MohoObject()
local drawingToolsNonZero = MOHO.MohoGlobals.DisableDrawingToolsNonZero
if not drawingToolsNonZero then
MOHO.MohoGlobals.DisableDrawingToolsNonZero = true
end
local frame = moho.frame
if frame == 0 then
moho:SetCurFrame(1)
moho:SetCurFrame(0)
elseif frame ~= 0 then
moho:SetCurFrame(0)
moho:SetCurFrame(frame)
end
if not drawingToolsNonZero then
MOHO.MohoGlobals.DisableDrawingToolsNonZero = drawingToolsNonZero
end
helper:delete()
end
Code: Select all
-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************
ScriptName = "MR_TestScript"
-- **************************************************
-- General information about this script
-- **************************************************
MR_TestScript = {}
function MR_TestScript:Name()
return 'MR Test Script'
end
function MR_TestScript:Version()
return '1.0'
end
function MR_TestScript:UILabel()
return 'MR Test Script'
end
function MR_TestScript:Creator()
return 'Eugene Babich'
end
function MR_TestScript:Description()
return ''
end
-- **************************************************
-- Is Relevant / Is Enabled
-- **************************************************
function MR_TestScript:IsRelevant(moho)
return true
end
function MR_TestScript:IsEnabled(moho)
return true
end
-- **************************************************
-- Keyboard/Mouse Control
-- **************************************************
function MR_TestScript:OnMouseDown(moho, mouseEvent)
end
function MR_TestScript:OnMouseMoved(moho, mouseEvent)
end
function MR_TestScript:OnMouseUp(moho, mouseEvent)
end
function MR_TestScript:OnKeyUp(moho, keyEvent)
end
-- **************************************************
-- Tool Panel Layout
-- **************************************************
MR_TestScript.optionalButton = true
MR_TestScript.REDRAW_LAYOUT = MOHO.MSG_BASE
MR_TestScript.OPTIONAL_BUTTON = MOHO.MSG_BASE + 1
function MR_TestScript:DoLayout(moho, layout)
print('TestScript:DoLayout')
self.redrawLayoutButton = LM.GUI.Button('Redraw Layout', self.REDRAW_LAYOUT)
layout:AddChild(self.redrawLayoutButton, LM.GUI.ALIGN_LEFT, 0)
if self.optionalButton then
self.optionalButtonButton = LM.GUI.Button('Optional Button', self.OPTIONAL_BUTTON)
layout:AddChild(self.optionalButtonButton, LM.GUI.ALIGN_LEFT, 0)
end
end
function MR_TestScript:HandleMessage(moho, view, msg)
if msg == self.REDRAW_LAYOUT then
self.optionalButton = not self.optionalButton
local drawingToolsNonZero = MOHO.MohoGlobals.DisableDrawingToolsNonZero
if not drawingToolsNonZero then
MOHO.MohoGlobals.DisableDrawingToolsNonZero = true
end
local frame = moho.frame
if frame == 0 then
moho:SetCurFrame(1)
moho:SetCurFrame(0)
elseif frame ~= 0 then
moho:SetCurFrame(0)
moho:SetCurFrame(frame)
end
if not drawingToolsNonZero then
MOHO.MohoGlobals.DisableDrawingToolsNonZero = drawingToolsNonZero
end
elseif msg == self.OPTIONAL_BUTTON then
end
end
Code: Select all
-- **************************************************
-- General information about this script
-- **************************************************
ScriptName = "TestScript"
TestScript = {}
function TestScript:Name()
return 'Name'
end
function TestScript:Version()
return 'Version'
end
function TestScript:UILabel()
return 'UILabel'
end
function TestScript:Creator()
return 'Creator'
end
function TestScript:Description()
return 'Description'
end
-- **************************************************
-- Is Relevant / Is Enabled
-- **************************************************
function TestScript:IsRelevant(moho)
return true
end
function TestScript:IsEnabled(moho)
return true
end
-- **************************************************
-- Variables
-- **************************************************
local dialog_table = {}
local suspend_update_widgets = false
local suspend_do_layout = false
-- **************************************************
-- Events
-- **************************************************
function TestScript:OnMouseDown(moho, mouseEvent)
end
function TestScript:DoLayout(moho, layout)
if suspend_do_layout == true then return end
print('TestScript:DoLayout')
local dialog = LM.GUI.SimpleDialog('Dialog', dialog_table)
local dialog_layout = dialog:GetLayout()
local button = LM.GUI.Button('DoLayout', MOHO.MSG_BASE)
dialog_layout:AddChild(button, LM.GUI.ALIGN_FILL, 0)
local popup = LM.GUI.PopupDialog('Popup', true, 0)
popup:SetDialog(dialog)
layout:AddChild(popup, LM.GUI.ALIGN_LEFT, 0)
end
function TestScript:UpdateWidgets(moho)
if suspend_update_widgets == true then return end
print('TestScript:UpdateWidgets')
end
function dialog_table:HandleMessage(msg)
suspend_update_widgets = true
suspend_do_layout = true
local helper = MOHO.ScriptInterfaceHelper:new_local()
local moho = helper:MohoObject()
local drawingToolsNonZero = MOHO.MohoGlobals.DisableDrawingToolsNonZero
if not drawingToolsNonZero then
MOHO.MohoGlobals.DisableDrawingToolsNonZero = true
end
local temp_layer = nil
if moho.layer:LayerType() == MOHO.LT_GROUP then temp_layer = moho:CreateNewLayer(MOHO.LT_UNKNOWN, false) end
local frame = moho.frame
if frame == 0 then
moho:SetCurFrame(1)
if temp_layer == nil then suspend_do_layout = false end
moho:SetCurFrame(0)
elseif frame ~= 0 then
moho:SetCurFrame(0)
if temp_layer == nil then suspend_do_layout = false end
moho:SetCurFrame(frame)
end
suspend_do_layout = false
if temp_layer ~= nil then moho:DeleteLayer(temp_layer) end
suspend_update_widgets = false
if not drawingToolsNonZero then
MOHO.MohoGlobals.DisableDrawingToolsNonZero = drawingToolsNonZero
end
helper:delete()
end
I don't want to iterate over ALL layers, I need a function to find first match and exit the loop.