access Freeplane files via Python API

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

access Freeplane files via Python API

nnako
Hi devs,

some years ago I started using Freeplane maps directly from their file representation (not only directly via the builtin editor GUI). Now, this usage has finally led into a stable Python API. It is far from complete concerning the coverage of all the activities possible with the Freeplane editor itself, but it covers the basics and it is under development and thus highly extensible.

I'd like to give it back and open its further development to the Freeplane community. As I want to submit to existing API interfacing standards, I would see the first further development step to adapt to the Java API interface. So users of the Python API don't have to learn another interface but can start with what they already know.


some working Python API examples

import freeplane

# get mindmap object
map = freeplane.Mindmap("path-to-mindmap.mm")

# search for node with specific id
node = map.findNodes(id="ID_12345678")[0]

# get plain text from that node
plaintext = node.PlainText

# navigate to parent of that node
parent = node.Parent

# get all the siblings of the node
lstSiblings = parent.Children

# get the value of the first sibling's attribute 'test'
value = lstSiblings[0].Attributes['test']


My question to you devs is, where would you recommend the sources for the Python API to reside? I would suggest to put and maintain it as an ordinary project directly connected with my personal GitHub account. Or would there be a better location for it?

What do you think?
Reply | Threaded
Open this post in threaded view
|

Re: access Freeplane files via Python API

Felix Natter
"nnako [via Freeplane Developer]" <[hidden email]>
writes:

> Hi devs,

hi Nnako,

> some years ago I started using Freeplane maps directly from their file representation (not only directly via the builtin editor GUI). Now, this usage has finally
> led into a stable Python API. It is far from complete concerning the coverage of all the activities possible with the Freeplane editor itself, but it covers the
> basics and it is under development and thus highly extensible.
>
> I'd like to give it back and open its further development to the Freeplane community. As I want to submit to existing API interfacing standards, I would see the
> first further development step to adapt to the Java API interface. So users of the Python API don't have to learn another interface but can start with what they
> already know.
>
> some working Python API examples
>
> import freeplane
>
> # get mindmap object
> map = freeplane.Mindmap("path-to-mindmap.mm")
>
> # search for node with specific id
> node = map.findNodes(id="ID_12345678")[0]
>
> # get plain text from that node
> plaintext = node.PlainText
>
> # navigate to parent of that node
> parent = node.Parent
>
> # get all the siblings of the node
> lstSiblings = parent.Children
>
> # get the value of the first sibling's attribute 'test'
> value = lstSiblings[0].Attributes['test']
>
> My question to you devs is, where would you recommend the sources for the Python API to reside? I would suggest to put and maintain it as an ordinary project
> directly connected with my personal GitHub account. Or would there be a better location for it?

This is a really cool idea, gratulations!

I wouldn't mind putting it under the github.com/freeplane umbrella.

The problem is that Dimitry maintains the java api in parallel. So maybe
it is possible to wrap this code to always be up-to-date and correct?

Cheers and Best Regards,
--
Felix Natter
debian/rules!
Reply | Threaded
Open this post in threaded view
|

Re: access Freeplane files via Python API

Dimitry Polivaev
Administrator
In reply to this post by nnako
Hello Nnako,

recently Freeplane has got a java API which allows to use Freeplane embedded in any Java applications both in user interface mode and headless mode. I think that parallel development and long term support of the comparable features directly in Python is too expansive.  Python developers could try to use it using jython, http://www.jython.org/. However jython seems to be a dead project. Someone could therefore try to use some methods described at https://stackoverflow.com/questions/3652554/calling-java-from-python/3793523 or similar.

Whatever project you start you can use Freeplane forum and wiki to place links to it. However I do not see myself accountable for this integration. Therefore I do not see it a part of Freeplane project.

Regards,
Dimitry

