[Geany-devel] GeanyPy Keybindings Again

Matthew Brush mbrush at xxxxx
Tue Sep 13 01:42:57 UTC 2011

On 09/12/2011 04:37 PM, Lex Trotman wrote:
> Hi Matthew,
> On 13 September 2011 06:16, Matthew Brush<mbrush at codebrainz.ca>  wrote:
>> Hi,
>> I started working on keybindings again for GeanyPy and I was hoping to get a
>> little advice from the experts.
> Can't provide any of that, but can heckle from the cheap seats :)

Thanks for the info, and same to Colomban.

> Presumably you know how to call back into the interpretor (if not I
> suggest looking at how PyGTK does it) so its just a matter of mapping
> from the key_id to a Python callable, I'd have all keys call one
> Python method that just looks up a callable in a dict by key_id.
> Clearly that means you don't expose the Geany's set key but a new
> Python function that records the key in the dict and calls Geany's set
> key.

Here's what I'm thinking of going with for now:

I think it will be sufficient for now.  What it does is adds a 
`bindings` module in the `geany` package which Python plugins can
use to register keybindings, so in practice it looks like this in the 
plugin's code:

   import geany

   class MyPlugin(geany.Plugin):

     def __init__(self):
       # register keybinding
         'MyPlugin',          # name of the plugin
         'Do stuff',          # name of the binding
         self.on_kb_activate, # callback
         'Some user data')    # user data

     def on_kb_activate(self, keyid, data):
       print 'Got %d: %s' % (keyid, data)

In the preferences dialog, all Python bindings show up under the 
'GeanyPy' keygroup and their labels are formatted with the plugin name 
and the keybinding label (ex. "MyPlugin: Do stuff").

Of course it needs more thought and lots more work, but I guess I will 
have to settle for something like this until we get motivated to mess 
with the plugin code in Geany.

At least it's not nearly as hacky as my previous ideas :)

Matthew Brush

More information about the Devel mailing list