Building GUIs With Fusion's UI Manager

User avatar
SirEdric
Fusionator
Posts: 2405
Joined: 10 years ago
Real name: Eric Westphal
Been thanked: 6 times
Contact:

Re: Building GUIs With Fusion's UI Manager

#16

Unread post by SirEdric »

Hi Andrew.

Fantastic examples. Thanks a lot.

Based on your tutorials I added some functions (most of them utterly useless...:-))
mainly to get a hang on how to read or set the states of checkboxes, buttons, etc.

Code: Select all

    local ui = fu.UIManager
    local disp = bmd.UIDispatcher(ui)
    local width,height = 400,400

function rgbToHex(rgb)
	hexadecimal = '0x'

	for key, value in pairs(rgb) do
		local hex = ''

		while(value > 0)do
			local index = math.fmod(value, 16) + 1
			value = math.floor(value / 16)
			hex = string.sub('0123456789abcdef', index, index) .. hex			
		end

		if(string.len(hex) == 0)then
			hex = '00'

		elseif(string.len(hex) == 1)then
			hex = '0' .. hex
		end

		hexadecimal = hexadecimal .. hex
	end
	print(hexadecimal)
	return hexadecimal
end

    win = disp:AddWindow({
      ID = 'MyWin',
      WindowTitle = 'My First Window',
      Geometry = { 100, 100, width, height },
      Spacing = 10,
     
      ui:VGroup{
        ID = 'root',
       
        -- Add your GUI elements here:
        ui:HGroup{
			Margin = 20, -- defines left/right margin
			ui:Button{ ID = 'B', Text = 'The Button Label' },
			ui:Button{ ID = 'C', Text = 'The Other Button' },
        },
		
		-- Add your GUI elements here:
        ui:HGroup{
			Margin = 20, -- defines left/right margin
			ui:CheckBox{ ID = 'D', Text = 'The Checkbox Label' },
        },
		
		-- Add your GUI elements here:
        ui:HGroup{
			Margin = 10, -- defines left/right margin
			ui:ColorPicker{ ID = 'Color' },
        },
		
	    ui:HGroup{
			Margin = 10, -- defines left/right margin
			ui:Label{ ID = 'L', Text = 'This is a Label', Alignment = { AlignHCenter = true, AlignTop = true }, },
			ui:Label{ ID = 'L2', Text = 'This is another Label', Alignment = { AlignHCenter = true, AlignTop = true }, },
        },
		
      },
    })
     
	 clicks = 0 
	 choices = {"Don't click him..", "You never listen, do you?", "Seriously?", "You did it again" }
    -- The window was closed
    function win.On.MyWin.Close(ev)
        disp:ExitLoop()
    end
     
    -- Add your GUI element based event functions here:
    itm = win:GetItems()
     
    function win.On.B.Clicked(ev)
      print('Button A Clicked')
        disp:ExitLoop()
    end
	
	function win.On.C.Clicked(ev)
      print('Button B Clicked')
        --disp:ExitLoop()
		choice = clicks%4 + 1
		print("choice: " .. choice)
		itm.B.Text = choices[choice]
		clicks = clicks + 1
		print(itm.Color.Color.R)
		--dump(itm.Color.Color)
		itm.L.Text = "R: " .. string.format("%.3f",itm.Color.Color.R) .. " | G: " .. string.format("%.3f",itm.Color.Color.G) .. " | B: " .. string.format("%.3f",itm.Color.Color.B)
		myRgb = {math.floor(itm.Color.Color.R*256), math.floor(itm.Color.Color.G*256), math.floor(itm.Color.Color.B*256)}
		rgbToHex(myRgb) -- triggers grbToHex function correctly
		itm.L2.Text = "Hex: " .. hexadecimal
    end
	
	function win.On.D.Clicked(ev)
		theState = itm.D.CheckState
		print(theState)
		if theState == "Checked" then
			itm.D.Text = "Gosh, I am HOT!"
		else
			itm.D.Text = "How boring..."
		end
	end
	
	function win.On.Color.changeColor(ev)
      print('Did some color')
    end
	

	
    win:Show()
    disp:RunLoop()
    win:Hide()
	
I didn't manage though to catch any "ColorHasBeenChanged" event for the ColorSlider.
While looking up checkbox in the QT documentation helped, neither "colorSelected" nor "currentColorChanged" seems to yield any event..

