7 Replies Latest reply on May 2, 2013 3:16 AM by Petfactory

    UI base class

    Petfactory Level 1

      Hi!

      I want to create a ui "base class" that I can reuse. I have done a test that works when I launch it from ESTK but when launched from within Illustrator the window flashes then disappears. The idea was to create a function that returns the window and a group to which I can add more controls to from the class that "instantiates the base class".

      Below is a simplified example of the base class.

       

      #target Illustrator
      #targetengine main
      
      function UIBase(aTitle)
      {
          var win = new Window ("palette", aTitle);  
          win.margins = 0;
          
          var banner = win.add ("group",[0,0,200,60]);
          banner.graphics.backgroundColor = banner.graphics.newBrush (banner.graphics.BrushType.SOLID_COLOR, [0.2, 0.2, 0.2]);
          
          var body = win.add ("group");
          body.margins = 10;
          
          return {"win":win, "body":body};
      }
      
      

       

      The script that uses the base class looks like this.

       

      #include UIBase.jsx
      
      winObj = new UIBase("Hello World!");
      win = winObj["win"];
      body = winObj["body"];
        
      var btn = body.add("button", undefined, "Button!");
      
      win.show();
      

       

      It would be super handy to do something like this so that I dont have to rewrite code for the basic ui. Like I said it works from the ESTK but not from within illustrator. Does anyone have any ideas why this is not working? I am also interested if you have some examples of another way implementing a "ui base class" that can be extended.

       

      Best Regards,

      Johan

        • 2. Re: UI base class
          Petfactory Level 1

          Hi!

          That pdf is a really good resource, but I did not find exactly was I was looking for. After some additional googeling I found the $.evalFile() command. I used that command to "import" the base file instead of #include and it seems to work fine.

           

          BR,

          Johan

          • 3. Re: UI base class
            milligramme Level 3

            Hi. that code doesnt work for me.

             

            1. remove #target and #targetengine line from UIBase.jsx
            2. add only #target Illustrator to execute.jsx
            3. change to #targetengine session or something, NOT main
            4. or try with 'dialog' instead of 'palette'
            5. add #includepath /dirpath/to/UIBase.jsx to execute.jsx

             

            I tried this lists, and works fine both 'dialog' and 'palette'

             

            thank you.

            mg

            • 4. Re: UI base class
              Petfactory Level 1

              Hi,

               

              I tried what you suggested but I did not get the palette window to stay open. If I use  a "dialog" it works but I want to be able to have the window open while I work, and that is not possible with a window of the dialog type.

               

              The "base class" UIBase.jsx:

              function UIBase(aTitle)
              {    
                  var win = new Window ("palette", aTitle);  
                  var body = win.add ("group");
                  return {"win":win, "body":body};
              }
              
              

               

              The files that includes "the base class":

              #target Illustrator
              #targetengine session
              #include UIBase.jsx
              
              winObj = new UIBase("Hello World!");
              win = winObj["win"];
              body = winObj["body"];
              
              var runBtn = body.add ("button", undefined, "Button");
              
              win.show ();
              
              

               

              I changed the targetengine to session in the file that calls the "base class". I used just the #include since the file I wish to include is in the same folder. Like I said it works fine with a dialog type window, and it works from ESTK ( when the targetengine is set to main, I assume that I can not use a custom targetengine from ASTK ?)

               

              What am I missing to make this work with a window of the palette type ?

               

              Thank you,

              Johan

              • 5. Re: UI base class
                Muppet Mark Level 5

                #targetengine main will cause a palette to stay open…

                • 6. Re: UI base class
                  Petfactory Level 1

                  Hi Mark,

                   

                  When using #targetengine main in a script with a palette window created form a single jsx file it works as expected, the palette stays open. But I am including a "base class" UI file which has some code that I wish to reuse across multiple scripts. When using the #targetengine main in this file the windows disappears a short moment after it becomes visible. I am using a mac by the way.

                  Any ideas?

                   

                  Best Regards,

                  Johan

                  • 7. Re: UI base class
                    Petfactory Level 1

                    This is a strange behaviour. When I include a file useing the #include preprocessor the palette window flashes and disappears. If I remove the #include it works... hmmmm.

                     

                    #target illustrator
                    #targetengine main
                    //#include INCLUDE.jsx
                    
                    var win = new Window ("palette", "Palette");  
                    win.show();
                    
                    

                     

                    Anyone got an idea why this is ?

                     

                    BR,

                    Johan