jcmeyer 0 Light Poster

I am creating a validator for the text entered in the items of a tree. I am using the EVT_TREE_BEGIN_LABEL_EDIT and EVT_TREE_END_LABEL_EDIT to accomplish this.

In the scenario that the user enters text that is not allowed, I want a message dialog to pop up to tell them what they did wrong and then I want the label that has been incorrectly named to already be in edit mode after the message dialog goes away.

I can do all this except I run into a problem. After the first time that I enter in text that is not allowed and I click OK on the message dialog and I return to the label that is already in edit mode, the enter and escape keys stop working! I have to click outside the label with the mouse to get the EVT_TREE_END_LABEL_EDIT. What is going on?

Here is some code:

def OnBeginEdit(self, event):
        self.tree=self.parent.FindFocus()
        self.tree.SelectItem(event.GetItem(), select=True)
        self.prevLabel=self.tree.GetItemText(event.GetItem())   

#When the user finishes editing the text of a label
def OnEndEdit(self, event):
       newLabel=event.GetLabel()

       if newLabel==self.prevLabel 
            msg=wx.MessageDialog(self.parent.GetActiveChild(), 'That 
            name is already in use.', 'Error', wx.OK|wx.ICON_ERROR)
            msg.ShowModal()
            msg.Destroy()
            event.Veto()
            #Here is where I am not sure what to do. This will start the 
            #edit after I click OK on the message dialog. However, the 
            #enter and escape keys no longer work
            self.tree.EditLabel(event.GetItem())
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.