geanypy icon indicating copy to clipboard operation
geanypy copied to clipboard

Option to completly reload a plugin

Open frlan opened this issue 10 years ago • 21 comments

On developing a plugin it would be quiet useful to complete unload and load a given plugin instead of restarting Geany complete.

frlan avatar Feb 20 '15 06:02 frlan

Assuming you mean python plugins, then you can already load and unload them, its just that if they crash they might leave the system in an unknown state (like a Geany plugin can crash geany).

elextr avatar Feb 21 '15 01:02 elextr

Am 21.02.2015 um 02:14 schrieb elextr:

Assuming you mean python plugins, then you can already load and unload them, its just that if they crash they might leave the system in an unknown state (like a Geany plugin can crash geany).

Maybe my observations are wrong, but I've got the feeling that it's not reloaded from disc. So doing a change on geanypy-plugin is not applied after deactivating and reactivating plguin.

frlan avatar Feb 21 '15 07:02 frlan

Ahh, yes, you are right, the module is never unloaded, like Geany itself which opens the dll to get the info for the plugin dialog, geanypy loads the plugin module to get the info for its plugin manager. But this seems to only happen at startup, then the dialog is populated and doesn't seem to be reloaded.

By the way Geanypy continues Geany's confusing terminology where "load" really means activate, since the plugin was already actually loaded to get its info. So in fact load and unload only mean activate and deactivate.

elextr avatar Feb 21 '15 10:02 elextr

I think doing something like reload()/imp.reload() isn't going to work, but I'd be happy to be proven wrong :)

codebrainz avatar Feb 21 '15 23:02 codebrainz

Well, imp.load_source() sort of sounds like it will reload the module if its run again.

You can't actually unload the module because then it won't appear in the plugin manager because its info isn't available. And how do you unload a module anyway? Is it safe to just delete the global module object? So as @codebrainz says maybe just reload it and pray?

elextr avatar Feb 22 '15 00:02 elextr

On 15-02-21 04:53 PM, elextr wrote:

And how do you unload a module anyway? Is it safe to just delete the global module object?

Probably, but if it uses any C extensions, I don't think they'll be unloaded or re-initialized next time they're imported. Also they probably won't actually be unloaded/collected until nothing refers to them again, which might not be when the del some_module occurs.

codebrainz avatar Feb 22 '15 05:02 codebrainz

I've added a feature on my fork to add a 'refresh' button to the python plugin manager, it saves the activated plugins, unloads all, re-searches for plugins, then restores the plugins that were loaded.

Works nice as you can keep the python plugin manager open and just hit refresh to reload your python plugin when you're working on it. I'd also recommend running geany from a terminal with -vv to get debug output

ghost avatar Jul 10 '15 09:07 ghost

Will it be possible to do it with keystroke?

frlan avatar Jul 10 '15 09:07 frlan

Oooo I'm not sure, I haven't got that far with my plugin development knowledge yet. Have you worked with keyboard shortcuts in geanypy?

ghost avatar Jul 10 '15 09:07 ghost

At the moment plugins can only set keybindings when they start.

That means that "master" plugins like Geanypy cannot set keybindings for its child Python plugins since it doesn't know them when it starts.

And as the Geanypy plugin manager is itself a plugin therefore I don't think it can have keybindings at the moment.

A new plugin loading method that will support "native" Python plugins is planned to be added during the 1.26 development period, and so the Python plugins will be part of the normal PM I believe.

elextr avatar Jul 10 '15 09:07 elextr

For geanypy I was thinking about a global reload feature; As of the new plugin interface: Yes.

frlan avatar Jul 10 '15 09:07 frlan

@frlan I read:

I've added a feature on my fork to add a 'refresh' button to the python plugin manager, it saves the activated plugins, unloads all, re-searches for plugins, then restores the plugins that were loaded.

to say the "Geanypy" reload is part of the plugin manager plugin, so that is what needs the keybinding, but I may be wrong since the OP hasn't left a link to the code ;-)

elextr avatar Jul 10 '15 09:07 elextr

Yeah the manager is in python but since its part of the C plugin, it shouldn't be too hard to get the signal in C and call a function in the python code. I'll look at it tonight. I'll see if its possible for the python to add a keybinding first as im sure that'd be a useful example for developing plugins.

I've found the bit of code in the codenav plugin that uses a keybinding so that'll help me figure out what I'm looking for.

ghost avatar Jul 10 '15 09:07 ghost

I don't think (IIRC) that the Geany plugin API exports the required functions for adding keybinding actions, even for plugins in C, it only supports adding keybinding actions at plugin startup. This is because the keybinding preference GUI does not allow the number of actions in a section to be changed after creation and so no such API exists.

You could look at changing this, as several other parts of Geany could benefit from "dynamic" actions, eg the build menu. But its not intuitively obvious how to do it without breaking lots of stuff which is why its not been done.

Also plugins should not define actual keys for actions since they can clash with ones a user has defined for Geany actions or ones defined for other plugins. Plugins should only add actions and let the user define the key to use.

elextr avatar Jul 10 '15 09:07 elextr

Yeah, I'm pretty new to the project so thank you for your experience.

I'm wondering could it be done in pygtk like in thsi example: https://developer.gnome.org/pygtk/stable/class-gtkaccellabel.html#id3253816

I'm in work at the minute or I'd give it a go

ghost avatar Jul 10 '15 10:07 ghost

On 10 July 2015 at 20:00, rob [email protected] wrote:

Yeah, I'm pretty new to the project so thank you for your experience.

I'm wondering could it be done in pygtk like in thsi example: https://developer.gnome.org/pygtk/stable/class-gtkaccellabel.html#id3253816

​It will probably work for adding an action, but where would you allow the user to define the keybinding? It won't add the action into the Geany keybinding preferences dialog. Having multiple different places to define keybindings is not a good user interface.​

Also beware that Geany does its own key handling before GTK. It lets keys it doesn't know about go through to Scintilla and GTK, but if it has the key defined it will override your accelerator, like if the user or another plugin defines it.

I'm in work at the minute or I'd give it a go

— Reply to this email directly or view it on GitHub https://github.com/codebrainz/geanypy/issues/19#issuecomment-120331201.

elextr avatar Jul 10 '15 11:07 elextr

I see what you mean, unless the keybindings_set_item http://www.geany.org/manual/reference/keybindings_8h.html#a3b50ee5ee6000d83c8a93d8989daa551 function was available to python it has to be done in C

ghost avatar Jul 10 '15 13:07 ghost

Well a true Python/C hacker might manage it with ctypes ;-P

But the question is where would you get the group pointer, and if you said by running plugin_set_key_group() I'll ask where you get the plugin pointer from?

I think its better to wait for a bit until the new plugin system is added and then help moving Geanypy to work with that.

elextr avatar Jul 11 '15 00:07 elextr

I'll ask where you get the plugin pointer from

You already answered it :)

from ctypes import *
mod = CDLL(handle=None)
geany_plugin_ptr = c_void_p.in_dll(mod, "geany_plugin")

(untested pseudo-code)

codebrainz avatar Jul 11 '15 01:07 codebrainz

Thats the Geanypy pointer not the non-existent pointer for the Python plugin :)

elextr avatar Jul 11 '15 01:07 elextr

I thought that was the one you meant.

codebrainz avatar Jul 11 '15 01:07 codebrainz