wxPython: Keyboard events and TreeCtrl

S

Saketh

Hello, everyone.

I am a writing an application that I want to make a stripped-down
framework of Leo for Cornell note-taking. I have one TreeCtrl, a menu,
and a status bar. There are two classes currently - the Application
class and the Frame class. The Frame class contains all of the event
handling, such as OnAbout and OnExit.

I am trying to add keyboard shortcuts. When someone hits Ctrl-I, I want
a new node to be added at the bottom level - if you've ever used Leo,
you know what I am talking about. Like in Leo, when the new node is
created, I want the title to be highlighted so that you can type in the
title of the node.

For some reason, the way I am doing it is not working. It's probably
because OnKeyDown is not attached to anything, but I am not sure.
Anyway, here is what my OnKeyDown method looks like:

def OnKeyDown(self, e):
key = e.KeyCode()
controlDown = e.ControlDown()
altDown = e.AltDown()
elif (controlDown and key == WXK_I):
# I want the "Node Title" to be editable upon its creation
self.tree.AppendItem(root, 'Node Title')

Am I supposed to connect the method to the Frame somehow? Or does it
automatically get called when the user hits Ctrl-I, regardless of the
fact that no other methods call OnKeyDown?

Thank you for the assistance.
 
J

jean-michel bain-cornu

Am I supposed to connect the method to the Frame somehow? Or does it
automatically get called when the user hits Ctrl-I, regardless of the
fact that no other methods call OnKeyDown?

I think it must be connected to the treectrl.
One line or a combination of :
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
self.Bind(wx.EVT_CHAR, self.OnChar)
That's coming from the demo (process and events->key events).

If it does not work, it'd be helpful if you join your program to a next
post, something that we can test without having to write a demo
specifically.

Regards,
jm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top