On 14-04-25 10:18 AM, Pavel Roschin wrote:
On 14-04-24 09:44 PM, Pavel Roschin wrote:
I'm played with GeanyPy plugin and faced with a problem.
Here is the source code I created to get current document from sidebar:
def press(self, widget, event, data=None): if event.button != 2: return mod, it = widget.get_selection().get_selected() doc = mod.get(it, 2)[0]
According to sidebar.c, mod.get(it, 2) should return pointer to Document.
This isn't supported/recommended to do in either Geany plugin API or GeanyPy, but see below.
But how can I do this in native way? I just want to implement simplest feature I proposed in PR #172 which seems will take forever to accept.
I just meant it's not recommended for plugins to rely on the tree view implementation stuff like which tree model columns have various things packed in them and such just because it's undocumented and could change anytime. Anyway, you are of course free to do anything you want, and if that's the only way, what else can you do? :)
If you really want to, maybe try to call the C function `Document_create_new_from_geany_document()` (in src/geanypy-document.[ch]) which is used by GeanyPy internally, but should be callable somehow from Python.
How can I call this function? I could try to use ctypes to load library but I didn't find native way to get full path to geanypy library.
It should be in the "current" library (not sure correct term), like if it was C, you would call `dlopen(NULL, ...)`. I'm not familiar enough with ctypes to say exactly but if it had a function like `load_library()` I'd expect you would pass `None` where it expects a filename. Alternatively, you might try `geany.document.__file__` to pickup the C module's filename where the symbol lives, if that works.
Cheers, Matthew Brush