How to auto run Python extension

I have successfully created Python extensions.
They appear as menu items on the extension menu. This is ok.
How can I get a python extension to auto run at MD start, rather than when the user selects from menu? (Like a normal Java extension can do).

Thanks.

  1. 1 Posted by hleofxquotes on 24 Jan, 2021 06:33 AM

    hleofxquotes's Avatar

    Don't define the actions structure in your script_info.dict. This will effectively disable the "add to menu insertion".

    I have some old notes that the following works in the past. Not sure if it still is.

    In your Python code

    • Create a Python class. Instantiate and assign to a variable named moneydance_extension. Something like this
      moneydance_extension = MyAwesomeExtension()
      
    • In your Python class, define two methods 'initialize' and 'invoke'.
    • 'initialize' will get called when your extension is initialized. Here you do stuff like register for a new "menu item" for a "feature"
    • 'invoke' is the callback when your feature calls (that you registerd in initialize
    class MyAwesomeExtension(object):
    
        def initialize(self, extension_context, extension_object):
            self.moneydanceContext = extension_context
            self.moneydanceExtensionObject = extension_object
    
            self.moneydanceContext.registerFeature(extension_object, "awesome", None, "Test awesome")
            
        def invoke(self, eventString=""):
            self.moneydanceContext.setStatus("Python extension received command: %s" % (eventString))
    
  2. 2 Posted by Stuart Beesley ... on 24 Jan, 2021 06:55 PM

    Stuart Beesley - JUST A FELLOW USER's Avatar

    Hi, Thank you!!!! I suspect this is not desired behaviour, but yet it works of a fashion… It creates a problem with the moneydance_xx variables not being set, but I think I can get around that… This will enable me to play..

    Thanks again….

  3. 3 Posted by Stuart Beesley ... on 24 Jan, 2021 09:34 PM

    Stuart Beesley - JUST A FELLOW USER's Avatar

    .

  4. 4 Posted by Stuart Beesley ... on 25 Jan, 2021 12:33 PM

    Stuart Beesley - JUST A FELLOW USER's Avatar

    Closing as the method above answers the question - thanks

  5. Stuart Beesley - JUST A FELLOW USER closed this discussion on 25 Jan, 2021 12:33 PM.

  6. Sean Reilly re-opened this discussion on 25 Jan, 2021 02:14 PM

  7. Support Staff 5 Posted by Sean Reilly on 25 Jan, 2021 02:14 PM

    Sean Reilly's Avatar

    I'd like to make it easier to create and package python extensions and am planning to add actions for initialisation, file open/close, and others to the script_info keys. Would that solve the problem here?

    --
    Sean Reilly
    Developer, The Infinite Kind
    https://infinitekind.com

  8. 6 Posted by Stuart Beesley ... on 25 Jan, 2021 02:31 PM

    Stuart Beesley - JUST A FELLOW USER's Avatar

    Hi Sean. Thanks for reply. How would your extra actions work? E.g. I know ‘menu’ adds the script to extensions menu and then when selected the whole script runs. This is how Toolbox currently runs.

    So how would a file/open action work for example? Would this be a trigger sent to a script pre-defined method when a MD file opens? A bit like the existing pre-defined notifications for Java extensions..?

    The beauty of the ability just to run the script when MD launches is that it can self install as an extension and then it’s loaded as a class which can get on with stuff, rather than just waiting for the user to click something.

    I’ve got an experimental python extension running (just for learning) that does just this and listens to MD notifications...

    Perhaps we need a ‘auto-run’ action item too?

    Would be happy to trial/test a file/open action when I understand how it would work?

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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