Using Python in Far

You want to talk about Far Manager, but don't know where to turn?
jonib
Posts: 73
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Using Python in Far

Post 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
Last edited by jonib on Mon 28 Sep, 2015 15:41, edited 1 time in total.
User avatar
HaRT
Moderator
Posts: 10823
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

Using Python in Far

Post 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.
Фар есть инструмент, а не нянька. © 2009 DrKnS
User avatar
techie
Posts: 795
Joined: Mon 03 Oct, 2005 22:42
Has thanked: 35 times
Been thanked: 6 times

Using Python in Far

Post 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.
User avatar
HaRT
Moderator
Posts: 10823
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

Using Python in Far

Post 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.
Фар есть инструмент, а не нянька. © 2009 DrKnS
User avatar
techie
Posts: 795
Joined: Mon 03 Oct, 2005 22:42
Has thanked: 35 times
Been thanked: 6 times

Using Python in Far

Post 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.)
User avatar
HaRT
Moderator
Posts: 10823
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

Using Python in Far

Post by HaRT »

techie wrote: Plugin is in pure C
Why not use a more appropriate technology if Python integration is needed?
Фар есть инструмент, а не нянька. © 2009 DrKnS
User avatar
techie
Posts: 795
Joined: Mon 03 Oct, 2005 22:42
Has thanked: 35 times
Been thanked: 6 times

Using Python in Far

Post 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.
User avatar
HaRT
Moderator
Posts: 10823
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

Using Python in Far

Post 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?
Фар есть инструмент, а не нянька. © 2009 DrKnS
User avatar
techie
Posts: 795
Joined: Mon 03 Oct, 2005 22:42
Has thanked: 35 times
Been thanked: 6 times

Using Python in Far

Post 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.
Last edited by techie on Thu 01 Jan, 1970 01:00, edited 0 times in total.
Reason: Исправлено форматирование цитат
User avatar
HaRT
Moderator
Posts: 10823
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

Using Python in Far

Post 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.
Фар есть инструмент, а не нянька. © 2009 DrKnS
jonib
Posts: 73
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Using Python in Far

Post 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
tstr
Posts: 557
Joined: Thu 16 Apr, 2009 16:15
Has thanked: 20 times
Been thanked: 9 times

Using Python in Far

Post 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.
User avatar
cmd.exe
Posts: 378
Joined: Fri 16 Apr, 2010 18:26
Location: Нижний Новгород
Has thanked: 181 times
Been thanked: 10 times
Contact:

Using Python in Far

Post 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.
I've been using Vim for about 2 years now, mostly because I can't figure out how to exit it. (c) I Am Devloper
I know nothing except the fact of my ignorance. (с) Socrates
jonib
Posts: 73
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Using Python in Far

Post 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
User avatar
HaRT
Moderator
Posts: 10823
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

Using Python in Far

Post by HaRT »

jonib, please have a look at http://forum.farmanager.com/viewtopic.p ... 11#p134711 (just published).
Фар есть инструмент, а не нянька. © 2009 DrKnS
Post Reply

Return to “General Discussions”