Search code examples
stdoutipythonstdingimppython-fu

Using ipython as the gimp py-fu interpreter, sending all output and input to the terminal


Ideally I'd like to be able to start gimp from a terminal, then have that terminal behave as an ipython interpreter for gimp. Someone in this thread on gimp forums (http://gimpforums.com/thread-use-console-as-ipython-gimp-interpreter?pid=20373#pid20373) suggested that I modify my /usr/lib/gimp/2.0/interpreters/pygimp.interp file.

I've taken some guesses, but I have not been successful in tweaking things or finding any documentation on this file.

Assuming that this file could be modified to change which binary gimp uses on activation of the interpreter, what could I do to then send the output and input to stdout and stdin respectively?

Thanks a lot :)


Solution

  • You can simply add this plugin: ~/.gimp-2.8/plug-ins/ipython_console.py,

    #!/usr/bin/env python                                                                                            
    import gimpfu                                                                                                    
    import gimp                                                                                                      
    import IPython                                                                                                   
    from gimpfu import pdb                                                                                           
    gimpfu.register("IPython-Console", "IPython Interpreter",                                                        
                    "Launches IPython interpreter in terminal",                                                      
                    "Nic", "Nicolas CORNETTE", "2014",                                                               
                    "<Image>/Filters/Languages/Python-Fu/_IPython Console",                                          
                    "", [], [], lambda image,layer: IPython.embed())                                                 
    gimpfu.main()                                                                                                    
    

    Now if I launched Gimp from terminal, I can open Filters -> Python-Fu -> IPython Console, then use IPython from terminal.4

    you can also have a look here for an slightly improved version : https://gist.github.com/ncornette/8b799c0345eaba56cc8c

    Avoid pressing Ctrl+C in terminal !