7 Replies Latest reply on Feb 8, 2017 2:16 AM by Klaus Göbel

    Trapping the ghost

    K.Daube Level 1

      Dear friends,
      In my post Special effects - mostly unwanted I reported about some really persky things happening with my (now about 4500 lines) script. While the Twins and the Slave effect have disappeared by the time (not knowing which changes did it), the Ghost could not be trapped until now.
      Hence, I have now stripped down the script to the bare bones, which also create this ghostly effect.

       

      • Have any FM document open (it may be empty) and run the script Ghostbuster.jsx
      • In the document type ESC, q, m, c
      • The panel is opened
      • You may type something in the edit field
      • Cancel
      • In the document type ESC, q, m, c

       

      => The ghost appears: a mysterious drop down list, which got text from the edit field and into which you can type (and if you do so),  the typed text will apear in the next invocation of th panel.

       

      Where the heck does this come from?

      Ghostbusters are higly welcome!

       

      Klaus

      // Ghostbuster.jsx --- Attempt to find out what creates the ghost (artfacts) in the C and S panels.
      
      #target framemaker
      
      // === global variables, arrays ===================================================================
      var wPalC  = new Window("palette", undefined, undefined);  // title set in PaletteCalcMarkers
      var glbl = {};
        glbl.sCalcMarkerText = "Some initial text";
      main ();                                          // follow the standard …
      
      function main () { //=== ==========================================================================
        SetUpMenus(); // uncomment             comment
      }
      function SetUpMenus () { //=== Define the menu items for document and book ========================
      var bkFMcalcMenu, docFMcalcMenu, menuLocation, oMenus = {}, oCmd = {};
        oMenus.MenuMain           = "Calculations in FrameMaker…";
        oMenus.HandleCalcMarker   = "Handle #calc Markers…";
        oCmd.HandleCalcMarker   = DefineCommand(4,"docHcalcMarker",   oMenus.HandleCalcMarker,   "\\!qmc");
        oCmd.HandleCalcMarker.KeyboardShortcutLabel   = "ESC q m c";  
        menuLocation = app.GetNamedMenu("FormatMenu");
        docFMcalcMenu  = menuLocation.DefineAndAddMenu("!FMcalcMain", oMenus.MenuMain); // ! required 
        docFMcalcMenu.AddCommandToMenu (oCmd.HandleCalcMarker);
        UpdateMenus();                                  // refresh and actually make the new menu appear
      } //--- end SetUpMenus
      
      function Command (cmd) { //=== Assign functions to menu commands ==================================    
        switch (cmd) {
          case 4:
            PaletteCalcMarkers();    
            break;
        }
      } //--- end Command
      
      function PaletteCalcMarkers(){ //=== Palette for handling #calc markers ===========================
        wPalC.title = "FMcalc : Handle #calc Markers";
          wPalC.st1 = wPalC.add('statictext',undefined,"Marker contents");
          wPalC.st1.alignment = ['left',' '];
          wPalC.st1.graphics.font = ScriptUI.newFont(wPalC.st1.graphics.font.family,"BOLD",wPalC.st1.graphics.font.size);
      
          wPalC.sMarkerContent = wPalC.add('edittext',undefined, glbl.sCalcMarkerText, {multiline:true, scrollable:true});
        wPalC.sMarkerContent.graphics.font = ScriptUI.newFont ("Consolas", "", 12);
          wPalC.sMarkerContent.preferredSize.width = 580;
          wPalC.sMarkerContent.preferredSize.height = 65;
      //                                                //--- Button row Evaluate, Help, Cancel ---------
        wPalC.g4 = wPalC.add('group',undefined);
        wPalC.g4.alignment = ['fill',' '];
        wPalC.g4.margins= [0,0,7,0];                    // add right margin
            wPalC.g4.Cancel = wPalC.g4.add('button',undefined,"Cancel");
            wPalC.g4.Cancel.helpTip = "Dismiss dialogue panel";
            wPalC.g4.Cancel.preferredSize.width = 137;
      
        wPalC.g4.Cancel.onClick = function () {
          wPalC.close();
        };
        wPalC.show();
      } //--- end of PaletteCalcMarkers -----------------------------------------------------------------
      
        • 1. Re: Trapping the ghost
          K.Daube Level 1

          You may immediately spot the statement

          var wPalC  = new Window("palette", undefined, undefined);
          

          outside the dialogue function. Initially I had this within the dialogue function and there where no ghosts.

          But I needed to move it into the global area to be able to address dialogue items in the Notify (and other) function outside of the dialogue.

          I am now looking again, whether this is still necessary - if not it would probaly solve the ghost problem.

          • 2. Re: Trapping the ghost
            Russ Ward Level 4

            Hi Klaus,

             

            I was able to replicate this. Very interesting. I do not have time to study the code in detail to investigate, but I want to ask you about that statement, where wPalC is assigned a new window object. I would expect that statement to appear in the PaletteCalcMarkers(), as you suspected that someone might. It is possible that you could rewrite to avoid the need for a global variable, but in the interim, why not do this:

             

            - Define wPalC as a global, where it appears now, but do not assign the window object:

             

            var PalC;

             

            - Then, assign a new window object each time within PaletteCalcMarkers(). That is, put this statement at the beginning of the function:

             

            wPalC  = new Window("palette", undefined, undefined); 

             

            When I do it like that, the ghost is vanquished.

             

            Russ

            1 person found this helpful
            • 3. Re: Trapping the ghost
              Klaus Göbel Level 3

              Hi Klaus,

              you should create a group to add your edittext to this group.

              Then it works.

              Instead of

              // Instead of your line 40
              wPalC.sMarkerContent = wPalC.add('edittext',undefined, glbl.sCalcMarkerText, {multiline:true, scrollable:true});  
              
              
              // use these 2 lines
              
              var wPalCTextGroup = wPalC.add('group',undefined);  
              wPalC.sMarkerContent = wPalCTextGroup.add('edittext',undefined, glbl.sCalcMarkerText, {multiline:true, scrollable:true});  
              
              
              1 person found this helpful
              • 4. Re: Trapping the ghost
                K.Daube Level 1

                Dear Klaus and Russ,

                 

                Nine hours ago I was disappointed and frustrated, because non of your ideas was successful in the complete script:
                When I opened a new document (to the already open others) the document was white and switching to the other documents made them white also. And then the closing of one by one took 15 seconds for each, during which the document was visible, but the still open again became white... Even the final FM close took 20 sec.
                I closed Windows in frustration and went to the kitchen to prepare lunch.
                I even thought of some budget (USD 500) to hand over the problem to You ...
                After lunch and shopping (we were absent for some days and the fridge was completely empty) I checked the definitions in the script again:

                • Menu is active (not working with the debuggin menu which is just a list to select from)
                • var wPalC, wPalS, wPalDS; is global scope
                • Palette window is defined within panel function
                • The group is defined as Klaus suggests.

                Then I started FM-13, opened the first test document and started the script.
                I made exactly the same tests along the detailed protocol of the morning session.
                This time everything worked as expected!


                I have also found out, that a Console statement in a Notify function is pretty dangerous:
                If such a statement exists in the path of "Constants.FA_Note_PostActiveDocChange" which is activated by a menu action (opening one of the palettes), then both the palette and the console window are opened. They are somehow connected (the Slave in my noted post): Closing the console window also closes the palette. To get rid of this behaviour I must restart FM at least twice (without activating the script). IMHO there is something wrong in the State of Denmark (Hamlet)!
                Now I hope that the ghost has been defeated and the Slave is freed.


                A small detail is this (in the palette function):

                  wPalC  = new Window("palette", undefined, undefined);
                  wPalC.title = goTxt.wPalC;
                

                Does not define the title - it is empty in the displayed palette.

                 

                  wPalC  = new Window("palette", goTxt.wPalC, undefined);
                

                This displays the title...

                • 5. Re: Trapping the ghost
                  Klaus Göbel Level 3

                  Hi Klaus,

                  one of the problems could be, that one of the started scripts still was registered.

                  You MUST be sure, before testing, that all registered versions are unregistered.

                  • 6. Re: Trapping the ghost
                    K.Daube Level 1

                    Yes, Klaus, it's possible that I forgot to unregister before testing and hence run into the mess of white documents.

                    I would like to have (at the beginning of a script) a statement such as: "Clear the Situation" or "Reset Environment". In ESTK there is a Reset function in the Debug menu - which is absolutely necessary if const is used. But such a Reset is not available in plain ExtendScript. Hence I could not use const in the script and defined a global object

                    var glbl = {};
                      glbl.APP_NAME = "FMcalc";             // the name of the game, also name of flow and x-ref page;
                      glbl.FMCALC_VERSION = "1.0";          // current version of script (inc after publication)
                      glbl.TEMPLATE_FILE = "FMcalc_tpl.fm"; // name of template file (FM version 10)
                      ...

                    • 7. Re: Trapping the ghost
                      Klaus Göbel Level 3

                      Hi Klaus,

                       

                       

                      I would like to have (at the beginning of a script) a statement such as: "Clear the Situation" or "Reset Environment".

                      Reset in ESTK is (or can be) very dangerous and destructive, because it deletes ALL of used variables, not only these from that script you are degugging at the moment.

                      That is a task, that a programmer / scripter has to do accomplish. In some cases I do it at the start and at the end of a script.

                       

                      There are methods to avoid global variables. I need some time to prepare an example and then I will open a new thread.