6 Replies Latest reply on Mar 11, 2013 5:25 AM by DBarranca

    Execute code after dialog displayed without user input?

    badeshazer

      The window onShow() event executes before a dialog is displayed. Is there any way to execute some specific code right after the dialog window is displayed that does not require user-input of some kind?

       

      My dialog window is very simple, just a read-only EditText control and a single "OK" button, essentially imitating an alert() box.

       

      What I want to happen:

       

      1) Previous code that modifies the open document (filters, etc.) runs

      2) create and show dialog window

      3) execute app.refresh() to make sure the active document display is refreshed to reflect the current state of the document

       

      Right now I am reversing the order of #2 and #3 but it is causing a noticable and annoying delay of about 1.5 seconds between the time the previous action finishes and my dialog is displayed.

       

      Thanks for any input or ideas you might have!

        • 1. Re: Execute code after dialog displayed without user input?
          Michael L Hale Level 5

          There are not any ScriptUI events I can think of that would work without the user doing something like moving the mouse over the window, etc.

           

          And with a simple dialog I would think that the delay is being caused by the app.refresh call. Even if there was a good way to call it after the dialog shows there would still be that delay before the user could close the dialog.

          • 2. Re: Execute code after dialog displayed without user input?
            badeshazer Level 1

            Michael L Hale wrote:

             

            There are not any ScriptUI events I can think of that would work without the user doing something like moving the mouse over the window, etc.

             

            And with a simple dialog I would think that the delay is being caused by the app.refresh call. Even if there was a good way to call it after the dialog shows there would still be that delay before the user could close the dialog.

             

            Yes, the delay is definitely coming from the app.refresh call, removing it makes the dialog pop right up. This is why I want it to occur after the dialog has been displayed and not before.

             

            That 1.5 seconds may not seem like a lot, but it's just enough to make you think that something has either stopped working or that the process is complete...and then the dialog pops up. It's very disconcerting, and for the particular set of tasks I am performing this occurs multiple times, making it even more noticable.

             

            The 1.5 second delay after the dialog is displayed I can live with, it would probably take most people longer than that to read the contents of the dialog and then dismiss the dialog either via keyboard or mouse click.

             

            Unfortunately I haven't been able to come up with a solution myself which is why I went fishing here and on your other site.

             

            Thanks for the reply!

            • 3. Re: Execute code after dialog displayed without user input?
              Michael L Hale Level 5

              I guess you could make two windows that are the same size. The first would be a palette type window and the second a dialog type.

               

              Then you could do something like this...

               

               

              var win1 = new Window('palette', 'title');
              win1.preferredSize = [ 200, 100 ];
              win1.stMessage = win1.add('statictext',undefined,'Please wait for screen refresh');
              
              var win2 = new Window('dialog', 'title');
              win2.preferredSize = [ 200, 100 ];
              win2.stMessage = win2.add('statictext',undefined,'After refresh message.');
              win2.btnCancel = win2.add('button',undefined,'Ok',{name:'cancel'});
              // do some steps
              win1.show();
              app.refresh();
              win1.close();
              win2.show();
              
              • 4. Re: Execute code after dialog displayed without user input?
                badeshazer Level 1

                LOL, great minds think alike Michael, that was actually one of the ideas that I was considering!

                • 5. Re: Execute code after dialog displayed without user input?
                  badeshazer Level 1

                  Well, until one of the Adobe engineers swoops in and says "you can just do this...", I'm going with the dual-window method

                   

                  This isn't perfect because of little differences between the "palette" and "dialog" windows... things like the thickness of the title bar, etc. Also, for the palette window, I removed the close/min/max buttons like so:

                   

                   

                  var wintemp = new Window (restemp,wintitle,undefined,{closeButton: false, maximizeButton: false, minimizeButton: false});
                  

                   

                  There is also a noticable "flash" when the dialog window is displayed over the palette window, but lacking a better solution for now I guess I'll have to live with it, it is an improvement after all.

                   

                  After some experimenting I chose not to close the palette window until after the dialog window has been closed, as it seemed to make for a bit of a smoother transistion and gives a neat kind of "fade out" effect doing it this way. This code shows the order I ended up using:

                   

                   

                  // -------------------------------------------------------------------------------------------------
                  // Display the GUI window and controls
                  // -------------------------------------------------------------------------------------------------
                  wintemp.center();
                  wintemp.show();
                  app.refresh();
                  
                  
                  win.center();
                  win.show();
                  wintemp.close();
                  
                  

                   

                  The frustrating part is that the document display is updated almost immediately from the app.refresh() call, I imagine it is all the other re-building of histograms and other internals that causes the real delays... wish there was a call that just updated the display...

                   

                  Oh well, when I get grumpy trying to figure this stuff out I just remind myself how amazing the amount of control we do have through scripting really is...

                   

                  Hopefully this discussion helps someone else in the future...

                   

                  (All testing thus far was on Mac OSX running CS6, still have to test with CS4 & CS5 on Mac & Win)

                   

                  Forgot this forum software doesn't like 'tabs' in the code sections...

                  • 6. Re: Execute code after dialog displayed without user input?
                    DBarranca Level 4

                    Why don't you try using a Palette window via BridgeTalk?

                    Bridgetalk is asynchronous, so that after the window is shown, the "script interpreter" goes ahead reading the next command (more info here).

                    Alternatively (I'm not sure it would work) try to link some actions to the onDraw handler (see here).

                    Let us know!

                     

                    Davide