javanewbie
javanewbie

Reputation: 301

WxPython - 1st Event Handler to activate/wait for 2nd Event Handler to be activated

When I click on a row in my Wx.ListCtrl, I want nothing to happen until I press DELETE. Problem is, I don't know how to make an Event handler activate another.

This is my code so far:

self.list.Bind(wx.EVT_LIST_ITEM_SELECTED, ...)
self.list.Bind(wx.EVT_KEY_DOWN, self.onSelect)

def onSelect(self, event):
    keycode = event.GetKeyCode()

    if keycode == wx.WXK_DELETE:
        print "You pressed delete."

    event.Skip()

I want to somehow make the first event handler activate/wait for the 2nd event handler to become true (someone presses delete). Then the function runs and prints "You pressed delete."

If this isn't possible, any other ideas as to how I can do this?

Upvotes: 0

Views: 64

Answers (1)

Yoriz
Yoriz

Reputation: 3625

When the list item selected event triggers, get the event handler for that to set a variable can_delete to True or False if no item is selected. In the key event handler, when delete is pressed also check that can_delete is true.

Or

when delete is pressed, check if the list control has focus and an item is selected.

Upvotes: 1

Related Questions