REQUEST: Pass .handleEvent() .cleanup() .unload() methods through to Python extensions from the PythonExtension container

Stuart Beesley (Mr Toolbox)'s Avatar

Stuart Beesley (Mr Toolbox)

28 Feb, 2021 12:09 PM

I would like to get my Python extensions operating properly, like Java extensions. Unfortunately, there are some methods that don't reach the Py extension class due to the implementation within Moneydance. When a Py Extension is loaded, the Py Interpreter is invoked (of course), and this Python Interpreter Instance (PyII) is registered as the Moneydance extension. This PyII maintains a reference to the actual Python extension class that the user/script defined and PyII calls this when necessary.

Hence:
- Java Extension: Extension Container -> Java Extension Class(and its methods) - Python Extension: Extension Container(Py) -> Python Interpreter Instance(PyII) -> Py Extension(and its methods).

Thus, PyII is 'blocking' certain things....

Thankfully, PyII does pass through .invoke() so Py extensions can handle .showURL() calls. This is so the "menu" method works.

But the following are not passed through:
.handleEvent() .cleanup() .unload()

Please can the PythonExtension class be tweaked to pass through these methods(), the same as .invoke() to allow Py extensions to:
- Properly handle MD events - Unload properly when uninstalled.

On the latter point, the effect of a Py extension uninstall is that the PyII gets killed, but the underlying Py extension is still operating in memory (until MD restart)..

Many thanks!!

  1. 1 Posted by Stuart Beesley ... on 20 Mar, 2021 12:36 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    This should be in build 3055. I will test and advise..

  2. 2 Posted by Stuart Beesley ... on 22 Mar, 2021 10:12 AM

    Stuart Beesley (Mr Toolbox)'s Avatar

    These methods are now available in build 3056 onwards - there are two options:

    1/ in script_info.dict define {"type" = "method", "method" = "handle_event", "script_file" = "handle_event.py"} for example. The methods are handle_event, invoke, cleanup and unload. Within these method scripts, look for the global variable moneydance_extension_parameter for the passed parameter on invoke and handle_event.

    2/ .. or instead define and execute an initialisation script when MD loads by defining the following in script_info.dict. {"type" = "initializer", "script_file" = "scriptname.py"} and within your script, define and execute your ExtensionClass and call the class, setting the global variable moneydance_extension=ExtensionClass(). Within this class define .invoke(), .handle_event(), .cleanup(), unload().

    NOTE - I don't think .cleanup() actually is used anywhere in MD...

    NOTE - There are some 'older' methods of tricking MD to load a Py Extension, some work, some don't now; contact me if you want further details....

  3. Stuart Beesley (Mr Toolbox) closed this discussion on 22 Mar, 2021 10:12 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac