Modal Window Return Values

Home Forums General Programming Modal Window Return Values

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #14020
    lfo2vco
    Participant
      • Topics: 26
      • Replies: 162
      • Total: 188
      • ★★

      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-crystal

      #14021
      atom
      Keymaster
        • Topics: 159
        • Replies: 2945
        • Total: 3104
        • ★★★★★

        runModalLoop() returns a number that indicates what button was pressed to dismiss the window.

        #14022
        lfo2vco
        Participant
          • Topics: 26
          • Replies: 162
          • Total: 188
          • ★★

          Cheers 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-crystal

          #14023
          atom
          Keymaster
            • Topics: 159
            • Replies: 2945
            • Total: 3104
            • ★★★★★
            ret = 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
            
            #14024
            lfo2vco
            Participant
              • Topics: 26
              • Replies: 162
              • Total: 188
              • ★★

              Excellent, 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-crystal

              #14025
              lfo2vco
              Participant
                • Topics: 26
                • Replies: 162
                • Total: 188
                • ★★

                OK 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-crystal

                #14041
                atom
                Keymaster
                  • Topics: 159
                  • Replies: 2945
                  • Total: 3104
                  • ★★★★★

                  The 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);
                  
                  #14097
                  lfo2vco
                  Participant
                    • Topics: 26
                    • Replies: 162
                    • Total: 188
                    • ★★

                    Hi 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-crystal

                    #14098
                    atom
                    Keymaster
                      • Topics: 159
                      • Replies: 2945
                      • Total: 3104
                      • ★★★★★

                      This 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.

                      #14099
                      lfo2vco
                      Participant
                        • Topics: 26
                        • Replies: 162
                        • Total: 188
                        • ★★

                        Fair 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-crystal

                        #14102
                        lfo2vco
                        Participant
                          • Topics: 26
                          • Replies: 162
                          • Total: 188
                          • ★★

                          MMMMmmmm 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-crystal

                          #14109
                          lfo2vco
                          Participant
                            • Topics: 26
                            • Replies: 162
                            • Total: 188
                            • ★★

                            Hi 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

                          Viewing 12 posts - 1 through 12 (of 12 total)
                          • The forum ‘Programming’ is closed to new topics and replies.
                          There is currently 0 users and 45 guests online
                          No users are currently active
                          Forum Statistics
                          Threads: 2,495, Posts: 17,374, Members: 77,605
                          Most users ever online was 12 on January 22, 2019 3:47 pm
                          Ctrlr