Code: Select all

function win.On.Color.changeColor(ev)
      print('Did some color')
end

User avatar
miaz3
Fusioneer
Posts: 238
Joined: 10 years ago
Location: Angoulême / France
Real name: Jérémy Bepoix

Re: Building GUIs With Fusion's UI Manager

#17

Unread post by miaz3 »

Excellent work, thank to share all of this !

User avatar
SirEdric
Fusionator
Posts: 2405
Joined: 10 years ago
Real name: Eric Westphal
Been thanked: 6 times
Contact:

Re: Building GUIs With Fusion's UI Manager

#18

Unread post by SirEdric »

Actually...similar to the ColorSlider,
what's the trick to determine if a ComboBox has been changed and what it's current value is?

Cheers.
Eric.

User avatar
AndrewHazelden
Fusius Of Borg
Posts: 2605
Joined: 10 years ago
Location: West Dover, Nova Scotia, Canada
Has thanked: 4 times
Been thanked: 18 times
Contact:

Using the ComboBox Control

#19

Unread post by AndrewHazelden »

SirEdric wrote:Actually...similar to the ColorSlider,
what's the trick to determine if a ComboBox has been changed and what it's current value is?

Cheers.
Eric.
The way to detect a ComboBox change is with the event "function win.On.MyComboBox.CurrentIndexChanged(ev)".

You can read the current ComboBox enum style integer value with "itm.MyComboBox.CurrentIndex". This CurrentIndex value starts with the first item in the menu having a value of 0.


Try this example:

Code: Select all

    local ui = fu.UIManager
    local disp = bmd.UIDispatcher(ui)
    local width,height = 400,100
     
    win = disp:AddWindow({
      ID = 'MyWin',
      WindowTitle = 'My First Window',
      Geometry = {100, 100, width, height},
      Spacing = 10,
     
      ui:VGroup{
        ID = 'root',
       
        -- Add your GUI elements here:
        ui:ComboBox{ID = 'MyCombo', Text = 'Combo Menu'},
      },
    })
     
    -- The window was closed
    function win.On.MyWin.Close(ev)
        disp:ExitLoop()
    end
     
    -- Add your GUI element based event functions here:
    itm = win:GetItems()
     
    -- Add the items to the ComboBox menu
    itm.MyCombo:AddItem('Apple')
    itm.MyCombo:AddItem('Banana')
    itm.MyCombo:AddItem('Cherry')
    itm.MyCombo:AddItem('Orange')
    itm.MyCombo:AddItem('Mango')
    itm.MyCombo:AddItem('Kiwi')
     
    -- This function is run when a user picks a different setting in the ComboBox control
    function win.On.MyCombo.CurrentIndexChanged(ev)
      if itm.MyCombo.CurrentIndex == 0 then
        -- Apple
        print('[' .. itm.MyCombo.CurrentText .. '] Lets make an apple crisp dessert.')
      elseif itm.MyCombo.CurrentIndex == 1 then
        -- Banana
        print('[' .. itm.MyCombo.CurrentText .. '] Lets make a banana split with ice cream.')
      elseif itm.MyCombo.CurrentIndex == 2 then
        -- Cherry
        print('[' .. itm.MyCombo.CurrentText .. '] Lets make some cherry tarts.')
      elseif itm.MyCombo.CurrentIndex == 3 then
        -- Orange
        print('[' .. itm.MyCombo.CurrentText .. '] Lets peel an orange and have sliced orange boats.')
      elseif itm.MyCombo.CurrentIndex == 4 then
        -- Mango
        print('[' .. itm.MyCombo.CurrentText .. '] Lets eat cubed mango chunks with yoghurt.')
      elseif itm.MyCombo.CurrentIndex == 5 then
        -- Kiwi
        print('[' .. itm.MyCombo.CurrentText .. '] Lets have a fresh Kiwi snack.')
      end
    end
     
    win:Show()
    disp:RunLoop()
    win:Hide()
Last edited by AndrewHazelden 7 years ago, edited 1 time in total.

User avatar
SirEdric
Fusionator
Posts: 2405
Joined: 10 years ago
Real name: Eric Westphal
Been thanked: 6 times
Contact:

Re: Building GUIs With Fusion's UI Manager

