Old 06-17-2020, 06:54 PM   #721
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 89
Default

Quote:
Originally Posted by solger View Post
I guess it's possible by making a custom function in your script for creating and returning a 'full' selection table.
I ended up just creating another return value within the listbox class that keeps track of everything and returns it as the full bool list.


Quote:
Originally Posted by solger View Post
What's the use-case for which you require the 'full' listbox selection table?
I tend to iterate through the entire list in order to remove certain objects from arrays and what not, so only having the partial array would never work for me because I need the index of what items are true or not. At least in my opinion, having this full list is a lot more useful then only having the partial list.


Quote:
Originally Posted by solger View Post
By the way: are you using v2 or v3 (Scythe) of the GUI library?
I am currently using v2.
jkooks is offline   Reply With Quote
Old 06-28-2020, 08:50 AM   #722
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 248
Default GUI Label element not displaying above a certain font size

Is there some maximum font point size above which the Label element does not work?

I have a label that I resize according to size of the GUI window. Above a certain size, it vanishes, and then comes back if I resize down back below that size.

Is this a Windows limitation? Anybody know?
__________________
Source-Destination 4-Point Editing for REAPER!
Available NOW for PC & Mac • FREE Trial License included
info@cohlerclassical.comhttps://cohlerclassical.com
cohler is offline   Reply With Quote
Old 06-28-2020, 09:29 AM   #723
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 248
Default Maximum height appears to be 255 pixels

Did some more testing.

Above 255 pixel height as returned by gfx.measurestr on Windows, the caption just vanishes.

Is this a known PC/Windows limitation? On Mac it goes to any size.
__________________
Source-Destination 4-Point Editing for REAPER!
Available NOW for PC & Mac • FREE Trial License included
info@cohlerclassical.comhttps://cohlerclassical.com
cohler is offline   Reply With Quote
Old 06-28-2020, 06:48 PM   #724
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 248
Default Lokasenna GUI window problem on Windows only

I have simplified this function as much as possible and provided LICEcap videos below to demonstrate the problem.

The function below creates a GUI window to display a 3-digit number with leading zeros as necessary using the Lokasenna GUI V2.

Initially the window is sized 349x291 and the font size of the number is 255.

As the user drags the corner of the window to resize it, the GUI.onresize function adjusts the font size of the number to fit in the window at the same ratio while keeping it in the center.

This code works perfectly on the Mac. On Windows it works ONLY when the window is sized such that the height of the number in the window is 255 or less. When the number is a height of 256 or more, it disappears!

Any insights or help would be appreciated!

Code:
function Number(n)
  local lib_path = reaper.GetExtState("Lokasenna_GUI", "lib_path_v2")
  loadfile(lib_path .. "Core.lua")(); GUI.req("Classes/Class - Label.lua")()

  local w,h,sz = 349,291,255
  GUI.name, GUI.fonts.bigfont = "Number", {"Calibri",sz}  
  GUI.x, GUI.y, GUI.w, GUI.h = 0, 0, w, h
  GUI.anchor, GUI.corner, GUI.freq = "screen", "C", .03
  GUI.colors.wnd_bg = {255,255,255,255}
  
  GUI.New("mylabel", "Label", 1, 20, 20, string.format("%03d",n), 
          false, "bigfont", "white", "black")
          
  local rw,rh,bf,label = sz/w, sz/h, GUI.fonts.bigfont, GUI.elms.mylabel
  GUI.onresize = function()
    bf[2] = math.floor(math.min(GUI.cur_h*rh,GUI.cur_w*rw))
    label.x, label.y = GUI.center(label)      
    GUI.Val("mylabel",label.caption)
  end

  GUI.Init(); GUI.Main()
end
Number(1)
Here is the INCORRECT behavior on Windows...



Here is the CORRECT behavior on Mac OS X...

__________________
Source-Destination 4-Point Editing for REAPER!
Available NOW for PC & Mac • FREE Trial License included
info@cohlerclassical.comhttps://cohlerclassical.com

Last edited by cohler; 06-29-2020 at 05:52 AM. Reason: Added LICEcap video
cohler is offline   Reply With Quote
Old 07-09-2020, 09:45 AM   #725
aurelien
Human being with feelings
 
