4 Replies Latest reply on Nov 9, 2010 4:46 PM by mkeatley17

    "Loading..." pop up window

    mkeatley17 Level 1

      I have an action that can take up to 40 seconds to run, and my users need to know not to touch their computers during that time

       

      Is there anyway to make a pop-up window that will indicate that the action is processing, and will disappear when the action is done?

       

      I know how to make all sorts of pop-up windows, but I DON'T know how to

       

      1.  make the window automatically pop up and disappear without user input

      2.  allow the action to run in the background while there's a pop up window

       

       

      Any help would be great. THANKS!

        • 1. Re: "Loading..." pop up window
          xbytor2 Level 4

          The only way to do this is to create a script that opens up a palette-style window with your Loading... message.

          You then call your action, let it process, then close your palette after it finishes.

           

          Here's the a function to create a palette. It's overkill for your needs but you can trim out the stuff you don't need.

           

          //
          // createProgressPalette
          //   title     the window title
          //   min       the minimum value for the progress bar
          //   max       the maximum value for the progress bar
          //   parent    the parent ScriptUI window (opt)
          //   useCancel flag for having a Cancel button (opt)
          //   msg       a message that can be displayed (and changed) in the palette (opt)
          //
          //   onCancel  This method will be called when the Cancel button is pressed.
          //             This method should return 'true' to close the progress window
          //
          function createProgressPalette(title, min, max,
                                                     parent, useCancel, msg) {
            var win = new Window('palette', title);
            win.bar = win.add('progressbar', undefined, min, max);
            if (msg) {
              win.msg = win.add('statictext');
              win.msg.text = msg;
            }
            win.bar.preferredSize = [500, 20];
          
            win.parentWin = undefined;
            win.recenter = false;
            win.isDone = false;
          
            if (parent) {
              if (parent instanceof Window) {
                win.parentWin = parent;
              } else if (useCancel == undefined) {
                useCancel = !!parent;
              }
            }
          
            if (useCancel) {
              win.onCancel = function() {
                this.isDone = true;
                return true;  // return 'true' to close the window
              };
          
              win.cancel = win.add('button', undefined, 'Cancel');
          
              win.cancel.onClick = function() {
                var win = this.parent;
                try {
                  win.isDone = true;
                  if (win.onCancel) {
                    var rc = win.onCancel();
                    if (rc != false) {
                      if (!win.onClose || win.onClose()) {
                        win.close();
                      }
                    }
                  } else {
                    if (!win.onClose || win.onClose()) {
                      win.close();
                    }
                  }
                } catch (e) {
                  var msg = Stdlib.exceptionMessage(e);
                  Stdlib.log(msg);
                  alert(msg);
                }
              };
            }
          
            win.onClose = function() {
              this.isDone = true;
              return true;
            };
          
            win.updateProgress = function(val) {
              var win = this;
          
              if (val != undefined) {
                win.bar.value = val;
              }
          //     else {
          //       win.bar.value++;
          //     }
          
              if (win.recenter) {
                win.center(win.parentWin);
              }
          
              win.show();
              win.hide();
              win.show();
            };
          
            win.recenter = true;
            win.center(win.parent);
          
            return win;
          };
          
          
          • 2. Re: "Loading..." pop up window
            mkeatley17 Level 1

            thank you so much! This works!!!!

             

            the one part I'm confused on is how to update the progress bar without showing it then hiding it each time? For example this an exmaple of progressing the bar form 0% to 100%:

             

            var dlg = createProgressPalette('Progress Bar', 0, 100, null,true,'Loading...'); 

             

            for(i=0;i<=100;i++)

            {

                 dlg.close();

                 // PERFORM SOME ACTION HERE

                dlg = createProgressPalette('Progress Bar', i, 100, null,true,'Loading...'); 
                dlg.show();
            }   

             

             

            is there a way to update the prgress bar without showing then hiding it?

             

            thank you

            • 3. Re: "Loading..." pop up window
              xbytor2 Level 4

              Try this in your loop:

              for(i=0;i<=100;i++)
              {
                   // PERFORM SOME ACTION HERE
                  dlg.update(i);
              }    
              
              • 4. Re: "Loading..." pop up window
                mkeatley17 Level 1

                I think you mean:

                for(i=0;i<=100;i++)
                {
                     // PERFORM SOME ACTION HERE
                    dlg.updateProgress(i);
                }  

                 

                THANKS!!