Old 03-26-2020, 11:42 AM   #1
Fergler
Human being with feelings
 
Fergler's Avatar
 
Join Date: Jan 2014
Posts: 5,220
Default Close script windows with Esc?

I recently overhauled my Reaper setup and switched over from toolbars to the Radial Menu and ReaNoir colour swatch tool, and using the Quick Adder 2 for FX adding.

I would like to close these windows with Esc but they all seem to ignore the Esc key except for Radial Menu, I'm assuming this because they are script windows and the Esc key is hardwired to close Reaper floating windows... so does it require the script maker to define this function manually?

Any way I can close them with Esc whether it's scripted in or not?
Fergler is online now   Reply With Quote
Old 03-26-2020, 12:04 PM   #2
solger
Human being with feelings
 
solger's Avatar
 
Join Date: Mar 2013
Posts: 5,852
Default

Yeah, in case of Radial Menu, the key input handling is managed directly inside the script.
Here's a code snippet from the GUI.Main function:
Code:
--  (Escape key)  (Window closed)    (User function says to close)
  if GUI.char == 27 or GUI.char == -1 or GUI.quit == true then
    return 0
  else
    reaper.defer(GUI.Main)
  end

I'm doing the same in my ReaLauncher script (which also uses Lokasenna's GUI as base).
So as far as I know, it comes down to the script maker to implement this behavior.


EDIT: Here are other examples using gfx.getchar: https://forum.cockos.com/showthread....41#post1785841
__________________
ReaLauncher

Last edited by solger; 03-26-2020 at 12:28 PM.
solger is offline   Reply With Quote
Old 03-26-2020, 02:30 PM   #3
Fergler
Human being with feelings
 
Fergler's Avatar
 
Join Date: Jan 2014
Posts: 5,220
Default

So I suppose I should request this feature to the makers of ReaNoir and Quick Adder 2

In the mean time I have found the action ReaScript: Close all running Reascripts which I've assigned to Shift+esc. This is working quite well for me.
Fergler is online now   Reply With Quote
Old 05-13-2020, 09:33 AM   #4
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,067
Default

Hey solger!

GUI.quit doesn't work for me. Is there anything I am missing?
I'm also using a Loka GUI.
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 05-13-2020, 09:58 AM   #5
solger
Human being with feelings
 
solger's Avatar
 
Join Date: Mar 2013
Posts: 5,852
Default

Hi,

here's a short example:

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 install 'Lokasenna's GUI library v2 for Lua', available on ReaPack, then run the 'Set Lokasenna_GUI v2 library path.lua' script in your Action List.", "Whoops!", 0)
    return
end

loadfile(lib_path .. "Core.lua")()
if missing_lib then return 0 end

GUI.name = "GUI"
GUI.x, GUI.y, GUI.w, GUI.h = 0, 0, 640, 480
GUI.anchor, GUI.corner = "mouse", "C"

GUI.Main = function()
  GUI.char = gfx.getchar()
  --  if GUI.char > 0 then reaper.ShowConsoleMsg("\t" .. tostring(GUI.char) .. "\n") end

  if GUI.char == 27 or GUI.char == -1 or GUI.quit == true then
    return 0
  else
    reaper.defer(GUI.Main)
  end
end

GUI.Init()

GUI.func = Main
GUI.freq = 0

GUI.Main()
Side note: looks like closing via ESC doesn't work when running the script from within Reaper's internal IDE window.
__________________
ReaLauncher
solger is offline   Reply With Quote
Old 05-13-2020, 10:27 AM   #6
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,067
Default

Hmm, nope, doesn't work here. Is GUI.quit generated by the Loka GUI functions?
I couldn't find it in the Wiki.
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 05-13-2020, 10:46 AM   #7
solger
Human being with feelings
 
solger's Avatar
 
Join Date: Mar 2013
Posts: 5,852
Default

Quote:
Originally Posted by _Stevie_ View Post
Hmm, nope, doesn't work here. Is GUI.quit generated by the Loka GUI functions?
I couldn't find it in the Wiki.
Yeah, if I remember correctly GUI.quit is part of the Core.lua from Loka's GUI. Another option would be to call gfx.quit() (instead of the 'return 0').
But not sure if GUI.quit might do some additional things (in comparison to gfx.quit.

Are you using v2 or v3 in this case?
The example is for v2. Not sure if something in this regards changed in v3 (hadn't had time yet to take a closer look).

If you like, you can also PM me your current script, so I can take a look at it.
__________________
ReaLauncher
solger is offline   Reply With Quote
Old 05-13-2020, 10:47 AM   #8
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,067
Default

Hey Solger, thanks, doing that!
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 08-18-2020, 04:13 AM   #9
joe2
Human being with feelings
 
Join Date: Sep 2008
Location: UK
Posts: 394
Default

Hey, not necessarily entirely relevant to the specific discussion above, but I found this thread when searching for a problem I was having, so thought I'd write up here in case it's helpful for anyone looking in the future.

I'm using v3 aka Scythe.

I believe the default behaviour is that scripts will quit when you press Escape (or click the OS close button of the script GUI window).

However I needed to add another defer loop to mine, and this would carry on running even after the GUI closed. (A couple of side-notes here: (1) I know I can use GUI.func = foo, but for whatever reason this doesn't update fast enough for me. Possibly by design? (2) I guess having another defer loop might be a way of having a script that keeps running regardless of if its GUI is open? Not sure.)

My solution was to add the typical "keep running unless the window is closed or Esc is pressed" thing to my main defer loop.

Roughly speaking:

Code:
-- the usual Scythe boilerplate

...

local function mainloop()

...

  local char = gfx.getchar()

  if char ~= 27 and char ~= -1 then
    reaper.defer(mainloop)
  end

end

...

GUI.Main()

mainloop()
And with that, the script and GUI seems to successfully quit/exit when I press Esc or close the window, but I still have a nice fast defer loop running to do various things.

Hope this helps someone
joe2 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 10:19 AM.


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