Join Date: Apr 2014
Posts: 50
Default

Hello all,
Thanks for this great library, was able to create my GUI with v3.
However, I'm having a really hardtime using listbox : i spent two hours trying to add an element in my listbox...

Spent some times in the example, but there's no example of adding an element in a listbox.

I just have a button mapped to add a value in my table, and maybe refresh the listbox.

If someone is able to help

Thanks!

PHP Code:
squares = {149162536496481}
local function addText()
  -- 
Get the list boxs selected item(s)
  
local selected GUI.Val("lst_titles")
  
local lstbox GUI.findElementByName("lst_titles")

    -- 
Get and sort the selected item numbers
    
for kv in pairs(selected) do
        
Msg(v)
        
Msg(k)
    
end
    
     table
.insert(squares99)
     
lstbox.recalculateWindow()
     
end 

Last edited by aurelien; 07-09-2020 at 09:58 AM.
aurelien is offline   Reply With Quote
Old 07-09-2020, 10:23 AM   #726
solger
Human being with feelings
 
solger's Avatar
 
Join Date: Mar 2013
Posts: 4,781
Default

.list lets you get/set the current list values: https://jalovatt.github.io/scythe/#/...ements/Listbox

Here are two short examples to try:


1) Updating the squares table and passing this one to the listbox
PHP Code:
local squares = {149162536496481}

local function addText()
    
table.insert(squares99)
    
myListBox.list = squares
end 
2) Or updating the list directly:
PHP Code:
local squares = {149162536496481}

-- 
version 1
local 
function addText()
    
local listboxEntries myListBox.list 
    
table.insert(listboxEntries99)
end

-- version 2
local 
function addText()
    
table.insert(myListBox.list, 99)
end 
myListBox in the examples is the variable name:
Code:
 
local myListBox = GUI.createElement({
...
As mentioned in the link, calling Listbox:recalculateWindow() is only necessary when changing certain listbox parameters:
Quote:
Listbox:recalculateWindow()
Update internal values for the window size. If you change the listbox's w, h, pad, or textFont, this method should be called afterward.
__________________
ReaLauncher

Last edited by solger; 07-09-2020 at 10:35 AM.
solger is offline   Reply With Quote
Old 07-09-2020, 12:14 PM   #727
aurelien
Human being with feelings
 
Join Date: Apr 2014
Posts: 50
Default

Thanks for this awesome reply.
I'm not used to lua and basic functions are taking quite some time for me !

It's working great now
aurelien is offline   Reply With Quote
Old 07-18-2020, 02:49 AM   #728
forsakenlight
Human being with feelings
 
Join Date: Jul 2020
Posts: 2
Default get resized widnow height and widht?

Hi, I'm new here so first of all I want to say hello to everyone!
And now lets go straight to the business
I have a trivial problem, I can't find how can I get resized, window height and width. When I ask for window.h after resizing window, it doesn't hold changed value and returns my initial window size. Please can anyone can point me in the right direction?
btw I'm using Scythe v 3 form ReaPack
forsakenlight is offline   Reply With Quote
Old 07-18-2020, 05:04 AM   #729
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: Apr 2020
Location: Leipzig
Posts: 1,174
Default

Look at gfx.h and gfx.w.

Maybe you can transfer those values to give the guilib the current windowsize to work with.

Welcome to the forum
__________________
Use you/she/her, when contacting me, please. Thanks :) Not mentoring via PMs, sorry.
Ultraschall-API - 1200 ReaScript functions for Reaper - Reaper Internals - Developerdocs4Reaper - Donate, if you wish
Meo-Ada Mespotine is offline   Reply With Quote
Old 07-18-2020, 07:03 AM   #730
forsakenlight
Human being with feelings
 
Join Date: Jul 2020
Posts: 2
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
Look at gfx.h and gfx.w.

Maybe you can transfer those values to give the guilib the current windowsize to work with.

Welcome to the forum
Superb, thank you, great it work like charm
forsakenlight is offline   Reply With Quote
Old 07-24-2020, 06:53 AM   #731
aurelien
Human being with feelings
 
Join Date: Apr 2014
Posts: 50
Default

Hello,
Is there a way to have a validator like behavior on MenuBox item ? Exactly like the textbox have ?
The idea is to have a callback when the users is selecting a menubox item.

Is there a way to add keyboard shortcuts for specific action?

Thanks!

Last edited by aurelien; 07-24-2020 at 07:52 AM.
aurelien is offline   Reply With Quote
Old 07-24-2020, 11:29 AM   #732
solger
Human being with feelings
 
solger's Avatar
 
Join Date: Mar 2013
Posts: 4,781
Default

Quote:
Originally Posted by aurelien View Post
Hello,
Is there a way to have a validator like behavior on MenuBox item ? Exactly like the textbox have ?
The idea is to have a callback when the users is selecting a menubox item.
Hi,

try this example (side note: selecting a menubox item via mouse is possible by clicking or using the mousewheel):
Code:
function myClickFunction(self)
  local index, value = myMenuBox:val()
  reaper.ShowConsoleMsg("Click: " .. index .. " / " .. value .. "\n")
end

function myWheelFunction(self)
  local index, value = myMenuBox:val()
  reaper.ShowConsoleMsg("Wheel: " .. index .. " / " .. value .. "\n")
end

myMenuBox = GUI.createElement({
  name = "menubox",
  type = "Menubox",
  x = 80,
  y = 20,
  w = 100,
  h = 20,
  options = {"Option 1", "Option 2", "Option 3"},
  afterMouseUp = myClickFunction,
  afterWheel = myWheelFunction
})
Quote:
Originally Posted by aurelien View Post
Is there a way to add keyboard shortcuts for specific action?
Can you post more details or an example about what you're looking for, exactly?
Like, what's the specific action in this case (that should be triggered or performed)?
__________________
ReaLauncher

Last edited by solger; 07-24-2020 at 12:25 PM.
solger is offline   Reply With Quote
Old 07-26-2020, 02:29 AM   #733
aurelien
Human being with feelings
 
Join Date: Apr 2014
Posts: 50
Default

Awesome it's working perfectly for the menubox ! Didn't find in the documentation

As for the keyboard shortcut it's pretty simple, just launch one function when i enter some specific key.

Like press "Insert" and it's using the same function as the button...Etc
aurelien is offline   Reply With Quote
Old 07-28-2020, 08:14 AM   #734
solger
Human being with feelings
 
solger's Avatar
 
Join Date: Mar 2013
Posts: 4,781
Default

Quote:
Originally Posted by aurelien View Post
Awesome it's working perfectly for the menubox ! Didn't find in the documentation
Yeah, the part about user events is currently not in the documentation. Only the empty placeholder (User events (placeholder)).

Some hints can be found in the examples and code files of the Scythe library v3 (developer tools) - which is a separate entry in ReaPack besides the Scythe library v3 one.
Or by looking at the code of the core Scythe library files.

Quote:
Originally Posted by aurelien View Post
As for the keyboard shortcut it's pretty simple, just launch one function when i enter some specific key.

Like press "Insert" and it's using the same function as the button...Etc
OK, I believe the approach in Scythe is still the same as in v2 of the GUI library:

If you look, for instance, at the code of the Radial Menu and Theory Helper scripts (both created with v2) from Lokasenna, the character codes for allowed input keys are usually defined in a table (GUI.chars) for easier access:
Code:
GUI.chars = {
  ESCAPE    = 27,
  SPACE    = 32,
  BACKSPACE  = 8,
  HOME    = 1752132965,
  END      = 6647396,
  INSERT    = 6909555,
  DELETE    = 6579564,
  RETURN    = 13,
  UP      = 30064,
  DOWN    = 1685026670,
  LEFT    = 1818584692,
  RIGHT    = 1919379572,
  
  F1      = 26161,
  F2      = 26162,
  F3      = 26163,
  F4      = 26164,
  F5      = 26165,
  F6      = 26166,
  F7      = 26167,
  F8      = 26168,
  F9      = 26169,
  F10      = 6697264,
  F11      = 6697265,
  F12      = 6697266
}
Checking key inputs globally (by comparing the character codes retrieved via gfx.getchar() with entries in the GUI.chars table) can be done with the help of a separate (defer loop) function:
Code:
local function CheckKeyInput()
  local char = gfx.getchar()

  -- console output to check/debug which value is sent on a button press
  -- if char > 0 then
  --  reaper.ShowConsoleMsg(tostring(char) .. "\n")
  -- end
  
  if char == GUI.chars.INSERT then
      reaper.MB("Insert", "Key", 0)
      -- do something when this particular key is pressed (as example: call the same function assigned to a button click here)
  end

  reaper.defer(CheckKeyInput)
end

GUI.func = CheckKeyInput()
Some details about the gfx.getchar function can be found here: https://www.extremraym.com/cloud/rea...ua_gfx.getchar
__________________
ReaLauncher

Last edited by solger; 07-28-2020 at 09:03 AM.
solger is offline   Reply With Quote
Old 07-31-2020, 06:56 PM   #735
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 89
Default

Is there a better way of redrawing the main window rather than using gfx.quit and then gfx.init? As context, I am trying to force the resize of the main window so the height changes.

This is in version 2, by the way.
jkooks is offline   Reply With Quote
Old 07-31-2020, 07:06 PM   #736
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: Apr 2020
Location: Leipzig
Posts: 1,174
Default

No quitting necessary.

To set the window-size anew, just pass "" as name-parameter into gfx.init.

From the docs:
Quote:
To resizes/reposition the window, call gfx.init again and pass an empty string as name-parameter.

The following example-code moves position and size of the gfx-window every half of a second:

Code:
gfx.init("Test")
A=0
function main()
  A=A+1
  if A==15 then 
    A=0
    gfx.init("", math.random(20)*10, math.random(20)*10, 0, math.random(20)*10, math.random(20)*10)
  end
  reaper.defer(main)
end

main()
I'm not sure, if Lokasenna's Gui-Lib reads out the windowsize dynamically, so maybe, you need to transfer gfx.w and gfx.h to some internal Gui-Lib-variables after having changed that.

If I remember, the resize/repositioning of the gfx-window had been added long after v2 of the Gui-Lib was finished, so I think, it's not automatically supported yet, but I might be wrong.

Edit: Probably related to this post? https://forum.cockos.com/showpost.ph...&postcount=728

Edit2:
I smoothed out the example code. So now, the window changes its size and position transitionary. Because it looks cooler that way

Code:
X=100
Y=100
W=100
H=100
DifX=101
DifY=101
DifW=101
DifH=101

gfx.init("Test", W, H, 0, X, Y)
function main()
  if DifX>X then X=X+1 else X=X-1 end
  if DifY>Y then Y=Y+1 else Y=Y-1 end
  if DifW>W then W=W+1 else W=W-1 end
  if DifH>H then H=H+1 else H=H-1 end
  
  if X==DifX then DifX=(math.random(20)*40)/2 end
  if Y==DifY then DifY=(math.random(20)*40)/2 end
  if W==DifW then DifW=(math.random(20)*40)/2 end
  if H==DifH then DifH=(math.random(20)*40)/2 end

    gfx.init("", W, H, 0, X, Y)

  reaper.defer(main)
end

main()
__________________
Use you/she/her, when contacting me, please. Thanks :) Not mentoring via PMs, sorry.
Ultraschall-API - 1200 ReaScript functions for Reaper - Reaper Internals - Developerdocs4Reaper - Donate, if you wish

