StyledTextCtrl - Destroy() makes unrelated TextCtrl carret disappear

Hello,
I’m having a problem with destroying stc.StyledTextCtrl instance. I have a frame with TextCtrl and StyledTextCtrl. If TextCtrl has focus (text is being edited), and StyledTextCtrl instance gets destroyed (as a part of keydown event on TextCtrl, for example), blinking carret inside TextCtrl indicating position in text vanishes, even though focus is still inside TextCtrl and you can continue editing text.

Simplified sample that is attached can provide better demonstration of the problem.

Am I doing something wrong?

Thank you,
Pavel

sctrl_test.py (1.56 KB)

Hi Pavel,

I can’t explain the behaviour, but I can tell you that the same happens with wxPython 2.8.12.1 under Windows. I’ll take a look again later (time permitting). Hopefully a brain greater than mine will be able to explain this to you.

Cheers!!

Dermot.

···

On 3 February 2013 13:05, fhjull00 fhjull00@outlook.com wrote:

Hello,
I’m having a problem with destroying stc.StyledTextCtrl instance. I have a frame with TextCtrl and StyledTextCtrl. If TextCtrl has focus (text is being edited), and StyledTextCtrl instance gets destroyed (as a part of keydown event on TextCtrl, for example), blinking carret inside TextCtrl indicating position in text vanishes, even though focus is still inside TextCtrl and you can continue editing text.

Simplified sample that is attached can provide better demonstration of the problem.

Am I doing something wrong?

Thank you,

Pavel

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

I never see "print "Destroying result panel..", on Win 7 64, Py 2.7, wxPy 2.9.5.0.b20121231 msw (classic)

I see it if I add "style=wx.TE_PROCESS_ENTER" to the textctrl and at that point I can also see your problem of the carret disappearing.

Even moving the destroy to a separate function and using CallAfter to call it didn't help (Destroy in an event can cause issues - there was a thread about this some time ago).

Instead of doing Destroy the problem goes away if you use:
     styledControl.Hide()
     styledControl.Close()

Werner

···

On 03/02/2013 13:05, fhjull00 wrote:

Hello,
I'm having a problem with destroying stc.StyledTextCtrl instance. I have a frame with TextCtrl and StyledTextCtrl. If TextCtrl has focus (text is being edited), and StyledTextCtrl instance gets destroyed (as a part of keydown event on TextCtrl, for example), blinking carret inside TextCtrl indicating position in text vanishes, even though focus is still inside TextCtrl and you can continue editing text.

Simplified sample that is attached can provide better demonstration of the problem.

Am I doing something wrong?

fhjull00 wrote:

Hello,
I'm having a problem with destroying stc.StyledTextCtrl instance. I have
a frame with TextCtrl and StyledTextCtrl. If TextCtrl has focus (text is
being edited), and StyledTextCtrl instance gets destroyed (as a part of
keydown event on TextCtrl, for example), blinking carret inside TextCtrl
indicating position in text vanishes, even though focus is still inside
TextCtrl and you can continue editing text.

Simplified sample that is attached can provide better demonstration of
the problem.

Am I doing something wrong?

Not that I can see, it is probably some weird interaction happing at the native level. Does it make any difference if you put the textctrl on the panel instead of directly on the frame? How about if you have some other widget there and SetFocus to it before the Destroy and then set the focus back to the main textctrl after the Destroy (perhaps with CallAfter or CallLater to delay it a little)?

···

--
Robin Dunn
Software Craftsman

Hi,
thank you for the replies.

…but I can tell you that the same happens with wxPython 2.8.12.1 under Windows. I’ll take a look again later (time permitting).

Thank you for confirmation - if you find the time to take another look, I’d be glad.

I see it if I add “style=wx.TE_PROCESS_ENTER” to the textctrl and at
that point I can also see your problem of the carret disappearing.

You are right, I forgot to set this style - although it worked for me when I tested the script :slight_smile:

Instead of doing Destroy the problem goes away if you use:

 styledControl.Hide()

 styledControl.Close()

This works as a workaround. Although I assume the object is not freed from memory (judging by the fact that it still appears in the inspector), which could be a problem if more objects are created/closed in this way.

Does it make any difference if you put the textctrl on the panel instead of directly on the frame?

This doesn’t seem to make any difference. I discovered this while using SearchCtrl on a Toolbar, the included sample is simplified form of that.

How about if you have some other widget there and SetFocus to it before the Destroy and then set the focus back to the main textctrl after the Destroy (perhaps with CallAfter or CallLater to delay it a little)?

This, however, makes the problem disappear (even without CallAfter or CallLater). Unfortunately, the side effect is that the TextCtrl cannot be reliably typed into anymore (if the event handler would need to react for all keys, not just ENTER), since focus may take a while (although tiny) to return back which makes it miss some keys if typing reasonably fast.

So far the workaround seems to be to Hide/Close the object and collect the list of those objects for destruction once focus is in a safe place (I found that this doesn’t steal carret away from another StyledTextCtrl for example). Of course, I welcome any other ideas.

If it is a bug (and not just me doing something wrong), what would be the best place to submit it? wxWidgets tracker or does it occur only when using wxPython?

Thank you,
Pavel

···