Possible to prevent focus on a wx.TextCtrl?

I'm trying to use a wx.TextCtrl the way a wx.StaticText would normally
be used, meaning read only, and non selectable. In other words, if the
user clicks on the control, no cursor should appear.

Currently I'm using the wx.TE_READONLY style, which prevents the user
from selecting the text, but if they click on the text their cursor
appears inside the text.

Is it possible prevent this behavior?

Here's how I'm constructing it currently:

wx.TextCtrl(self, -1, "testing", size = (150, 17), style=wx.TE_RICH2

wx.NO_BORDER | wx.TE_CENTRE | wx.TE_READONLY)

If you're using Windows, you can see the behavior by trying the
program I'm working on:

http://gizmoware.net/triggerfinger

Click on one of the captions under one of the buttons.

As I understand it, TE_READONLY just makes the text control read-only,
which means the user can still select the text so that they can copy
and paste it. They just can't edit the text in the control.

There are two ways to prevent the user from getting a cursor in there
(I think):

1) Bind the control to the EVT_SET_FOCUS and cancel it
2) Disable the widget (probably the best solution)

···

On Mar 25, 7:14 am, wrybread <wrybr...@gmail.com> wrote:

I'm trying to use a wx.TextCtrl the way a wx.StaticText would normally
be used, meaning read only, and non selectable. In other words, if the
user clicks on the control, no cursor should appear.

Currently I'm using the wx.TE_READONLY style, which prevents the user
from selecting the text, but if they click on the text their cursor
appears inside the text.

Is it possible prevent this behavior?

Here's how I'm constructing it currently:

wx.TextCtrl(self, -1, "testing", size = (150, 17), style=wx.TE_RICH2
> wx.NO_BORDER | wx.TE_CENTRE | wx.TE_READONLY)

If you're using Windows, you can see the behavior by trying the
program I'm working on:

Trigger Finger Jukebox Thingamajiggy

Click on one of the captions under one of the buttons.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

As I understand it, TE_READONLY just makes the text control read-only,
which means the user can still select the text so that they can copy
and paste it. They just can't edit the text in the control.

There are two ways to prevent the user from getting a cursor in there
(I think):

1) Bind the control to the EVT_SET_FOCUS and cancel it

Focus events are not veto-able, but what you can do is call Navigate so the focus will be moved to the next widget in the tab-order, or explicitly call SetFocus on some other widget if you want it to go to some specific place.

2) Disable the widget (probably the best solution)

Yes, but that changes the appearance of the widget, which may not be desired.

···

On 3/25/10 7:22 AM, Mike Driscoll wrote:

--
Robin Dunn
Software Craftsman

> As I understand it, TE_READONLY just makes the text control read-only,
> which means the user can still select the text so that they can copy
> and paste it. They just can't edit the text in the control.

> There are two ways to prevent the user from getting a cursor in there
> (I think):

> 1) Bind the control to the EVT_SET_FOCUS and cancel it

Focus events are not veto-able, but what you can do is call Navigate so
the focus will be moved to the next widget in the tab-order, or
explicitly call SetFocus on some other widget if you want it to go to
some specific place.

I didn't know that...oops! I meant basically the same thing though
(i.e. SetFocus on a different widget)

> 2) Disable the widget (probably the best solution)

Yes, but that changes the appearance of the widget, which may not be
desired.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

Yeah, but I couldn't think of a different way other than Disabling the
widget or just using a StaticText.

···

On Mar 25, 4:46 pm, Robin Dunn <ro...@alldunn.com> wrote:

On 3/25/10 7:22 AM, Mike Driscoll wrote:

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Hi all,

···

2010/3/26 Mike Driscoll kyosohma@gmail.com

On Mar 25, 4:46 pm, Robin Dunn ro...@alldunn.com wrote:

On 3/25/10 7:22 AM, Mike Driscoll wrote:

As I understand it, TE_READONLY just makes the text control read-only,

which means the user can still select the text so that they can copy

and paste it. They just can’t edit the text in the control.

There are two ways to prevent the user from getting a cursor in there

(I think):

  1. Bind the control to the EVT_SET_FOCUS and cancel it

Focus events are not veto-able, but what you can do is call Navigate so

the focus will be moved to the next widget in the tab-order, or

explicitly call SetFocus on some other widget if you want it to go to

some specific place.

I didn’t know that…oops! I meant basically the same thing though

(i.e. SetFocus on a different widget)

  1. Disable the widget (probably the best solution)

Yes, but that changes the appearance of the widget, which may not be

desired.

Robin Dunn

Software Craftsmanhttp://wxPython.org

Yeah, but I couldn’t think of a different way other than Disabling the

widget or just using a StaticText.


Mike Driscoll

Blog: http://blog.pythonlibrary.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

To unsubscribe from this group, send email to wxpython-users+unsubscribegooglegroups.com or reply to this email with the words “REMOVE ME” as the subject.

I would also like to have textctrl without focus, and then I thought of using StaticText but I wish he had defined edges.

What to do?


Fabio Spadaro
www.fabiospadaro.com

You can make the TextCtrl read-only...

···

On Dec 22, 3:21 am, Fabio Spadaro <fabiolinos...@gmail.com> wrote:

Hi all,

2010/3/26 Mike Driscoll <kyoso...@gmail.com>

> On Mar 25, 4:46 pm, Robin Dunn <ro...@alldunn.com> wrote:
> > On 3/25/10 7:22 AM, Mike Driscoll wrote:

> > > As I understand it, TE_READONLY just makes the text control read-only,
> > > which means the user can still select the text so that they can copy
> > > and paste it. They just can't edit the text in the control.

> > > There are two ways to prevent the user from getting a cursor in there
> > > (I think):

> > > 1) Bind the control to the EVT_SET_FOCUS and cancel it

> > Focus events are not veto-able, but what you can do is call Navigate so
> > the focus will be moved to the next widget in the tab-order, or
> > explicitly call SetFocus on some other widget if you want it to go to
> > some specific place.

> I didn't know that...oops! I meant basically the same thing though
> (i.e. SetFocus on a different widget)

> > > 2) Disable the widget (probably the best solution)

> > Yes, but that changes the appearance of the widget, which may not be
> > desired.

> > --
> > Robin Dunn
> > Software Craftsmanhttp://wxPython.org

> Yeah, but I couldn't think of a different way other than Disabling the
> widget or just using a StaticText.

> -------------------
> Mike Driscoll

> Blog: http://blog.pythonlibrary.org

I would also like to have textctrl without focus, and then I thought of
using StaticText but I wish he had defined edges.
What to do?

--
Fabio Spadaro

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org