Using Python in Far

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

Using Python in Far

Post by jonib » Mon 16 Feb, 2015 18:28

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: 8022
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 67 times
Been thanked: 99 times

Using Python in Far

Post by HaRT » Mon 16 Feb, 2015 22:02

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: 753
Joined: Mon 03 Oct, 2005 22:42
Has thanked: 26 times
Been thanked: 2 times

Using Python in Far

Post by techie » Mon 28 Dec, 2015 06:02

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: 8022
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 67 times
Been thanked: 99 times

Using Python in Far

Post by HaRT » Mon 28 Dec, 2015 13:38

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: 753
Joined: Mon 03 Oct, 2005 22:42
Has thanked: 26 times
Been thanked: 2 times

Using Python in Far

Post by techie » Tue 29 Dec, 2015 14:15

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: 8022
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 67 times
Been thanked: 99 times

Using Python in Far

Post by HaRT » Tue 29 Dec, 2015 14:22

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: 753
Joined: Mon 03 Oct, 2005 22:42
Has thanked: 26 times
Been thanked: 2 times

Using Python in Far

Post by techie » Wed 30 Dec, 2015 12:58

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: 8022
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 67 times
Been thanked: 99 times

Using Python in Far

Post by HaRT » Wed 30 Dec, 2015 13:45

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: 753
Joined: Mon 03 Oct, 2005 22:42
Has thanked: 26 times
Been thanked: 2 times

Using Python in Far

Post by techie » Wed 30 Dec, 2015 14:24

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 HaRT on Wed 30 Dec, 2015 14:30, edited 1 time in total.
Reason: Исправлено форматирование цитат

User avatar
HaRT
Moderator
Posts: 8022
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 67 times
Been thanked: 99 times

Using Python in Far

Post by HaRT » Wed 30 Dec, 2015 14:33

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: 72
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Using Python in Far

Post by jonib » Wed 30 Dec, 2015 15:41

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: 484
Joined: Thu 16 Apr, 2009 16:15
Has thanked: 2 times
Been thanked: 3 times

Using Python in Far

Post by tstr » Wed 30 Dec, 2015 17:27

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: 317
Joined: Fri 16 Apr, 2010 18:26
Location: Нижний Новгород
Has thanked: 168 times
Been thanked: 5 times
Contact:

Using Python in Far

Post by cmd.exe » Wed 30 Dec, 2015 17:32

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: 72
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Using Python in Far

Post by jonib » Wed 30 Dec, 2015 17:59

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: 8022
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 67 times
Been thanked: 99 times

Using Python in Far

Post by HaRT » Wed 30 Dec, 2015 18:03

jonib, please have a look at viewtopic.php?p=134711#p134711 (just published).
Фар есть инструмент, а не нянька. © 2009 DrKnS

jonib
Posts: 72
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Using Python in Far

Post by jonib » Wed 30 Dec, 2015 18:41

HaRT wrote: jonib, please have a look at viewtopic.php?p=134711#p134711 (just published).
Cool, thanks. I guess that's what I'm studying tonight. I'll wait to post my code until I have studied it to see if my code is still useful.

jonib

Post Reply

Return to “General Discussions”