#20

Unread post by SirEdric »

Ahhh...thanks mate!
I was soooo close....the page I found on QT Elements said MyComboBox.currentIndexChanged(ev)
(with the first "c" being lower rather than capital....:-))

And with the same capital "C" even
print(itm.MyCombo.CurrentText)
works....


Cheers.

Eric.

User avatar
AndrewHazelden
Fusius Of Borg
Posts: 2605
Joined: 10 years ago
Location: West Dover, Nova Scotia, Canada
Has thanked: 4 times
Been thanked: 18 times
Contact:

Re: Building GUIs With Fusion's UI Manager

#21

Unread post by AndrewHazelden »

Hi Eric.

I updated the "Creating UI Manager based Windows and GUI Elements" post by adding examples on how to read the current ComboBox, Checkbox settings. I also added new examples for Sliders, Tree, TextEdit, and LineEdit fields.

At this point in time I haven't figured out how to read a DoubleSpinBox value, and don't know what event is triggered when a ColorPicker is changed.

Edit: You can read the current value of a DoubleSpinBox with:

Code: Select all

function win.On.MySpinner.ValueChanged(ev)
	print('[DoubleSpinBox Value] '.. itm.MySpinner.Value)
end
I'm writing up some notes now that explain how you can monitor actions that happen in your Fusion composite using AddNotify() which is a really powerful feature of the UI Manager system.
Last edited by AndrewHazelden 7 years ago, edited 2 times in total.

User avatar
SirEdric
Fusionator
Posts: 2405
Joined: 10 years ago
Real name: Eric Westphal
Been thanked: 6 times
Contact:

Re: Building GUIs With Fusion's UI Manager

#22

Unread post by SirEdric »

Hey Andrew.

QL! Thanks a bunch mate.

Eric.

User avatar
AndrewHazelden
Fusius Of Borg
Posts: 2605
Joined: 10 years ago
Location: West Dover, Nova Scotia, Canada
Has thanked: 4 times
Been thanked: 18 times
Contact:

Fusion Diagnostic Tool

#23

Unread post by AndrewHazelden »

Overview:
This Fusion Lua script works on Windows/Mac/Linux and allows you to generate a Fusion centric diagnostics report in HTML format. The script uses a new UI Manager based GUI in Fusion 8.2.1 and Fusion 9 to show the results with styled text.

Download
Fusion Diagnostics Tool.lua
Screenshot
fusion-diagnostics-tool.png
Installation:
Step 1. Copy the "Fusion Diagnostics Tool.lua" script to your Fusion user preferences "Scripts/Comp/" folder.

Step 2. Once the script is copied into the "Scripts/Comp/" folder you can then run it from inside Fusion's GUI by going to the Script menu and selecting the "Fusion Diagnostics Tool" item.

Step 3. You can click the "View in Webbrowser" button to send the HTML report to your default HTML viewing program (typically either: FireFox/Chrome/Safari/Internet Explorer).
You do not have the required permissions to view the files attached to this post.

User avatar
PeterLoveday
Fusioneer
Posts: 225
Joined: 10 years ago

Re: Building GUIs With Fusion's UI Manager

#24

Unread post by PeterLoveday »

Most UI controls support more than one event; but they usually only enable one by default, for efficiency. Additional events may be set by specifying an Events table. Note that if you do specify an Events table, you must include the default event if you still want it.

eg:

Code: Select all

	ui:ComboBox{
		ID = "MyCombo",
		...
		Events = { CurrentIndexChanged = true, Activated = true },
	}

function win.On.MyCombo.CurrentIndexChanged(ev)
	...
end

function win.On.MyCombo.Activated(ev)
	...
end

Note that the 'ev' parameter to the event handler function contains general info for all events, and specific info such as current value or state for many events.