> Hi devs,
>
> some years ago I started using Freeplane maps directly from their file representation (not only directly via the builtin editor GUI). Now, this usage has finally led into a stable Python API. It is far from complete concerning the coverage of all the activities possible with the Freeplane editor itself, but it covers the basics and it is under development and thus highly extensible.
>
> I'd like to give it back and open its further development to the Freeplane community. As I want to submit to existing API interfacing standards, I would see the first further development step to adapt to the Java API interface. So users of the Python API don't have to learn another interface but can start with what they already know.
>
Reply | Threaded
Open this post in threaded view
|

Re: access Freeplane files via Python API

h.goebel
Hi all,

Am 11.11.2018 um 20:49 schrieb Dimitry Polivaev [via Freeplane Developer]:
> recently Freeplane has got a java API which allows to use Freeplane
> embedded in any Java applications both in user interface mode and
> headless mode. I think that parallel development and long term support
> of the comparable features

AFAIU, Nnako was not referring to embedding Freeplane into applications,
but he implemented an API for easily manipulating .mm files. This
basically comes down to some xml manipulations API, specialized on .mm
files.

IMHO this is a good idea and should be included under the
github.com/freeplane umbrella, as Felix suggested.

@Nnako: From the example you posted, it looks like this is using a quite
uncommon way to work with xml-documents (while I'm not an expert on
this). I'm interested in reviewing the code. Where can I find it?


BTW: Embedding a java application for just mm-file manipulation ins not
only much too much effort, but also much too much overhead.

> Someone could therefore try to use some methods described at
> https://stackoverflow.com/questions/3652554/calling-java-from-python/3793523 or
> similar.

To quote from there: "the last release is from Jan 2009 and I see people
failing to compile JPype."


--
Regards
Hartmut Goebel

| Hartmut Goebel          | [hidden email]               |
| www.crazy-compilers.com | compilers which you thought are impossible |


--
Regards
Hartmut Goebel

| Hartmut Goebel          | h.goebel@crazy-compilers.com               |
| www.crazy-compilers.com | compilers which you thought are impossible |
Reply | Threaded
Open this post in threaded view
|

Re: access Freeplane files via Python API

Felix Natter
"h.goebel [via Freeplane Developer]" <[hidden email]>
writes:

> Hi all,

hi Hartmut,

> Am 11.11.2018 um 20:49 schrieb Dimitry Polivaev [via Freeplane Developer]:
>> recently Freeplane has got a java API which allows to use Freeplane
>> embedded in any Java applications both in user interface mode and
>> headless mode. I think that parallel development and long term support
>> of the comparable features
>
> AFAIU, Nnako was not referring to embedding Freeplane into applications,
> but he implemented an API for easily manipulating .mm files. This
> basically comes down to some xml manipulations API, specialized on .mm
> files.

Dimitry does not refer to "embedding Freeplane into application", but he
extracted a *standalone* API for manipulating *.mm from Java programs,
not for remote controlling Freeplane.

> IMHO this is a good idea and should be included under the
> github.com/freeplane umbrella, as Felix suggested.

It definitely is a good idea. The problem is that Dimitry developed the
same thing in Java (project freeplane_api) in Java, which he maintains.

Half a year ago, this would have been a *great* project, but maybe it's
very useful even today?

> @Nnako: From the example you posted, it looks like this is using a quite
> uncommon way to work with xml-documents (while I'm not an expert on
> this). I'm interested in reviewing the code. Where can I find it?
>
> BTW: Embedding a java application for just mm-file manipulation ins not
> only much too much effort, but also much too much overhead.

The advantage is that if we track Dimitry's jar, we always get updates
and bug fixes.

>> Someone could therefore try to use some methods described at
>> https://stackoverflow.com/questions/3652554/calling-java-from-python/3793523 or
>> similar.
>
> To quote from there: "the last release is from Jan 2009 and I see people
> failing to compile JPype."

Maybe there are other solutions for calling Java from Python?
@Nnako: Can you think of something?

Cheers and Best Regards,
--
Felix Natter
debian/rules!
Reply | Threaded
Open this post in threaded view
|

Re: access Freeplane files via Python API

h.goebel
Hi Felix,
> AFAIU, Nnako was not referring to embedding Freeplane into applications,
> but he implemented an API for easily manipulating .mm files. This
> basically comes down to some xml manipulations API, specialized on .mm
> files.

