Jython (Python) IDE, Editor and Java - On MacOS Catalina

Some interesting questions....:

OK, I have some scripts that work fine in Moneybot. These are Python/Jython and call Moneydance and Java classes (of course).

I have now installed IntelliJ IDE with the Python plug-in editor.

It was highlighting my imports of Moneydance modules/classes as 'Unresolved reference'. So I pointed my global libraries at the moneydance.jar file contained within my latest downloaded Moneydance application package. This seemed to work and most of the imports now have now underline. Interestingly, it still underlines AccountType on this line
'from com.infinitekind.moneydance.model.Account import AccountType'. Very odd, as it clearly does exist and works on Moneybot. Any ideas on this point?

Next, it doesn't recognise any of the from java xxx imports. They are all underlined as 'Unresolved references'. I have a bog standard Mac Catalina and haven't installed any Java JRE or JDKs.... Now clearly these scripts work, and I believe that Moneydance already contains Java within itself.... So, is there a way that I can point to the Moneydance self-contained Java libraries to resolve these references?

Also, any other editor / IDE tips for developing Moneydance Jython scripts..?

Thanks

  1. 1 Posted by Stuart Beesley ... on 30 Nov, 2020 07:32 AM

    Stuart Beesley - JUST A FELLOW USER's Avatar

    OK, I have all this working... Here's some notes for the record (in case others want to see it)....... :

    Regarding running outside of Moneydance:
    1) I see no practical way to test Python scripts ‘outside’ Moneydance…. I.e. how would they work as they rely on MD?

    ) Further the moneydance (and _ui and _data) variables are created by the Moneydance>MoneyBot>Python console, so again, these can only exist when MD is running the scripts.

    3) I can see conceptually that a Python script could open the MD data file itself, and then go from there calling the APIs, but (understandably) I don’t see an API method to actually open the MD data file… So no dice there..

    Regarding testing Python:
    FYI - whilst you need nothing other than a text editor to create MD Python scripts, I do now have IntelliJ IDE(A) configured to properly ‘manage’ Python(Jython) MD scripts - as follows:

    (IntelliJ seems more capable than PyCharm, but is from the same company)

    Rough steps

    Download/install IntelliJ (IJ)
    - add the Python addin (which is actually based on PyCharm)
    - add the Python 2.7 SDK into Platform settings
    - add(download) Adopt OpenJDK 14 (Hotspot) into IJ (this is what MD is built on)
    - open the MoneyDance application file / package contents and copy the contents somewhere for your project dev work
    - create a new project >> base it on Python 2.7
    - add a library (Java) and select all the .jar files within the application files you just copied from Contents/Java.
    - create/add a module called MoneyDanceApp
    >> select Java
    >>base it on OpenAdoptJDK 14
    >>in dependancies
    >>>>add/link to the library above you just created (as runtime)
    >>>>make sure adopt open JDK is listed
    >>>> add/link the contents directory from the MD contents you saved above and select classes and sources
    >>>> make sure the dependancy list is the MD Library, adoptJDK, module source, contents...

    - create another module called scripts
    >> based on Python 2.7
    >> in dependancies, add/link the MoneyDanceApp module you created above

    Now your code should recognise MD and resolve most references (not all).
    - It won’t resolve moneydance (and _ui and _data)
    - It won’t resolve the odd item within MD
    - It won’t resolve the odd Java item

    NOTE: We are using here the AdoptOpenJDK 14 which is what MD is built upon, but not the actual Java JRE that’s bundled with MD (I’ve found no way to do that, but not sure it matters too much).

    BUT on the whole it will help you manage your script better and look for errors.

    In addition, you can now create a debug/run configuration to run Moneydance within your IDE (it’s neat, but of no real use at the moment)
    >> Click add, application
    >> Main Class, type Moneydance (if you’ve done it right then this will resolve)
    >> Prog Args -d
    >> Working Dir = your MD data directory
    >> Use ClassPath of = MoneyDanceApp (that you created above)
    >> tick include dependancies with provided scope
    >> JRE = adopt-openJDK 14

    Then you can click RUN and MD will load. NOTE - make sure all other instances of MD are closed, also that it will not load your settings (due to sandboxing).. But all you need to do is copy config.dict
    From: /Users/xxx/Library/Containers/com.infinitekind.MoneydanceOSX/Data/Library/Application Support/Moneydance
    To /Users/xx/Library/Application Support/Moneydance
    Or wherever your system is storing its settings

    I’m now trying to workout how to go further, but that’s all for now…

    It has been suggested that: “you could write a java wrapper that launches moneydance... calling the com.moneydance.apps.md.controller.Main.main(argv) method. Then when that main method returns you could access the Main.mainObj static variable and get the python interpreter using Main.mainObj.getPythonInterpreter()” but I haven’t worked out how to do that yet, or what that would give me….

    If anyone improves the above setup, or go further, do shout..?

    It’s quite funny that you can create scripts with a plain text editor, or do all the above and get the same result…!!!

  2. Stuart Beesley - JUST A FELLOW USER closed this discussion on 30 Nov, 2020 07:32 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