Set focus from LUA code


(Sound_Compozer) #1

Hello.

Is it possible to set focus from LUA code? I make a jump to track with renoise.song().selected_track_index=track2need but after i need to click with mouse on pattern editor to have a focus on it. I need to set a focus to pattern editor automatically after renoise.song().selected_track_index.

Thank you


(danoise) #2

Not directly, no.

As a workaround, you could store a view preset with the focus already set and invoke that:

renoise.app().window:select_preset(preset_index)

(Sound_Compozer) #3

Thanx. It’s work, but there no keyboard focus. Only change view preset, but i can not immediately work with keyboard controls (need to any place mouse click on Renoise window).


(Ledger) #4

Not sure if this might help but Ive used this function in some scripts to set keyboard focus. For some reason I cant remember to hand it needed to unfocus and then focus to work in all instances.

local function focus_pattern()
 renoise.app().window.lock_keyboard_focus = false
 renoise.app().window.lock_keyboard_focus = true
end 

--run 
focus_pattern()

If you want the keyboard to work while a script dialog is still open and focused however, you would need to pass all the keystrokes to renoise via a key handler function:

--key Handler
local function my_keyhandler_func(dialog,key)
 return key
end

Just to expand the example a bit here is a combined version of the above snippets, with the added conditional that pressing escape is not passed to renoise but closes the dialog.

--key Handler
local function my_keyhandler_func(dialog,key)

 --always focus the pattern editor so renoise responds to key input
 renoise.app().window.lock_keyboard_focus = false
 renoise.app().window.lock_keyboard_focus = true

 --if escape pressed then close the dialog else return key to renoise
 if not (key.modifiers == "" and key.name == "esc") then
 return key
 else
 dialog:close()
 end
end

The keyhandler is passed to the show_custom_dialog method that initialises your GUI:

--Initialise Script dialog
my_dialog = renoise.app():show_custom_dialog("Note Properties", dialog_content,my_keyhandler_func)

(Sound_Compozer) #5

Thanx a lot, Ledger. Now it’s a little bit more suitable for my idea. Does the tool window can loose focus, after a screen button pressed on it? For example - i have a button (in my tool dialog) to JUMP TO TRACK XXXX, and i need to continue to work with track (in pattern editor) immediately after press this button?

Your example simple translate key strokes to renoise main window, still tool stay focused. And if there no ways to realize my ideas, i stay with your way to translate keystrokes to renoise main window.

Cheers.


(Ledger) #6

Like Danoise said I don`t think there is a way to do this directly. The only other thing would be to close the dialog on button press and then have the user re-open after using the pattern editor, but i guess this may defeat the functionality of the GUI anyway.

It may be worth making a request in the API thread here for the future, it sounds like a decent addition:

https://forum.renoise.com/t/the-api-wishlist-thread/29285