Last edited by Meo-Ada Mespotine; 07-31-2020 at 07:28 PM.
Meo-Ada Mespotine is offline   Reply With Quote
Old 08-03-2020, 10:21 AM   #737
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 89
Default

Awesome, works like a charm! Not sure how I missed that post above, but thank you for pointing it out!

And for anyone else that is curious, I believe the only Lokasenna GUI variables you would need to change are setting the current width and height to the new ones.

Code:
GUI.cur_w, GUI.cur_h = GUI.w, GUI.h
jkooks is offline   Reply With Quote
Old 08-14-2020, 05:26 PM   #738
joe2
Human being with feelings
 
Join Date: Sep 2008
Location: UK
Posts: 377
Default

Is there any way to give focus to a specific element programmatically in v3?

Specifically, I want a Textbox I've got to have focus when the script is launched (so the user can immediately start typing in it).

If you set focus = true for the element, it will appear to have focus, however typing won't work until you click in the textbox (it starts working with mousedown).

Another example would be "click this button and that textbox gets focus". Again, setting focus = true doesn't work as you might expect.

I've had a good dig through the code/docs/examples/etc. and have tried a few things, but unfortunately nothing works so far. I think it could be to do with the "state" that's often being passed around, about which I know nothing.

Thanks for any help!

PS if it's *not* currently possible, I wonder if it could be made possible by altering something in gui/window.lua...
joe2 is offline   Reply With Quote
Old 08-14-2020, 06:12 PM   #739
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 89
Default

