8 Replies Latest reply on Nov 11, 2014 10:22 PM by Marc Autret

    Type of window for progress bars?

    Pontus Uggla Level 1

      What type of window (window/palette/dialog etc) is best for progress bars?

       

      I´m using window now, but they can sometimes by accident get hidden behind the document.

       

      I dont think dialog works, since i do things to the document, but it would be nice since they allways stay on top.

       

      /Pontus

        • 1. Re: Type of window for progress bars?
          Peter Kahrel Adobe Community Professional & MVP

          You can use palette and window, but not dialog. Dialogs grab all attention: so long as one is displayed you can't do anything else.

           

          Peter

          • 2. Re: Type of window for progress bars?
            Marc Autret Level 4

            The palette container seems to work fine.

             

            Here is the ProgressBar object that I use in most of my scripts:

             

            var ProgressBar = function(/*str*/title)
            {
                 var w = new Window('palette', ' '+title, {x:0, y:0, width:340, height:60}),
                      pb = w.add('progressbar', {x:20, y:12, width:300, height:12}, 0, 100),
                      st = w.add('statictext', {x:10, y:36, width:320, height:20}, '');
                 st.justify = 'center';
                 w.center();
                 this.reset = function(msg,maxValue)
                      {
                      st.text = msg;
                      pb.value = 0;
                      pb.maxvalue = maxValue||0;
                      pb.visible = !!maxValue;
                      w.show();
                      };
                 this.hit = function() {++pb.value;};
                 this.hide = function() {w.hide();};
                 this.close = function() {w.close();};
            };


            //------------------------------------------------
            //      SAMPLE CODE
            //------------------------------------------------

            function main()
            {
                 var pBar = new ProgressBar("Script Title");
                 var i;
                 
                 // Routine #1
                 pBar.reset("Processing Routine #1...", 100);
                 for( i=0 ; i < 100; ++i, pBar.hit() )
                      {
                      $.sleep(10);
                      }
                 
                 // Routine #2
                 var i;
                 pBar.reset("Processing Routine #2...", 10);
                 for( i=0 ; i < 10; ++i, pBar.hit() )
                      {
                      $.sleep(300);
                      }
                 
                 pBar.close();
            }
            main();

             

             

            @+

            Marc

            • 3. Re: Type of window for progress bars?
              Pontus Uggla Level 1

              I put Marc Autrets progress bar function in my script, triggering it from a menu item, same result, its not updating until its finished or i give an alert.

               

               

              #targetengine "session" var ProgressBar = function(/*str*/title) {      var w = new Window('palette', ' '+title, {x:0, y:0, width:340, height:60}),           pb = w.add('progressbar', {x:20, y:12, width:300, height:12}, 0, 100),           st = w.add('statictext', {x:10, y:36, width:320, height:20}, '');      st.justify = 'center';      w.center();      this.reset = function(msg,maxValue)           {           st.text = msg;           pb.value = 0;           pb.maxvalue = maxValue||0;           pb.visible = !!maxValue;           w.show();           };      this.hit = function() {++pb.value;};      this.hide = function() {w.hide();};      this.close = function() {w.close();}; }; //------------------------------------------------ //      SAMPLE CODE //------------------------------------------------           test_menu = app.menus.item('$ID/Main').submenus.add('Test'); app.scriptMenuActions.everyItem().remove(); app.menus.item('$ID/Main').submenus.item('Test').submenus.everyItem().remove(); var test_sub_menu = app.scriptMenuActions.add('Test'); test_sub_menu.eventListeners.add('onInvoke', function() {      var pBar = new ProgressBar("Script Title");      var i;      // Routine #1      pBar.reset("Processing Routine #1...", 100);      for( i=0 ; i < 100; ++i, pBar.hit() )      {           $.sleep(10);      }      // Routine #2      var i;      pBar.reset("Processing Routine #2...", 10);      for( i=0 ; i < 10; ++i, pBar.hit() )      {           $.sleep(300);      }      pBar.close(); }); test_menu.menuItems.add(test_sub_menu);
              • 4. Re: Type of window for progress bars?
                adrian.n Level 1

                The progressbar which is not updating untill finishing the whole task may possibly be an issue of InDesign CS4.

                I had the same problem when trying to run the script in InDesign CS4 (Mac). Just try the same thing in CS5, for me it worked...

                • 5. Re: Type of window for progress bars?
                  Pontus Uggla Level 1

                  The problem started in CS5. The script was working fine in CS4. After 

                  an update for CS4 it stopped working in CS4 as well.

                   

                  I still dont have a solution for it.

                  • 6. Re: Type of window for progress bars?
                    Ruq

                    Worked for me.

                    Thanks a lot for this simple, generic and super useful script.

                    • 7. Re: Type of window for progress bars?
                      CZ X team

                      Hello,

                      I've found solution.

                      It appear that every InDesign remember any previous state of this setting: app.scriptPreferences.enableRedraw

                      I have two computers – on one progressbar works properly, on second doesn't.

                      So if your Progress bar doesn't work properly, try add following line at the begining of script (into main() function):

                      app.scriptPreferences.enableRedraw = true;

                      • 8. Re: Re: Type of window for progress bars?
                        Marc Autret Level 4

                        New version:

                         

                        function ProgressBar(/*str*/title, /*uint*/width, /*uint*/height)
                        // =========================================================
                        // Version 2.beta | 12-Nov-2014
                        // -- Keep the message centered --see below the new method this.msg()
                        // -- Supports message patterns e.g: "Step %1/100" --see the sample code
                        // -- Other minor improvements
                        // =========================================================
                        {
                            (60<=(width||0))||(width=340);
                            (40<=(height||0))||(height=60);
                        
                            var H = 22,
                                Y = (3*height-2*H)>>2,
                                W = new Window('palette', ' '+title, [0,0,width,height]),
                                P = W.add('progressbar', { x:20, y:height>>2, width:width-40, height:12 }, 0,100),
                                T = W.add('statictext' , { x:0, y:Y, width:width, height:H }),
                                __ = function(a,b){ return localize.apply(null,a.concat(b)) };
                        
                            this.pattern = ['%1'];
                        
                            W.center();
                        
                            // ---
                            // API
                            // ---
                           
                            this.msg = function(/*str*/s)
                            // ---------------------------------
                            {
                                s && (T.location = [(width-T.graphics.measureString(s)[0])>>1, Y]);
                                T.text = s;
                            };
                        
                            this.show = this.reset = function(/*str*/s, /*uint*/v)
                            // ---------------------------------
                            {
                                if( s && s != localize(s,1,2,3,4,5,6,7,8,9) )
                                    {
                                    this.pattern[0] = s;
                                    s = __(this.pattern, [].slice.call(arguments,2));
                                    }
                                else
                                    {
                                    this.pattern[0] = '%1';
                                    }
                               
                                P.value = 0;
                                P.maxvalue = v||0;
                                P.visible = !!v;
                        
                                this.msg(s);
                                W.show();
                            };
                        
                            this.hit = function(x)
                            // ---------------------------------
                            {
                                ++P.value;
                                ('undefined' != typeof x) && this.msg(__(this.pattern, [].slice.call(arguments,0)));
                            };
                        
                            this.hide = function()
                            // ---------------------------------
                            {
                                W.hide();
                            };
                           
                            this.close = function()
                            // ---------------------------------
                            {
                                W.close();
                            };
                        };
                        
                        
                        //------------------------------------------------
                        //      SAMPLE CODE
                        //------------------------------------------------
                        
                        (function()
                        {
                            var PB = new ProgressBar("Script Title",350,100),
                                i, vMax;
                        
                            // Quick process
                            // ---
                            PB.show("Processing quickly... %1 / 500", vMax=500, i=0);
                            for( ; i < vMax ; $.sleep(8), PB.hit(++i) );
                           
                            PB.reset("Wait for 800 ms...");
                            $.sleep(800);
                        
                            // Slow process
                            // ---
                            PB.reset("And now slowly (%1%)  |  Stage %2", vMax=13, 0, i=0);
                            for( ; i < vMax ; ++i, PB.hit((100*(i/vMax)).toFixed(2), i), $.sleep(400+200*(.5-Math.random())) );
                        
                            $.sleep(500);
                            PB.msg("The job is done.");
                            $.sleep(1500);
                        
                            // Quit
                            // ---
                            PB.close();
                        })();
                        
                        

                         

                        @+

                        Marc