Supported Events for various control types (* denotes events that are enabled by default):
  • Button:
    • Clicked *
      Toggled
      Pressed
      Released
  • CheckBox:
    • Clicked *
      Toggled
      Pressed
      Released
      StateChanged
  • ColorPicker:
    • ColorChanged *
  • ComboBox:
    • EditTextChanged
      Activated
      ActivatedText
      Highlighted
      HighlightedText
      CurrentIndexChanged *
      CurrentIndexChangedText
      CurrentTextChanged
      TextChanged
      TextEdited
      CursorPositionChanged
      ReturnPressed
      EditingFinished
      SelectionChanged
  • DoubleSpinBox:
    • EditingFinished
      ValueChanged *
  • LineEdit:
    • TextChanged *
      TextEdited
      CursorPositionChanged
      ReturnPressed
      EditingFinished
      SelectionChanged
  • Slider:
    • ValueChanged *
      SliderMoved
      ActionTriggered
      SliderPressed
      SliderReleased
      RangeChanged
  • SpinBox:
    • EditingFinished
      ValueChanged *
  • TabBar:
    • CurrentChanged *
      CloseRequested
      TabMoved
      TabBarClicked
      TabBarDoubleClicked
  • TextEdit:
    • TextChanged *
      CursorPositionChanged
      SelectionChanged
  • Tree:
    • ItemPressed
      ItemClicked *
      ItemDoubleClicked
      ItemActivated
      ItemEntered
      ItemChanged
      ItemExpanded
      ItemCollapsed
      CurrentItemChanged
      ItemSelectionChanged
  • Window:
    • Close *

User avatar
SirEdric
Fusionator
Posts: 2405
Joined: 10 years ago
Real name: Eric Westphal
Been thanked: 6 times
Contact:

Re: Building GUIs With Fusion's UI Manager

#25

Unread post by SirEdric »

Brilliant! Thanks for the summary mate!

User avatar
AndrewHazelden
Fusius Of Borg
Posts: 2605
Joined: 10 years ago
Location: West Dover, Nova Scotia, Canada
Has thanked: 4 times
Been thanked: 18 times
Contact:

Fusion RSS Headlines Script

#26

Unread post by AndrewHazelden »

The "Fusion RSS Headlines.lua" script runs inside of the Fusion 8.2.1/Fusion 9 on MacOS and uses the Lua-Feeds module to display live RSS news feeds. The GUI for the RSS reader script is based upon a ui:Tree layout in the new UI Manager system.

At this point in time the "Fusion RSS Headlines.lua" script only works with Fusion on MacOS since the Linux and Windows based Lua "luaexpat", "luasocket", and "luasec" module installation instructions have not been prepared or tested.

Screenshot
fusion-rss-reader.png
Download
Fusion-RSS-Headlines.zip
Installation

MacOS Install Steps (done via the Terminal.app)

Step 1. Add the Brew package manager from https://brew.sh/:

Code: Select all

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Step 2. Use Brew to install wget and lua5.1 with https support:

Code: Select all

brew install wget lua51 luajit pcre openssl
Step 3. Add the luarocks package manager:

Code: Select all

wget https://luarocks.org/releases/luarocks-2.4.1.tar.gz
tar zxpf luarocks-2.4.1.tar.gz
cd luarocks-2.4.1
./configure; sudo make bootstrap
Step 4. Use luarocks to install the luasockets, luaexpat, and luasec modules:

Code: Select all

sudo luarocks install luaexpat
sudo luarocks install luasocket
sudo luarocks install luasec OPENSSL_DIR=/usr/local/opt/openssl
Step 5. Open the lua library folders once so you know where they are for the future:

Code: Select all

open "/usr/local/lib/lua/5.1/"
open "/usr/local/share/lua/5.1/"
Step 6. Install the Fusion RSS Headlines Lua scripts:

Copy the "install/Scripts/Comp/Fusion RSS Headlines.lua" script to the Fusion 8.2.1+ user prefs "Scripts/Comp/" folder.

Copy the contents of the "install/share/lua/5.1/" folder to the "/usr/local/share/lua/5.1/" folder. You might have to change the folder permissions so you have write access to the folder.

Step 7. In Fusion run the Script > Fusion RSS Headlines menu item to open the RSS reader.

Edit: To use this script with Resolve 15 you might have to also copy the Lua module files from the brew install path here into your Resolve Fusion user prefs LuaModules:/ PathMap location. You can open the folder that holds the files you need to copy using:

Code: Select all

open "/usr/local/lib/lua/5.1/"
open "/usr/local/share/lua/5.1/"
You do not have the required permissions to view the files attached to this post.
Last edited by AndrewHazelden 6 years ago, edited 1 time in total.

User avatar
miaz3
Fusioneer
Posts: 238
Joined: 10 years ago
Location: Angoulême / France
Real name: Jérémy Bepoix

