-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get started with Python plugins? #2382
Comments
@m32 ? |
Did you read python/configs/plug/plugins/read-udebug-en.txt (contains info about VS Code python plugins debugging) and read-en.txt?
|
Yes I did. Did you read my issue? There is nothing in /tmp/. Does it mean that plugin is meant to be impossible to debug unless you use VS Code? It should report crashes somewhere no matter what. |
https://github.com/elfmz/far2l/wiki/Running-far2l-with-debug-logging-enabled https://github.com/akruphi/far2l/wiki Missing /tmp/far2l-py file means, I suggest, the python plugin "subsystem" is not loaded. Check the far2l debug log. |
Not sure if this environment variable helped, but now there is a /tmp/far2l-py file, thanks. |
@faerot from pluginmanager.py:
mkdir ~/.config/far2l/plugins/python after restarting far2l the login should be visible in the file debugging is a bit more complicated, I use vscode with the "attach to python" configuration if the interpreter hits: then in vs code you will go to debug this place in other words you use the debugger as if you were debugging remote code, the same with docker containers, flask, fastapi, remote rpi, ... you can also load plugins automatically and that's what plugins.ini is for |
documentation - I don't know what to document since the plugin adds by itself:
self.ffi is a wrapper to low-level functions from cffi like new,cast,string, ... documented by cffi
|
The only place that can be mysterious is the dialogbuilder. I don't like calculating the size of controls and their position, and just like wxPython does with sizers, this is how dialogbuilder works. HSIZER arranges controls horizontally, and VSIZER vertically. Several controls are supported, and the principle is always the same: dialogbuilder then materializes own variable ID_vshow, which can be used in the function handling the dialog, i.e.: |
@m32 Better than nothing, so still appreciated the hard work, but in order to make the plugin writing process enjoyable, I will have to add an abstraction layer around those cffi calls.
You say that as if there is a documentation of C++ plugins API. Or is there? So I will not have to figure our the hard way why FCTL_GETPANELINFO returns 0/1 and FCTL_GETCURRENTPANELITEM returns items size. |
I meant the cffi documentation, not the far plugin creation documentation. |
I don't really see any possibility of writing some general classes that would free me even more from the C API. |
cffi for me is not a problem, becuase it is common and well documented library. The problem is Far plugin API. Currently I am using an old help file from Far 1.70, but it is out of date in many places. |
I am currently finishing a simple plugin, once I will do, I will post it's source code to give you an idea of what I meant. |
Probably we need a wiki article like "developing a python plugin: getting started" :) |
Ok, I have written a small plugin. Back in the days of Far 1.70 there was a plugin which allowed to jump between selected files on the panel. This was very helpful if you have thousands or even tens of thousands files in the directory, select some of them by mask and wants to figure out which files were actually selected. I have bound those jumps to Alt+Up and Alt+Down. Here is the implementation of this plugin, when all of the Far details are abstracted away in the pythonic library: from yfar import FarPlugin
class Plugin(FarPlugin):
label = "Jump Between Selected Files"
openFrom = ["PLUGINSMENU", 'FILEPANEL']
def OpenPlugin(self, _):
panel = self.get_panel()
option = self.menu(('Jump to &Previous Selected File',
'Jump to &Next Selected File'), self.label)
if option == 0: # move up
for f in reversed(panel.selected):
if f.index < panel.cursor:
panel.cursor = f.index
break
elif option == 1: # move down
for f in panel.selected:
if f.index > panel.cursor:
panel.cursor = f.index
break This not pseudo-code, but an actual working plugin code. This is what I meant when said I was hoping for a pythonic interface to Far. This kind of interface (especially if properly documented) would make writing plugins for far a breeze, even for not very technically savvy people. Library attached. yfar.zip Also question - how to make some of the python plugins auto-load on Far start without the need to |
copy Plugins/python/plug/plugins/plugins.ini to ~/.config/far2l/plugins/python, in [autoload] section add next line with file name without suffix (.py) under what name this plugin is available, like below for ucharmap.py: |
added to far2l :) |
log is undefined ;) |
LOL. It was only a proof of concept and implements only limited number of methods necessary to implement said plugin posted above, I don't think it is worth adding there in it's current stage. It could turn out into proper library eventually though, if I will be writing more plugins and adding more interfaces. |
Yeah, was a bit too hard on cleaning things up before uploading. yfar.py needs
|
release often, release early maybe someone else will find it useful api is not stable either, but it's always better to have something than nothing |
Alright, I plan to implement at least couple of plugins that I miss from windows far, so will extend that library as well. |
@m32 how to make Python plugin menu appear only in panels and not in editor? |
python is queried for settings, and it queried all loaded plugins for settings, hence the sharing, see #2337 |
I don't understand that issue, it's about hotkeys shifting. I am saying that when you press F11 in panels and F11 in editor, how to make plugin to be displayed in panel plugin list, but not in editor plugin list. |
GetPluginInfo should return information about available options in DiskMenu, PluginsMenu and PluginConfig - this is taken from each python plugin. |
So in other words - it is impossible, if I understand it correctly. |
far2l when opening a plugin (OpenPlugin), tells where to get it from (OpenFrom parameter) and additionally gives a number from the list obtained from the GetPluginInfo call - it looks very confusing to me and I couldn't handle it. At the moment I haven't come up with anything better, and there was a time when the plugins I selected from the menu wouldn't open :) |
It would be great to see your library and plugins on GitHub as a repository. |
The python plugin is part of far2l, so it's best to clone the repository and add fixes (PR's) in the normal way. By the way, maybe it's time to add some plugin to manage add-ons? |
Ok, I have created a pull request with 2 new plugins and a (work-in-progress) library. |
Pull request was merged, I assume the issue is sort of closed, at least for me. |
I am trying to write a Python plugin, but I have faced a number of problems right off the bat:
It is a shame, because Python is such and easy and powerful language that would allow to quickly re-implement most of the plugins for windows FAR, if only it had proper documentation and debug tools. Right now the barrier to entry for most of the new users looks impossible.
The text was updated successfully, but these errors were encountered: