Hi, I am a user and quite new to Python. As I understand it:
- Moneydance MoneyBot uses Jython 2.7 - i.e. Java base - and is the latest available for now
- No - you have to run these scripts within the MD environment/console.
- I believe you can run a Java IDE to run Java (from within MD), but others will have to explain that.
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.
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..
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)
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
>>>>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…!!!