Quote:
Originally Posted by joe2 View Post
Is there any way to give focus to a specific element programmatically in v3?
I've had success directly setting the focus to true with GUI.elms.ElementName.focus = true before I initialize the GUI (with GUI.init)

That being said I haven't found a way to reliably set focus after the main GUI has been made (even if I redraw everything), and I am also using v2 - so this may not necessarily work in v3.
jkooks is offline   Reply With Quote
Old 08-15-2020, 06:42 AM   #740
joe2
Human being with feelings
 
Join Date: Sep 2008
Location: UK
Posts: 377
Default

Quote:
Originally Posted by jkooks View Post
I've had success directly setting the focus to true with GUI.elms.ElementName.focus = true before I initialize the GUI (with GUI.init
Thanks, that's useful to know. (FWIW, GUI.Init was removed for v3.[0])

I don't have the coding chops/time to pick it apart right now, but my eyes are on this bit of window.lua for possibly building a "give this element focus" method.

Code:
function Window:updateInputEvents()

...

  if elementToFocus then
    elementToFocus.focus = true
    elementToFocus:handleEvent("GotFocus", state, last)
    elementToFocus:redraw()

    state.focusedElm = elementToFocus
  end

...
Perhaps there's already a way to call/trigger that. If anyone with a better working knowledge of v3 has any ideas, let me know.

Cheers!

[0] https://github.com/jalovatt/scythe/b...p/CHANGELOG.md
joe2 is offline   Reply With Quote
Old 08-17-2020, 10:53 AM   #741
joe2
Human being with feelings
 
Join Date: Sep 2008
Location: UK
Posts: 377
Default

So I made a copy of
Code:
function Window:updateInputEvents()
in window.lua, removed most of the (mouse-handling, etc.) code, and to my complete surprise it worked first time:

Code:
function Window:giveElmFocus(element)
  local state = self.state
  local last = self.lastState

  local elementUpdated
  local elementToFocus = self:findElementByName(element)
  local elementToLoseFocus

  if last.focusedElm then
    elementToLoseFocus = last.focusedElm
  end

  -- TODO: Ensure that only one element can lose focus at a time, since this
  -- would potentially override them
  if elementToFocus then elementToLoseFocus = last.focusedElm end
  if state.shouldLoseFocus then elementToLoseFocus = state.shouldLoseFocus end

  if elementToLoseFocus then
    elementToLoseFocus.focus = false
    elementToLoseFocus:handleEvent("LostFocus", state, last)
    elementToLoseFocus:redraw()

    state.focusedElm = nil
  end

  if elementToFocus then
    elementToFocus.focus = true
    elementToFocus:handleEvent("GotFocus", state, last)
    elementToFocus:redraw()

    state.focusedElm = elementToFocus
  end
end
Haven't tested extensively so some cases might break (and some of the code above might be redundant), but it seems to work, so now it's possible to give elements focus programmatically from your main script:

Code:
window:giveElmFocus("Element Name")

Last edited by joe2; 08-18-2020 at 12:47 AM.
joe2 is offline   Reply With Quote
Old 08-24-2020, 08:41 AM   #742
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: Apr 2020
Location: Leipzig
Posts: 1,174
Default

Hey, I'm toying around with Scythe(v3) and try to alter dynamically the background-color of the window.
How can I do this or better, where are the colors of the window stored?

I can hardcode it in the theme.lua-file but this isn't feasible for the stuff I want to attempt.
__________________
Use you/she/her, when contacting me, please. Thanks :) Not mentoring via PMs, sorry.
Ultraschall-API - 1200 ReaScript functions for Reaper - Reaper Internals - Developerdocs4Reaper - Donate, if you wish
Meo-Ada Mespotine 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 12:53 AM.


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