wxPython: Keyboard events and TreeCtrl

Saketh saketh.bhamidipati at gmail.com
Sun Jun 11 15:46:57 EDT 2006


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.




More information about the Python-list mailing list