Option to completly reload a plugin
On developing a plugin it would be quiet useful to complete unload and load a given plugin instead of restarting Geany complete.
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).
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.
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.
I think doing something like reload()/imp.reload() isn't going to work, but I'd be happy to be proven wrong :)
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?
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.
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
Will it be possible to do it with keystroke?
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?
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.
For geanypy I was thinking about a global reload feature; As of the new plugin interface: Yes.
@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 ;-)
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.
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.
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
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.
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
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.
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)
Thats the Geanypy pointer not the non-existent pointer for the Python plugin :)
I thought that was the one you meant.