CustomTreeCtrl problem

Are you using the latest wxPython? There have been some changes to the
way the editing of labels works. Maybe you could provide a smple.

Yes.
If you check the demo of CustomTreeCtrl in demo.py of wxPython I think
you can understand the following (my problem) in order:

    1- My CustomTreeCtrl doesn't have icons (one difference from the
    demo);

    2- Editing in place allows you to set a label with an empty
    string (as in the demo);

    3- Because I have no icons in my tree, it's almost impossible to
    re-edit an empty label;
    
    4- If the user enters an empty label I show a dialog with a text
    entry so I can set the label with the user provided string. This
    dialog will only get out of the user way if he enters a non-empty
    string. After he enters a valid string I set the label text.This
    way I assure every label has a non-empty string.

    5- The thingy here is that if the user, when editing the label in
    step 2, presses ENTER after leaving the label blank, the node
    label is set blank, even after the user inserted a string in my
    dialog (at step 4). One nuance I noticed is that if the user
    presses the key mouse on the tree, instead of pressing ENTER, my
    dialog correctly sets the label.

I hope this provides you with a more clear example. Thanks for you
quick reply.

···

At Fri, 18 Jan 2008 08:21:26 -0600, Rickey, Kyle W wrote:

-Kyle Rickey

-----Original Message-----
From: Norberto Lopes [mailto:collector@mail.telepac.pt]
Sent: Friday, January 18, 2008 5:47 AM
To: wxpython-users@lists.wxwidgets.org
Subject: [wxPython-users] CustomTreeCtrl problem

I'm using CustomTreeCtrl, catching the following events:
    - EVT_TREE_SEL_CHANGING
    - EVT_TREE_SEL_CHANGED
    - EVT_TREE_BEGIN_DRAG
    - EVT_TREE_END_DRAG
    - EVT_TREE_BEGIN_LABEL_EDIT
    - EVT_TREE_END_LABEL_EDIT.

When I edit an item label in place, I verify if the input is nothing
and if it is nothing, I ask the user for some input. When the user
pressed Enter when editing in place, my change with the new input does
no modification to the label, but when the user instead pressing
Enter, clicks somewhere else, the tree throws an
EVT_TREE_END_LABEL_EDIT and I can change the item label.

Can someone give me some insight on what I'm doing wrong?

Thanks in advance,
       Norberto Lopes

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Hmm, I'm not exactly sure what's happening here. By the time
EVT_TREE_END_LABEL_EDIT is sent, the edit control is already destroyed,
so you can't just call event.Veto() and when EVT_TREE_BEGIN_LABEL_EDIT
is sent, the edit control has not been created yet, so you can't create
a custom binding for it.

It seems to me like you're trying a different approach. After the item
has been renamed, check to see if it was blank and then prompt the user
to fix it. However, if I'm understanding correctly,
EVT_TREE_END_LABEL_EDIT is not sent when you press enter?

Also, if this is the route you use, you would probably need to get the
text of the item when EVT_TREE_BEGIN_LABEL_EDIT is sent, so if the user
does not enter a string, the item will be reset. This seems clunky.

A better way would be to somehow add a validator to the edit control,
but I don't know how we can accomplish that.

-Kyle Rickey

···

-----Original Message-----
From: Norberto Lopes [mailto:collector@mail.telepac.pt]
Sent: Friday, January 18, 2008 11:19 AM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] CustomTreeCtrl problem

At Fri, 18 Jan 2008 11:06:16 -0600, Rickey, Kyle W wrote:

Could you post the code that runs when wx.EVT_TREE_END_LABEL_EDIT is
called? Is this your code that forces the user to input a non-empty
string?
wx.EVT_TREE_END_LABEL_EDIT is called on my system when the user

presses

enter AND when the user clicks on another item. Again, a working

sample

would help a lot. I can't see your code, so I don't know what the
problem is :slight_smile:

