SelectAll when focus is obtained due to click

Hi all, I need to select all contents from a TextCtrl when the control gets focus. I catch SET_FOCUS events on the textctrl and call selectAll from CallAfter, as suggested in another thread of this list. But still when the focus is gained by clicking over the control contents (not over the empty section but where there already is text), selection is cleaned up immediately after entering the control. A workaround is calling CallLater with a sensible timeout instead of CallLater but this won’t be bulletproof and produces an anti-esthetic flicker. Is it possible to avoid this automatic text deselection? I’m using libwxgtk-2.8.6. TIA. Regards -Carlos

Carlos Pita wrote:

Hi all, I need to select all contents from a TextCtrl when the control gets focus. I catch SET_FOCUS events on the textctrl and call selectAll from CallAfter, as suggested in another thread of this list. But still when the focus is gained by clicking over the control contents (not over the empty section but where there already is text), selection is cleaned up immediately after entering the control. A workaround is calling CallLater with a sensible timeout instead of CallLater but this won't be bulletproof and produces an anti-esthetic flicker. Is it possible to avoid this automatic text deselection? I'm using libwxgtk-2.8.6. TIA.

It's happening because of the repositioning of the caret at the clicked location, which is essentially the same as setting the selection to (pos, pos). You can try intercepting the mouse-down and mouse-up events and avoiding the default set position that is happening there

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!