Menu

#2424 scripting getApplication() returns None for new window

nextrelease
open-fixed
nobody
None
5
2022-02-08
2022-01-05
No

The getApplication() returns the application itself, so that it can be scripted. Actions like https://github.com/autoplot/dev/blob/master/demos/tools/editor/commit.jy use it to get a reference to the script itself to add actions to the editor.

Sadie and I noticed where the new commit action doesn't work because getApplication() doesn't work in new windows, and a runtime error occurs.

To demo:

  1. start Autoplot
  2. in the script editor, run the script "print getApplication()"
  3. note that toString is called on the AutoplotUI object.
  4. File->New Window
  5. in the new window's script editor, run the script "print getApplication()"
  6. note that "None" is printed, rather than the second AutoplotUI object.

Discussion

  • Jeremy Faden

    Jeremy Faden - 2022-01-05

    This is an old problem, really, where the ScriptContext is a static context, so there can really only be one script running. Since scripts usually don't use the getApplication command, we haven't noticed. The context is automatically set when two windows are running, which gives the sense that multiple contexts are supported but this isn't completely true, and some squirrelly behavior can occur, like where the consoles don't have the same thing or where setStatus called in one resets the status in another.

    I did "fix" it though by making sure that the application is set when running within a second window. I need to see that this works properly with the Git commands.

     
  • Jeremy Faden

    Jeremy Faden - 2022-01-09

    I verified that this fixes the git commands in a second window.

     
  • Jeremy Faden

    Jeremy Faden - 2022-02-08
    • status: open --> open-fixed
     
MongoDB Logo MongoDB