Native python interface for ggb files

messersm shared this question 11 years ago
Answered

Hi there.


I'm looking for a native python interface for ggb-files - meaning, I need a python module, that enables me to write a ggb-file from a python script.


e.g.:


    #!/usr/bin/env python

    # -*- coding: utf-8 -*-


    import ggb


    f = ggb.open("example.ggb")

    # ...

    f.close()


I know, that geogebra 5 will have python-scripting support from within geogebra, but I would like to access these ggb-files from an external module.


I tried to get it running, with the source from https://dev.geogebra.org/sv..., but the python-code seems connected very close to the geogebra-application.


If such a native python interface does not exist, it would be worth writing, i guess (and we're talking about simple xml after all)...

Comments (9)

photo
1

(You can use GeoGebra from a stand-alone script written in JPython or JRuby, but since you've emphasized "native" I assume you already know about that.)


I don't think you can use native Python because you need the "brain" of GG. E.g., when you do "C = MidPoint[A, B]", point C has to be computed and its element then added to the .ggb file. You'll have to re-implement the GeoGebra kernel, and this isn't feasible. But that's about *writing* ggb files. If you just want to extract some information from the ggb file it could be easy.

photo
1

Do you mean something like this? (ie to create a nice diagram from Python rather than Maple)

http://daveagp.wordpress.co...


Or something else?

photo
1

Thanks alot for answering.


@murkle: I thought of something like this, but with a clean (an platform-independent) interface to access ggb file from python.


@mooffie: Your ruby-script looks good. I would be completly happy, if I could write python code to access the geogebra-kernel (even if the interpreter is not cpython). Do I understand you correctly, if I say, I just need to use jpython, since this interpreter already has access to java (because it is java) and will have access to geogebra this way:


python <--- (interprets) jpython (has access to) -> java -> geogebra


Am I right? What would a example script look like for jpython?

photo
1

@murkle: I thought of something like this, but with a clean (an platform-independent) interface to access ggb file from python.


http://dev.geogebra.org/tra...

photo
1

How do I access the link given? It says "forbidden" (http://dev.geogebra.org/tra...)

photo
photo
1

Do I understand you correctly, if I say, I just need to use jpython, since this interpreter already has access to java

Yes, that's right. You can use almost any language whose compiler compiles into JVM: JPython, JRuby, Groovy, Clojure, etc.


The code I gave is a straighforward tranlsation of this GeoGebraPanel code to Ruby. JPython code should be very similar. See the JPython documentation for instructions on how to pull in JAR files (I don't have ready code as I'm not programming in JPython).


to access the geogebra-kernel

In theory, you'll have access to most parts of GeoGebra. Note, however, that the official GeoGebra is shipped in "obfuscated" form: class names and properties are mangled --to make them shorter-- purportedly to make the JAR files smaller. The only names that aren't mangled, and therefore the only names you can access (if you're using the official GeoGebra distribution) are the aforementioned GeoGebraPanel class and the GgbAPI (that link talks about using it from JavaScript, but it doens't really matter which language you use; @murkle gave you another link referring to it). You'll have to compile GeoGebra yourself if you want access to anything else (The GG developers may scoff at you for using anything other than GgbAPI because GG's code is changing and internal APIs you use today may not be there tomorrow).

photo
1

Note, however, that the official GeoGebra is shipped in "obfuscated" form: class names and properties are mangled --to make them shorter-- purportedly to make the JAR files smaller. The only names that aren't mangled, and therefore the only names you can access (if you're using the official GeoGebra distribution) are the aforementioned GeoGebraPanel class and the GgbAPI (that link talks about using it from JavaScript, but it doens't really matter which language you use; @murkle gave you another link referring to it). You'll have to compile GeoGebra yourself if you want access to anything else (The GG developers may scoff at you for using anything other than GgbAPI because GG's code is changing and internal APIs you use today may not be there tomorrow).


There is another API which is not obfuscated, the one used by the Python module to communicate with GeoGebra:


PythonFlatAPI


(it's called 'Flat' for historical reasons, there the previous API was called PythonAPI and the new one is a flattened version of it...)


Cheers,


Arnaud

photo
1

It was a stupid idea to move the Geogebra user forum to "reddit". We used to have a lively and creative forum - that's over now. Anyway, I will never join reddit.

© 2023 International GeoGebra Institute