Reputation: 1
I'm coding some Windows app using wxWidgets library and I've stuck on something interesting:
def HandleDblclick (self, event):
self.ItemActivation (event.GetItem ())
def HandleKeydown (self, event):
keyc = event.GetKeyCode ()
if keyc == 13:
self.ItemActivation (event.GetItem ())
elif keyc == 32:
self.ItemSelection (event.GetItem ())
self.sbar.SetStatusText (str (keyc) + " was pressed.")
def HandleRclick (self, event):
self.ItemSelection (event.GetItem ())
(yes, it's Python). ItemActivation () and ItemSelection () do all the dirty work. But only when I press the mouse button. When I enter a key, I get the following output:
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_controls.py", line 5315, in GetItemPyData
return _controls_.TreeCtrl_GetItemPyData(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "param" failed at ..\..\src\msw\treectrl.cpp(1083) in wxTreeCtrl::SetItemData(): failed to change tree items data
I'm trying to code a TreeCtrl. What's funny, nevertheless the error the tree expands (enter key), but item selsction (space) doesn't work at all.
What's going on and why? I think that wxWidgets try to handle the event twice, once with their default handler and twice with mine. But if I'm correct, how to disable default keyboard event processing for wx.TreeCtrl?
Thanks in advance.
Upvotes: 0
Views: 235
Reputation: 1
That's why the error is interesting. I DO NOT set any data item; I actually try to RECEIVE it. The line that stinks is the first one in both of my dirtywork functions:
ikey = self.GetPyData (item)
I really don't know what's going on and why wxWidgets engine tries to assign some data to item. I asked Uncle Google for this error, but I got no usable info.
Thanks for remark on keyboard handling.
Upvotes: 0
Reputation: 22753
First of all, it's a bad idea to try to handle keyboard in any native control yourself. Just remove your EVT_KEY_DOWN
handler entirely and handle EVT_TREE_ITEM_ACTIVATED
instead. This is guaranteed to work on all platforms, unlike stealing events from the native control which may really want to have it on its own.
Second, the error about SetItemData()
failure doesn't seem to have anything to do with the code you showed because it doesn't call this function at all. So you must not be showing us all of the relevant parts.
Upvotes: 1