By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,402 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,402 IT Pros & Developers. It's quick & easy.

wxPython: Keyboard events and TreeCtrl

P: n/a
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.

Jun 11 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
> 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
Jun 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.