Page 1 of 2

Using Python in Far

Posted: Mon 16 Feb, 2015 18:28
by jonib
Hi, Is there a way to use Python to make plugins or interact with Far in any way?
I haven't been able to decipher the Russian forum for anything useful about it.

jonib

Using Python in Far

Posted: Mon 16 Feb, 2015 22:02
by HaRT
Several years ago, there was a plugin to run IronPython scripts in Far (see links in this post). After that, the code was adapted to run via FarNet plugin, updated a couple of times, and later discontinued.
I haven't heard of any way to write plugins for Far in plain Python.

Using Python in Far

Posted: Mon 28 Dec, 2015 06:02
by techie
I find a way how to make C code accessible from Python http://techtonik.rainforce.org/2008/01/ ... h-gcc.html but could not find a way how to load Python from Far plugin.

Using Python in Far

Posted: Mon 28 Dec, 2015 13:38
by HaRT
techie wrote: how to load Python from Far plugin
Depending on the technology the plugin is based on, the approaches will differ. E.g. a plugin written in C++ might use Boost.Python. If the plugin is Qt-based, then PyQt might be more appropriate.

Using Python in Far

Posted: Tue 29 Dec, 2015 14:15
by techie
Plugin is in pure C, so I thought that maybe it is just possible to make it somehow load `python27.dll` dynamically. Python docs cover this to some degree https://docs.python.org/2/extending/embedding.html, but it kind of uncommon task for me to merge it with Far Manager.

As I understand there should be two shims (API adapters):

1. One that provides access to Far API from Python code
2. Another that allows Far API to call Python functions (callbacks etc.)

Using Python in Far

Posted: Tue 29 Dec, 2015 14:22
by HaRT
techie wrote: Plugin is in pure C
Why not use a more appropriate technology if Python integration is needed?

Using Python in Far

Posted: Wed 30 Dec, 2015 12:58
by techie
HaRT wrote:
techie wrote: Plugin is in pure C
Why not use a more appropriate technology if Python integration is needed?
What do you mean? Python is written in C.

Using Python in Far

Posted: Wed 30 Dec, 2015 13:45
by HaRT
techie wrote: What do you mean?
I mean why write the plugin in pure C when libraries for C++ supposedly provide for less-boilerplate-code bidirectional Python integration?

Using Python in Far

Posted: Wed 30 Dec, 2015 14:24
by techie
HaRT wrote: I mean why write the plugin in pure C when libraries for C++ supposedly provide for less-boilerplate-code bidirectional Python integration?
The problem is with bridge #1:
techie wrote: 1. One that provides access to Far API from Python code
and I don't know any sane way to call C++ from Python.

Using Python in Far

Posted: Wed 30 Dec, 2015 14:33
by HaRT
techie wrote: I don't know any sane way to call C++ from Python
Both Boost.Python and PyQt provide that. Your notion of “sane” might differ though.

Using Python in Far

Posted: Wed 30 Dec, 2015 15:41
by jonib
techie wrote:
techie wrote: 1. One that provides access to Far API from Python code
and I don't know any sane way to call C++ from Python.
At the moment at least my Python plugin uses cffi for Python to access C/C++. I like it as it moves most code to the Python side.

I'll try to post my code shortly, I'll just have to write some instructions how to use/compile.

jonib

Using Python in Far

Posted: Wed 30 Dec, 2015 17:27
by tstr
jonib> FUI
©pybind11 is a lightweight header-only library that exposes C++ types in Python and vice versa, mainly to create Python bindings of existing C++ code. Its
goals and syntax are similar to the excellent Boost.Python.

Using Python in Far

Posted: Wed 30 Dec, 2015 17:32
by cmd.exe
Boost.Python or cffi. It's really good idea.
If You like Boost.Python. I have like to seen far manager with it for compare.
If You like cffi. I have like to seen it too.

Using Python in Far

Posted: Wed 30 Dec, 2015 17:59
by jonib
tstr wrote:©pybind11 is a lightweight header-only library that exposes C++ types in Python and vice versa, mainly to create Python bindings of existing C++ code.
Thanks, looks like I missed it when I was looking for alternatives. I'll check it out next time I'm looking into alternative ways to bride C/C++ and Python.

jonib

Using Python in Far

Posted: Wed 30 Dec, 2015 18:03
by HaRT
jonib, please have a look at http://forum.farmanager.com/viewtopic.p ... 11#p134711 (just published).