On Wed, Jul 27, 2011 at 12:45 PM, Fernando Girotto
<[email protected]> wrote:

> Is it possible to overwrite a shortcut?

The short answer is, "yes, it's possible to do anything with Python and Leo".

The next question is, "how hard is it to do?"

Another question is, "in what context do you want the shortcut to be
defined?" Let us ignore this other question for the moment.

Here is the documentation for the relevant dictionaries in leoKeys.py:

QQQQQ
k.bindingsDict:
    Keys are shortcuts; values are *lists* of g.bunch(func,name,warningGiven)

k.masterBindingsDict:
    Keys are scope names: 'all','text',etc. or mode names.
    Values are dicts:  keys are strokes, values are
g.Bunch(commandName,func,pane,stroke)

k.masterGuiBindingsDict:
    Keys are strokes; value is a list of widgets for which stroke is bound.
QQQQQ

Depending on your purpose,  you may want to clear the proper entries
in all these dicts.

Putting this together, we get the following script:

ZZZZZ
delete = False
key = 'Insert'
key2 = '<Insert>'
k = c.k

# Keys are shortcuts; values are *lists* of g.bunch(func,name,warningGiven)
d = k.bindingsDict
if key in d:
    print('** k.bindingsDict',key,d.get(key))
    if delete:
        del d[key]

# Keys are scope names: 'all','text',etc. or mode names.
# Values are dicts:  keys are strokes, values are
g.Bunch(commandName,func,pane,stroke)
d = k.masterBindingsDict
for scope in list(d.keys()):
    d2 = d.get(scope)
    if d2:
        b = d2.get(key)
        if b:
            print('** k.masterBindingsDict: scope',scope,b)
            if delete: del d2 [key]

# Keys are strokes; value is a list of widgets for which stroke is bound.
d = k.masterGuiBindingsDict
if key2 in d:
    print('** k.masterGuiBindingsDict',key,d.get(key2))
    if delete:
        del d[key2]
ZZZZZ

Running this script yields the following output:

OOOOO
** k.bindingsDict Insert [Bunch...
_hash: myleosettings.leo
commandName: insert-node
func: <bound method Commands.insertHeadline of Commander 47880240:
'C:\\Users\\edreamleo\\ekr.leo'>
pane: all
]
** k.masterBindingsDict: scope all Bunch...
commandName: insert-node
func: <bound method Commands.insertHeadline of Commander 47880240:
'C:\\Users\\edreamleo\\ekr.leo'>
pane: all
stroke: Insert

** k.masterGuiBindingsDict Insert [<leoQLineEditWidget: widget:
<PyQt4.QtGui.QLineEdit object at 0x03F79858>, leoQTextEd
itWidget: 66041872, <leo.plugins.qtGui.leoQtTree object at 0x03EFB470>]
)))))
OOOOO

Setting 'delete' to True in the script does indeed kill the binding.
Note that in this example the "Insert" key gets sent to Qt, so the
Insert kill still works, but the principle still holds.

One could imagine a "convenience" method (somewhere) that does this,
but it doesn't exist yet.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en.

Reply via email to