Jump to: Board index » General » Fusion

ui.button in fusion

Learn about 3D compositing, animation, broadcast design and VFX workflows.
  • Author
  • Message
Offline

yaroslav81

  • Posts: 1
  • Joined: Wed Nov 17, 2021 12:12 pm
  • Real Name: Родионов Ярослав Игоревич

ui.button in fusion

PostWed Nov 17, 2021 12:28 pm

Dear fusion fellows,
I'm creating a very basic UI in daVinci resolve Script, using python.
So far I stole a piece of code which creates a slider in python:

Code: Select all
ui = fu.UIManager
disp = bmd.UIDispatcher(ui)

dlg = disp.AddWindow({ "WindowTitle": "My First Window", "ID": "MyWin", "Geometry": [ 100, 100, 400, 100 ], },
    [
        ui.HGroup({ "Spacing": 0, },
        [
            ui.Slider({ "ID": "MySlider", }),
            ui.Label({ "ID": "MyLabel", "Text": "Value:", }),
        ]),
    ])

itm = dlg.GetItems()

def _func(ev):
    disp.ExitLoop()
dlg.On.MyWin.Close = _func

itm['MySlider'].Value = 25
itm['MySlider'].Minimum = 0
itm['MySlider'].Maximum = 100

def _func(ev):
    itm['MyLabel'].Text = "Slider Value: " + str(ev['Value'])
    print("Slider Value: " + str(ev['Value']))
dlg.On.MySlider.ValueChanged = _func

dlg.Show()
disp.RunLoop()
dlg.Hide()


Now I want to add a button which once clicked on starts the process (say process.exe) and reads its output.


Naturally, I add:
Code: Select all
ui.Button({ "ID": 'Button1', "Flat": "true",}),


into ui.HGroup.

Now I need to attach the function to this button.
In lua this is achieved trivially. We simply add the function:
Code: Select all
function win.On.Button1.Clicked(ev)
   f = io.popen(path_to_exe0)
   path = f:read("*a")
end


How do I achieve the same in Python? Do you know where I can steal some examples?
Yaroslav.
Offline

Annaël Beauchemin

  • Posts: 93
  • Joined: Thu Nov 24, 2016 7:12 am

Re: ui.button in fusion

PostSun Nov 21, 2021 1:38 am

It looks like your code comes from this post on WeSuckLess:
https://www.steakunderwater.com/wesuckl ... 167#p16167

There's an example with a button.

Your button seems to be created correctly in the layout, so you would just need to add this event handler function to execute your function when the button is clicked:

Code: Select all
def _func(ev):
    ## popen function here
dlg.On.Button1.Clicked = _func


Btw, this block of code should be inserted just after or just before the slider's event.

Return to Fusion

Who is online

Users browsing this forum: Baidu [Spider], Majestic-12 [Bot] and 21 guests