Old 11-23-2019, 06:41 AM   #1
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 444
Default How to click a button in Lokasenna GUI v2

Ok, new problem, have checked the documentation and googled
with no luck. Have this code

Code:
function countDownTimer2 ()
  if (reaper.time_precise() <= endTime2) then
    reaper.defer(countDownTimer2)
  else
    reaper.ShowConsoleMsg("Continue")
    GUI.elms.Start_Cont_Button:exec() <--Click a button
  end
end
The Msg is shown, but the button is not clicked - what have I missed?
__________________
ToDoList Obliques MusicMath Donation Mark4celeste Frid i ditt hjärta Eve & the Fisherman on Spotify

Last edited by tompad; 11-24-2019 at 02:13 AM.
tompad is offline   Reply With Quote
Old 11-23-2019, 08:45 AM   #2
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,550
Default

- In future, it would be useful to clarify in the title and post that it's a question relating to my GUI.

- Working for me:
Code:
local lib_path = reaper.GetExtState("Lokasenna_GUI", "lib_path_v2")
if not lib_path or lib_path == "" then
    reaper.MB("Couldn't load the Lokasenna_GUI library. Please run 'Script: Set Lokasenna_GUI v2 library path.lua' in your Action List.", "Whoops!", 0)
    return
end
loadfile(lib_path .. "Core.lua")()

GUI.req("Classes/Class - Button.lua")()

if missing_lib then return 0 end

local function btn_click()
  GUI.Msg("Button was clicked")
end

local endTime2 = reaper.time_precise() + 2

function countDownTimer2 ()
  if (reaper.time_precise() <= endTime2) then
    reaper.defer(countDownTimer2)
  else
    GUI.Msg("Timer fired")
    GUI.elms.Start_Cont_Button:exec() --Click a button
  end
end

GUI.name = "New Window"
GUI.x, GUI.y, GUI.w, GUI.h = 0, 0, 432, 500
GUI.anchor, GUI.corner = "mouse", "C"

GUI.New("Start_Cont_Button", "Button", 1, 168, 28, 96, 20, "Go!", btn_click)

GUI.Msg("Started...")
countDownTimer2()

GUI.Init()
GUI.Main()
-->

Code:
Started...
(...two seconds later...)
Timer fired
Button was clicked
Lokasenna is offline   Reply With Quote
Old 11-24-2019, 03:05 AM   #3
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 444
Default

Quote:
Originally Posted by Lokasenna View Post
- In future, it would be useful to clarify in the title and post that it's a question relating to my GUI.
Oooh,missed it, was to exited ;-) Fixed now!

Quote:
Code:
local function btn_click()
  GUI.Msg("Button was clicked")
end

//////////

GUI.New("Start_Cont_Button", "Button", 1, 168, 28, 96, 20, "Go!", btn_click)

Hmmm, ok, I am using this

Code:
 function GUI.elms.Start_Cont_Button:onmouseup()

  GUI.Button.onmouseup(self)

-- Lots of code
end
instead of assigning btn_click to GUI.New button. Maybe thats
the problem? Or Linux? ;-)

I am using GUI-builder and the output of code is a bit different
and I had various luck with assigning function to button with that.
It was a long long time ago I tried it, could have missed something
important...
__________________
ToDoList Obliques MusicMath Donation Mark4celeste Frid i ditt hjärta Eve & the Fisherman on Spotify
tompad is offline   Reply With Quote
Old 11-24-2019, 03:15 AM   #4
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 444
Default

I found a solution!


I tried to assign function to GUI.New-button with:

Code:
GUI.New("Start_Cont_Button", "Button", {
  z = 11,
  x = 32.0,
  y = 128.0,
  w = 100,
  h = 30,
  caption = "START!",
  font = 2,
  col_txt = "txt",
  col_fill = "elm_frame",
  func = startButton
})
and call it from countTimer2.....

...that didn't work ;-(

Instead of that I moved all own code I had in

Code:
 function GUI.elms.Start_Cont_Button:onmouseup()

  GUI.Button.onmouseup(self)

-- Own code
end
to an own function that I called from GUI.elms.Start_Cont_Buttonnmouseup().

That worked! :-)
__________________
ToDoList Obliques MusicMath Donation Mark4celeste Frid i ditt hjärta Eve & the Fisherman on Spotify
tompad is offline   Reply With Quote
Old 11-24-2019, 08:31 AM   #5
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,550
Default

The exec method specifically calls the function assigned to func, so yes - if you overwrite mouseup directly to add our code instead of passing a function, exec won't work.
Lokasenna is offline   Reply With Quote
Old 11-24-2019, 08:50 AM   #6
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 444
Default

Quote:
Originally Posted by Lokasenna View Post
The exec method specifically calls the function assigned to func, so yes - if you overwrite mouseup directly to add our code instead of passing a function, exec won't work.
I am not sure I understand right.....

What I did was to replace
Code:
 function GUI.elms.Start_Cont_Button:onmouseup()
  GUI.Button.onmouseup(self)
-- Lots of code  
end
with

Code:
 function startButton()
 -- Lots of code
end
and added func = startButton to GUI.New ("Start_Cont_Button")-table
like this:

Code:
GUI.New("Start_Cont_Button", "Button", {
  z = 11,
  x = 32.0,
  y = 128.0,
  w = 100,
  h = 30,
  caption = "START!",
  font = 2,
  col_txt = "txt",
  col_fill = "elm_frame",
  func = startButton
})
But clicking the button did nothing. ? Shouldn't that do the thing?
Trying to understand ....but....dont.

The solution I had worked though.
__________________
ToDoList Obliques MusicMath Donation Mark4celeste Frid i ditt hjärta Eve & the Fisherman on Spotify
tompad is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:31 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.