Re: Building GUIs With Fusion's UI Manager

#27

Unread post by miaz3 »

Hehe,
Since the beginning of this thread, it is a gold mine,
Is too hard for you to open Firefox then go on WSL ? :P

In any case it is a very good idea, thank you for sharing it !

User avatar
AndrewHazelden
Fusius Of Borg
Posts: 2605
Joined: 10 years ago
Location: West Dover, Nova Scotia, Canada
Has thanked: 4 times
Been thanked: 18 times
Contact:

Re: Building GUIs With Fusion's UI Manager

#28

Unread post by AndrewHazelden »

miaz3 wrote:Hehe,
Is too hard for you to open Firefox then go on WSL ? :P

In any case it is a very good idea, thank you for sharing it !
It was mainly a proof of concept Lua demo that showed live data being loaded from an internet connection into a Fusion compositing session. This kind of approach of using Lua modules for network access would let you connect Fusion to TCP or UDP based data sources.

In the RSS Reader script you can actually load in a lot more sites then just WSL when you click on the the ComboControl . :D
fusion-rss-reader-data-sources.png
You do not have the required permissions to view the files attached to this post.

User avatar
AndrewHazelden
Fusius Of Borg
Posts: 2605
Joined: 10 years ago
Location: West Dover, Nova Scotia, Canada
Has thanked: 4 times
Been thanked: 18 times
Contact:

List Input Control Names

#29

Unread post by AndrewHazelden »

The "List Input Control Names" UI Manager script is based upon Chad's Lua script for getting input control names:
custom tool as bg from image

Overview:
This script is a Fusion Lua based UI Manager example that works in Fusion 8.2.1 and Fusion 9. The example displays a list of the input control names for the currently selected node in a ui:Tree view.

You can click on any of the input control name items in the list and the expression value will be copied to your clipboard.

The "ui:AddNotify('Comp_Activate_Tool', comp)" command is used to track the changing node selection in the flow area for the current comp. This AddNotify event runs the function disp.On.Comp_Activate_Tool(ev) which automatically updates the tree view when you select a new node.
ui-manager-list-input-control-names.png
Download
List Input Control Names.lua
Installation:
Step 1. Copy the "List Input Control Names.lua" script to your Fusion user preferences "Scripts/Comp/" folder.

Step 2. Select a node in the Fusion Flow area.

Step 3. Go to the Script menu and select the "List Input Control Names" item.

Notes:
For more details on reading node inputs and outputs check out:
https://www.steakunderwater.com/VFXPedi ... utput_List
You do not have the required permissions to view the files attached to this post.

User avatar
AndrewHazelden
Fusius Of Borg
Posts: 2605
Joined: 10 years ago
Location: West Dover, Nova Scotia, Canada
Has thanked: 4 times
Been thanked: 18 times
Contact:

Using AddNotify() in Fusion to Respond to Actions

#30

Unread post by AndrewHazelden »

Th UI Manager system in Fusion 8.2.1 and Fusion 9 has a neat action system that lets you respond to events that happen in Fusion as an artist is using the GUI and building a comp.

What Actions are Available in Fusion?

The following snippet of Lua code can be used to list all of the actions that are available in your copy of Fusion 8.2.1 or Fusion 9:
Code: [Select all] [Expand/Collapse] [Download] (getactions.lua)
  1. -- List all of the actions available in Fusion
  2. local act = fu.ActionManager:GetActions()
  3. for i,v in ipairs(act) do
  4.   if not v:Get('Parent') then
  5.     print(v.ID)
  6.   end
  7. end

In Fusion 9 I get the following list of actions back when I run the Lua code snippet above. This list was sorted afterwards for clarity.

Code: Select all

