Home › Forums › General › Programming › Modal Window Return Values
Tagged: Modal Window, Return Values
- This topic has 11 replies, 2 voices, and was last updated 10 years, 6 months ago by lfo2vco.
-
AuthorPosts
-
October 9, 2013 at 10:52 pm #14020
Hi, I am using a Modal Window based of Atom’s demo panel. However the function attached to it runs regardless of whether I select OK or cancel.
I have tried various lines of code to try to capture the return values but with no success. Here’s the method:
function renamePatch() if panel:getRestoreState() == true or panel:getProgramState() == true then return end -- ////////// Get Name For Rename Dialogue ////////// nameData = L(PatchLabel:getProperty("uiLabelText")) function trim (s) return (string.gsub(s, "^%s*(.-)%s*$", "%1")) end nameTrim = (trim(nameData)) -- //////////////////////////////////////////// -- ////////// Create Rename Dialogue ////////// modalWindow = AlertWindow("\n\nRename the Editor patch,\nup to 16 characters long.", "Please remember to save the\namended patch and name to\nyour Kiwi-3P synthesizer.", AlertWindow.InfoIcon) modalWindow:addButton("Cancel", 0, KeyPress(KeyPress.escapeKey), KeyPress()) modalWindow:addButton(" OK ", 1, KeyPress(KeyPress.returnKey), KeyPress()) modalWindow:addTextEditor ("renameTextEditor", (nameTrim), "Rename As:", false) modalWindow:setModalHandler(windowCallback) modalWindow:runModalLoop() textEditor = modalWindow:getTextEditor("renameTextEditor"):getText() if textEditor ~= nil then PatchLabel:setProperty("uiLabelText", (textEditor), false) end if textEditor == "" then PatchLabel:setProperty("uiLabelText", "Untitled Patch ", false) end end -- ////////// End Rename Dialogue ////////// -- ////////////////////////////////////////////
So the question is two part; What code do I need to capture the OK & Cancel values? Should it go in the windowCallback method or in the method above?
Here is some noise I organised into an acceptable format:
https://soundcloud.com/lfo2vco/a-dark-crystalOctober 9, 2013 at 11:13 pm #14021runModalLoop() returns a number that indicates what button was pressed to dismiss the window.
October 9, 2013 at 11:19 pm #14022Cheers Atom, so something like:
if runModalLoop == 1 then textEditor = modalWindow:getTextEditor blah blah blah
Should do it then.
Here is some noise I organised into an acceptable format:
https://soundcloud.com/lfo2vco/a-dark-crystalOctober 9, 2013 at 11:25 pm #14023ret = modalWindow:runModalLoop() if ret == 1 then -- i think this is OK button end if ret == 0 then -- this should be cancel end -- but it might be the other way around
October 9, 2013 at 11:27 pm #14024Excellent, indeed the values are the correct way around. Thanks again : )
Here is some noise I organised into an acceptable format:
https://soundcloud.com/lfo2vco/a-dark-crystalOctober 10, 2013 at 12:18 am #14025OK that works, however it requires each button to be pressed twice before dismissing the window. Same if I use keystrokes.
Here is some noise I organised into an acceptable format:
https://soundcloud.com/lfo2vco/a-dark-crystalOctober 10, 2013 at 3:02 pm #14041The double stuff might be caused bu the modal callbacks subsystem, If you want just a simple window that displays a messages and has a OK/Cancel button this will work
ret = utils.questionWindow("title", "message", "OK", "Cancel") if ret then console ("true") else console("false") end
Of if you want to get a text response from the user, you can use the other method in the utils
askForTextInputWindow (const String title, const String message, const String initialInputContent, const String onScreenLabel, const bool isPassword, const String button1Text, const String button2Text);
October 12, 2013 at 11:01 am #14097Hi Atom, I have finally found some time to sit down and look at this. I have opted for the ‘askForTextInputWindow’ as a text response is required.
I have been trying to get the return values from the buttons in this window with no success… also I will need to get the initialInputContent. Any pointers gratefully received.
I have been trawling the Juce site for info, but to no avail.
Here is some noise I organised into an acceptable format:
https://soundcloud.com/lfo2vco/a-dark-crystalOctober 12, 2013 at 11:09 am #14098This method will never return anything except a string that is typed in the window. You won’t know what button was pressed i’m afraid you only get the string inside the window, this is a very simple “get a line of text from user” method with no error checking.
October 12, 2013 at 11:24 am #14099Fair enough, so I can set button2 to false and just have an OK button then.
Here is some noise I organised into an acceptable format:
https://soundcloud.com/lfo2vco/a-dark-crystalOctober 12, 2013 at 12:31 pm #14102MMMMmmmm that didn’t work, so I have window two buttons that in effect do the same thing and I cannot remove of one of them.
I think in this instance it would be better of use the Model Window with only one button and no return callbacks. : )
Here is some noise I organised into an acceptable format:
https://soundcloud.com/lfo2vco/a-dark-crystalOctober 12, 2013 at 9:31 pm #14109Hi Atom, it seems I have resolved my issue with the Modal Window…
A silly misunderstanding on my part, which became obvious when I revisited the method. When you instructed me to add
ret = modalWindow:runModalLoop()
to get the button return values. I added the whole statement to the method.This meant that I ended up with
modalWindow:runModalLoop() ret = modalWindow:runModalLoop()
hence why the buttons required two presses before dismissing the window.
Amateurs eh!! I realise now that I only needed to add
ret =
Thanks for your patience as always.
- This reply was modified 10 years, 6 months ago by lfo2vco.
Here is some noise I organised into an acceptable format:
https://soundcloud.com/lfo2vco/a-dark-crystal -
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.