I thought that by "sample" you meant an explanation. Sorry about that.
Here goes my code.

    def tree_ctrl_left_end_label_edit(self, event):
        if not event.GetLabel().strip():
           self._tree_end_label_edit(event.GetItem())

    def _tree_end_label_edit(self, item):
            dlg = None
            dlg = wx.TextEntryDialog(None, _(u"Nome da Categoria:"),
_(u"Editar nome da categoria"), '', style=wx.OK|wx.TE_MULTILINE)
            dlg.EnableCloseButton(False)
            if dlg.ShowModal() == wx.ID_OK:
                val = dlg.GetValue().strip()
                if not val:
                    dlg.Destroy()
        # Ensure the user really enters a non-empty string
                    self._tree_end_label_edit(item)
                else:
                    self.tree_ctrl_left.SetItemText(item, val)
                    dlg.Destroy()

-Kyle Rickey

-----Original Message-----
From: Norberto Lopes [mailto:collector@mail.telepac.pt]
Sent: Friday, January 18, 2008 10:27 AM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] CustomTreeCtrl problem

At Fri, 18 Jan 2008 08:21:26 -0600, > Rickey, Kyle W wrote:
>
> Are you using the latest wxPython? There have been some changes to

the

> way the editing of labels works. Maybe you could provide a smple.
>
Yes.
If you check the demo of CustomTreeCtrl in demo.py of wxPython I think
you can understand the following (my problem) in order:

    1- My CustomTreeCtrl doesn't have icons (one difference from the
    demo);

    2- Editing in place allows you to set a label with an empty
    string (as in the demo);

    3- Because I have no icons in my tree, it's almost impossible to
    re-edit an empty label;
    
    4- If the user enters an empty label I show a dialog with a text
    entry so I can set the label with the user provided string. This
    dialog will only get out of the user way if he enters a non-empty
    string. After he enters a valid string I set the label text.This
    way I assure every label has a non-empty string.

    5- The thingy here is that if the user, when editing the label in
    step 2, presses ENTER after leaving the label blank, the node
    label is set blank, even after the user inserted a string in my
    dialog (at step 4). One nuance I noticed is that if the user
    presses the key mouse on the tree, instead of pressing ENTER, my
    dialog correctly sets the label.

I hope this provides you with a more clear example. Thanks for you
quick reply.

> -Kyle Rickey
>
> -----Original Message-----
> From: Norberto Lopes [mailto:collector@mail.telepac.pt]
> Sent: Friday, January 18, 2008 5:47 AM
> To: wxpython-users@lists.wxwidgets.org
> Subject: [wxPython-users] CustomTreeCtrl problem
>
>
> I'm using CustomTreeCtrl, catching the following events:
> - EVT_TREE_SEL_CHANGING
> - EVT_TREE_SEL_CHANGED
> - EVT_TREE_BEGIN_DRAG
> - EVT_TREE_END_DRAG
> - EVT_TREE_BEGIN_LABEL_EDIT
> - EVT_TREE_END_LABEL_EDIT.
>
> When I edit an item label in place, I verify if the input is nothing
> and if it is nothing, I ask the user for some input. When the user
> pressed Enter when editing in place, my change with the new input

does

> no modification to the label, but when the user instead pressing
> Enter, clicks somewhere else, the tree throws an
> EVT_TREE_END_LABEL_EDIT and I can change the item label.
>
>
> Can someone give me some insight on what I'm doing wrong?
>
> Thanks in advance,
> Norberto Lopes
>
>

---------------------------------------------------------------------

> To unsubscribe, e-mail:

wxPython-users-unsubscribe@lists.wxwidgets.org

> For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org
>
>

---------------------------------------------------------------------

> To unsubscribe, e-mail:

wxPython-users-unsubscribe@lists.wxwidgets.org

> For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:

wxPython-users-help@lists.wxwidgets.org

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:

wxPython-users-help@lists.wxwidgets.org

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org