Dimitry does not refer to "embedding Freeplane into application", but he
extracted a *standalone* API for manipulating *.mm from Java programs,
not for remote controlling Freeplane.

IC. I did not get this. Thanks.

(But I don't understand why freepane_api includes e.g. Controller.setStatusInfo(), which is not required for file manipulation.)

> BTW: Embedding a java application for just mm-file manipulation ins not
> only much too much effort, but also much too much overhead.

The advantage is that if we track Dimitry's jar, we always get updates
and bug fixes.

This is absolutely true. But as I said: Using Java from within Python is terrible and requires spawning a JVM in the background. IMHO this is a bad idea.

Additionally I just poked around at the files in freeplane_api. I did not much going beyond interfaces defining getters and setters., most of which use strings, ints and booleans as arguments. I understand this is the Java way to do it. Beside some data-validation: What did I miss?

From what I've seen at freeplane_api, I assume nobody using Python would take the effort to make freeplane_api accessible from within Python plus the JVM-overhead for "just" some XML manipulation - most of which is covered by e.g. lxml.etree anyway.
-- 
Regards
Hartmut Goebel

| Hartmut Goebel          | [hidden email]               |
| www.crazy-compilers.com | compilers which you thought are impossible |
--
Regards
Hartmut Goebel

| Hartmut Goebel          | h.goebel@crazy-compilers.com               |
| www.crazy-compilers.com | compilers which you thought are impossible |
Reply | Threaded
Open this post in threaded view
|

Re: access Freeplane files via Python API

Dimitry Polivaev
Administrator
Hi folks,

>> Dimitry does not refer to "embedding Freeplane into application", but he
>> extracted a *standalone* API for manipulating *.mm from Java programs,
>> not for remote controlling Freeplane.

actually, the freeplane API I implemented starts Freeplane instance in the same process, which can run with or without UI. When it is run without UI it gives you a reference to HeadlessMapCreator with limited set of operations.

> (But I don't understand why freepane_api includes e.g. Controller.setStatusInfo(), which is not required for file manipulation.)

This method can not be used without UI.

> Using Java from within Python is terrible and requires spawning a JVM in the background. IMHO this is a bad idea.

I have no opinion. If someone implements parts of Freeplane functionality in any other language than Java it is fine.

However such project can be partner of Freeplane project but not a member of Freeplane project because Freeplane team can not be made accountable for it.

Regards,
Dimitry
Reply | Threaded
Open this post in threaded view
|

Re: access Freeplane files via Python API

nnako
Sorry for the silence, devs. I didn't even manage to put the code "online", yet.

AIM OF THE PYTHON API

The idea is: creating / using a Python API with a small footprint to directly access a mindmap file. This has the potential to be used on even the smallest microcontroller system or any linux, MAC or DOS console. For my use case, it would make no sense to carry the heavy Java codebase with me, as many microcontrollers generally don't even provide a graphical user interface nor have other necessary features. I aim for fast and direct information retrieval / manipulation. In a way, this is like using a Freeplane mindmap file as an information database, and the GUI-based Freeplane editor merely as one possible other, but visually oriented, user interface. In a way, The Python API could act as an alternative to the Groovy API. Just not called from WITHIN but from OUTSIDE the Freeplane editor.

JAVA in Python

As Hartmut already mentioned, using JAVA from within a Python interpreter (e.g. with Jython) has its disqualifying limitations. This corresponds to my own experience regarding application size, execution speed and cross-platform usability. I have not been able to realize any successful project using Jython, yet (maybe I am not smart enough, though). Even if there are other promising In-Python-Java-Usage-Possibilities like JPype, Pyjinius, Py4j,... I would think, they would aim for overkill in this case.

I would definitely want to continue maintaining the Python API's codebase myself. Even if it resides apart from the Freeplane project.

@Hartmut: Yes, under the hood, the Python API is using xml.etree.ElementTree . I'd love see you review the codebase :-)

Please be patient. I will announce the API as soon as I got it online.