Old 05-19-2018, 03:28 PM   #1
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default Reascript Momentary Message Box?

Hi fellow scripters,

Is there a function or way to invoke a temporary message box or similar?

For example, if I run a certain type of script, I'd like to be able to have a certain message upon completion that I do not have to click OK on.

A real-life example would be if I forgot to select items and the scrip won't do anything unless there are selected items, it would be nice to have a message box pop up for a second saying:

"Nothing happened! No items were selected"

Is this possible?

Thanks in advance.

Cheers,

Andrew K

Last edited by Thonex; 05-19-2018 at 04:22 PM.
Thonex is offline   Reply With Quote
Old 05-19-2018, 05:11 PM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

There's Help_Set: reaper.Help_Set('Hello World!', true). ShowConsoleMsg can display a message on a modeless window.

For a true temporary message box you can design your own using gfx.
cfillion is offline   Reply With Quote
Old 05-19-2018, 06:31 PM   #3
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Code:
local timer = 2 -- Time in seconds
local msg_title = "Done!"
local msg_str = "Nothing happened - no items were selected."
local wnd_w, wnd_h = 400, 125

-- Get the screen size
local __, __, scr_w, scr_h = reaper.my_getViewport(0, 0, 0, 0, 0, 0, 0, 0, 1)

-- Reference time to check against
local time = os.time()

-- Window background
gfx.clear = reaper.ColorToNative(255,255,255)

-- Open the window
--          Name    w       h   dock    x                   y
gfx.init(msg_title, wnd_w, wnd_h, 0, (scr_w - wnd_w) / 2, (scr_h - wnd_h) / 2)

gfx.setfont(1, "Arial", 18)

-- Black
gfx.set(0, 0, 0, 1)

-- Center the text
local str_w, str_h = gfx.measurestr(msg_str)
local txt_x, txt_y = (gfx.w - str_w) / 2, (gfx.h - str_h) / 2

local function Main()
    
    -- Get the keyboard/window state
    local char = gfx.getchar()
    
    -- Reasons to end the script:
    --  Esc           Window closed         Timer is up
    if char == 27 or char == -1 or (os.time() - time) > timer then return end
    
    -- Center the text
    gfx.x, gfx.y = txt_x, txt_y
    gfx.drawstr(msg_str)
    
    -- Maintain the window and keep the script running
    gfx.update()
    reaper.defer(Main)
    
end

Main()
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 05-20-2018, 02:18 AM   #4
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Wow guys!!

Just wow!

Thanks so much for this.

This goes a little deeper than I though I would need... but thanks so much Lokasenna for that coding example. I got back late (2:15 am here in LA) and I'll look at it with fresh eyes after a good night's sleep.

Here's hoping I can wrap this nicely into a function and only have to "understand it" breiefly enough to get it to work

Thanks again... and you too cfillion, thanks for that Set_Help ... never would have found that. Will check it out also.

Cheers,

Andrew K
Thonex is offline   Reply With Quote
Old 05-20-2018, 04:06 PM   #5
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Just wanted to thanks you guys again.

Works 100%!!

I'm hoping Lokasenna already had that code handy and just inserted my "message".. I'd feel bad if he coded that simply on my account. :O

Then again... THANKS... because it works perfectly.

Cheers,

Andrew K
Thonex is offline   Reply With Quote
Old 05-20-2018, 05:37 PM   #6
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Quote:
Originally Posted by Thonex View Post
I'm hoping Lokasenna already had that code handy and just inserted my "message".. I'd feel bad if he coded that simply on my account. :O
I've probably spent too much time fiddling with GUI stuff; I wrote that from memory and then just had to run it a couple of times to work out the typos. Glad to help.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 05-20-2018, 09:00 PM   #7
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Quote:
Originally Posted by Lokasenna View Post
I've probably spent too much time fiddling with GUI stuff; I wrote that from memory and then just had to run it a couple of times to work out the typos. Glad to help.
Thanks Lokasenna! I can't do anything form the top of my head... LOL

Speaking of typos, what is the most recent Sublime Text Reascript module? I see this one but it's from 4 years ago... that seems ancient in Reaper years...

https://packagecontrol.io/packages/ReaSyntax

Also, is there a way to integrate Sublime into Reaper as it's default development environment? If so, where can I learn more on how to do this?

Cheers,

Andrew K
Thonex is offline   Reply With Quote
Old 05-20-2018, 09:05 PM   #8
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

That's the most recent one I can find too. I use Notepad++, but X-Raym's syntax module for it isn't much more up to date.

As for IDE integration... nope.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 05-20-2018, 09:24 PM   #9
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Quote:
Originally Posted by Lokasenna View Post
That's the most recent one I can find too. I use Notepad++, but X-Raym's syntax module for it isn't much more up to date.

As for IDE integration... nope.

Thanks for saving me the time! Oh yeah... IDE ... that's the acronym I was looking for

Cheers,

Andrew K
Thonex is offline   Reply With Quote
Old 02-04-2022, 04:52 PM   #10
cohler
Banned
 
Join Date: Dec 2018
Posts: 642
Default

Quote:
Originally Posted by Lokasenna View Post
Code:
local timer = 2 -- Time in seconds
local msg_title = "Done!"
local msg_str = "Nothing happened - no items were selected."
local wnd_w, wnd_h = 400, 125

-- Get the screen size
local __, __, scr_w, scr_h = reaper.my_getViewport(0, 0, 0, 0, 0, 0, 0, 0, 1)

-- Reference time to check against
local time = os.time()

-- Window background
gfx.clear = reaper.ColorToNative(255,255,255)

-- Open the window
--          Name    w       h   dock    x                   y
gfx.init(msg_title, wnd_w, wnd_h, 0, (scr_w - wnd_w) / 2, (scr_h - wnd_h) / 2)

gfx.setfont(1, "Arial", 18)

-- Black
gfx.set(0, 0, 0, 1)

-- Center the text
local str_w, str_h = gfx.measurestr(msg_str)
local txt_x, txt_y = (gfx.w - str_w) / 2, (gfx.h - str_h) / 2

local function Main()
    
    -- Get the keyboard/window state
    local char = gfx.getchar()
    
    -- Reasons to end the script:
    --  Esc           Window closed         Timer is up
    if char == 27 or char == -1 or (os.time() - time) > timer then return end
    
    -- Center the text
    gfx.x, gfx.y = txt_x, txt_y
    gfx.drawstr(msg_str)
    
    -- Maintain the window and keep the script running
    gfx.update()
    reaper.defer(Main)
    
end

Main()
Thanks for this, but it draws all the text as graphics. What if you want text as text that is selectable, copyable, etc...?

It is also not useful for visually impaired as screen readers cannot read this...
cohler 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 08:57 AM.


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