AddSetting
AddTool
App_About
App_Copy
App_CustomizeHotkeys
App_CustomizeToolBars
App_Cut
App_Delete
App_Exit
App_Help
App_NewImageView
App_OnlyActiveComp
App_Paste
App_PasteSettings
App_SelectAll
App_ShowUI
Bin_Icon_Size
Bin_New_Folder
Bin_New_Item
Bin_New_Reel
Bin_Show_Checker
Bin_View_Mode
Bins_Delete
Bins_Mode_Exit
Bins_Play
Bins_Refresh
Bins_Rename
Bins_SelectAll
Bins_Stop
Comp_Abort
Comp_Activate_Tool
Comp_BackgroundRender
Comp_Choose_Action
Comp_Choose_Tool
Comp_Close
Comp_New
Comp_NewFloatFrame
Comp_NewTabbedFrame
Comp_Open
Comp_Opened
Comp_Recent_Clear
Comp_Recent_Open
Comp_Redo
Comp_Render
Comp_Render_End
Comp_Render_Frame
Comp_Save
Comp_SaveAs
Comp_SaveCopyAs
Comp_SaveVersion
Comp_ShowTimeCode
Comp_Start_Render
Comp_StartRender
Comp_TimeCodeFormat
Comp_Undo
Execute
Frame_Activate_Frame
Frame_Activate_Next
Frame_Activate_Prev
Frame_Activate_SubWnd
Layout_Load
Layout_Reset
Layout_Save
Layout_Switch
NetRender_Allow
No_Action
Playback_Mode
Playback_Seek
Playback_Seek_End
Playback_Seek_Start
Player_Channel
Player_Device_DeckLink
Player_Gain
Player_Gamma
Player_Guide_Enable
Player_Guide_Select
Player_Item_Next
Player_Item_Prev
Player_Loop_Reset
Player_Loop_Set_In
Player_Loop_Set_Out
Player_Loop_Set_Shot
Player_Play
Player_Play_Forward
Player_Play_Reverse
Player_Seek_By
Player_Seek_End
Player_Seek_Next
Player_Seek_Prev
Player_Seek_Start
Player_Seek_To
Player_Set_FPS
Player_Set_Loop
Player_Set_Time
Player_Show_Metadata
Player_Sync_Mode
Player_Trim_Exit
Player_Trim_Set_In
Player_Trim_Set_Out
Prefs_Show
Reel_Delete_Selected
RunScript
Script_Edit
Target_Show_Menu
Target_Show_Scripts
Time_Goto_GlobalEnd
Time_Goto_GlobalStart
Time_Goto_Key_Next
Time_Goto_Key_Prev
Time_Goto_RenderEnd
Time_Goto_RenderStart
Time_Set
Time_Step_Back
Time_Step_Forward
Time_Step_NextKey
Time_Step_PrevKey
Tool_Settings_Activate
Tool_Settings_Store
Tool_ViewClear
Tool_ViewOn
Utility_Show
View_Pan_Mode
View_Reset
View_Show
View_Zoom_Absolute
View_Zoom_Fit
View_Zoom_In
View_Zoom_Mode
View_Zoom_Out
View_Zoom_Rectangle
View_Zoom_Relative
Viewer_3D_CentreSelected
Viewer_3D_FitAll
Viewer_3D_FitSelected
Viewer_Buffer
Viewer_Channel
Viewer_Controls_Show
Viewer_Guides_Show
Viewer_Image_ROI_Enable
Viewer_Lock
Viewer_QuadView
Viewer_Reset
Viewer_Scale_Abs
Viewer_Scale_Rel
Viewer_SubView_Show
Viewer_SubView_Swap
Viewer_Tools_Disable
Viewer_Unview_All
How do I use ui:AddNotify()?

Several of my previous code examples on this GUI Building thread have used the ui:AddNotify() function. Lets explore ui:AddNotify() by looking at how we can trigger a Lua function. If you wanted to have your UI Manager based GUI respond and update when a Fusion composite is saved you have several different save actions to choose from:

Comp_Save
Comp_SaveAs
Comp_SaveCopyAs
Comp_SaveVersion

"Comp_Save" is triggered each time the composite is saved.
"Comp_SaveAs" is triggered when the "Save As" command is used.
"Comp_SaveCopyAs" is triggered when the "Save Copy As" command is used.
"Comp_SaveVersion" is triggered when the "Save Version" command is used.
ui-manager-addnotify.png
This is the Lua code that is used to let the script know when an action based event occurred:
Code: [Select all] [Expand/Collapse] [Download] (addnotify1.lua)
  1.  
  2. local ui = fu.UIManager
  3. local disp = bmd.UIDispatcher(ui)
  4. local width,height = 600,100
  5.  
  6. win = disp:AddWindow({
  7.   ID = 'MyWin',
  8.   WindowTitle = 'AddNotify',
  9.   Geometry = {100, 100, width, height},
  10.   Spacing = 10,
  11.  
  12.   ui:VGroup{
  13.     ID = 'root',
  14.    
  15.     -- Add your GUI elements here:
  16.     ui:Label{ID = 'SaveLabel', Text = 'Save your Fusion comp to see the AddNotify() event in action.', Alignment = {AlignHCenter = true, AlignTop = true},},
  17.   },
  18. })
  19.  
  20.  
  21. -- Track the Fusion save events
  22. ui:AddNotify("Comp_Save", comp)
  23. ui:AddNotify("Comp_SaveVersion", comp)
  24. ui:AddNotify("Comp_SaveAs", comp)
  25. ui:AddNotify("Comp_SaveCopyAs", comp)
  26.  
  27. -- Add your GUI element based event functions here:
  28. itm = win:GetItems()
  29.  
  30. -- The window was closed
  31. function win.On.MyWin.Close(ev)
  32.   disp:ExitLoop()
  33. end
  34.  
  35. -- The Fusion "Save" command was used
  36. function disp.On.Comp_Save(ev)
  37.   print('[Update] Comp saved. Refreshing the view.')
  38.   RefeshDocument()
  39. end
  40.  
  41. -- The Fusion "Save Version" command was used
  42. function disp.On.Comp_SaveVersion(ev)
  43.   print('[Update] Comp saved as a new version. Refreshing the view.')
  44.   RefeshDocument()
  45. end
  46.  
  47. -- The Fusion "Save As" command was used
  48. function disp.On.Comp_SaveAs(ev)
  49.   print('[Update] Comp saved to a new file. Refreshing the view.')
  50.   RefeshDocument()
  51. end
  52.  
  53. -- The Fusion "Save Copy As" command was used
  54. function disp.On.Comp_SaveCopyAs(ev)
  55.   print('[Update] Comp saved as a copy to a new file. Refreshing the view.')
  56.   RefeshDocument()
  57. end
  58.  
  59. function RefeshDocument()
  60.   -- Do something
  61.   compFile = comp:GetAttrs().COMPS_FileName or 'Untitled'
  62.   print('[Current File] ', compFile)
  63.   itm.SaveLabel.Text = '[Current File] ' .. compFile
  64. end
  65.  
  66. win:Show()
  67. disp:RunLoop()
  68. win:Hide()
ui-manager-addnotify-addtool.png
Each action you run with the help of AddNotify() can report back details on the event that occurred using a "ev.xyz" sort of syntax to read the variable inside of your handler function.

If you wanted to track nodes added to your composite you could use code like this:
Code: [Select all] [Expand/Collapse] [Download] (addnotify2.lua)
  1. local ui = fu.UIManager
  2. local disp = bmd.UIDispatcher(ui)
  3. local width,height = 600,100
  4.  
  5. win = disp:AddWindow({
  6.   ID = 'MyWin',
  7.   WindowTitle = 'Add Tool',
  8.   Geometry = {100, 100, width, height},
  9.   Spacing = 10,
  10.  
  11.   ui:VGroup{
  12.     ID = 'root',
  13.    
  14.     -- Add your GUI elements here:
  15.     ui:Label{ID = 'SaveLabel', Text = 'Add new nodes to your composite to see the AddTool action at work.', Alignment = {AlignHCenter = true, AlignTop = true},},
  16.   },
  17.  
  18. })
  19.  
  20. -- We want to be notified whenever the 'AddTool' action has been executed on our comp
  21. notify = ui:AddNotify("AddTool", comp)
  22.  
  23. -- Add your GUI element based event functions here:
  24. itm = win:GetItems()
  25.  
  26. -- The window was closed
  27. function win.On.MyWin.Close(ev)
  28.   disp:ExitLoop()
  29. end
  30.  
  31. -- Handle the notification
  32. function disp.On.AddTool(ev)
  33.   print('[Added Node] ' .. tostring(ev.Args.id))
  34.   itm.SaveLabel.Text = '[Added Node] ' .. tostring(ev.Args.id)
  35. end
  36.  
  37. win:Show()
  38. disp:RunLoop()
  39. win:Hide()
You do not have the required permissions to view the files attached to this post.
Last edited by AndrewHazelden 7 years ago, edited 4 times in total.