textCrtrl custom renderer

30 views
Skip to first unread message

sebastián lópez

unread,
Oct 26, 2014, 11:55:43 AM10/26/14
to wxpytho...@googlegroups.com
I would like to create a text control that works in this way:

If the text control is empty then the control shows a default text 

In the other hand the control shows the user's input.

But i don't know how to set a custom renderer of a textCtrl

Karsten Hilbert

unread,
Oct 26, 2014, 12:06:39 PM10/26/14
to wxpytho...@googlegroups.com
On Sun, Oct 26, 2014 at 08:55:43AM -0700, sebastián lópez wrote:

> I would like to create a text control that works in this way:
>
> If the text control is empty then the control shows a default text
>
> <https://lh4.googleusercontent.com/-31USoxFcVso/VE0YqlUIQhI/AAAAAAAAA3Y/2eBQ5ORyyEY/s1600/render%2Bempty.png>
> In the other hand the control shows the user's input.
>
> But i don't know how to set a custom renderer of a textCtrl

You want to read up on "wx.EVT_TEXT".

Karsten
--
GPG key ID E4071346 @ eu.pool.sks-keyservers.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

sebastián

unread,
Oct 26, 2014, 12:21:38 PM10/26/14
to wxpytho...@googlegroups.com
if i used SetValue and GetValue methods i'll get the default text, so  i would like to manipulate the renderer


--
You received this message because you are subscribed to a topic in the Google Groups "wxPython-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/9to4Xi4Ld3A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wxpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Atentamente

sebastián
Sebastián López
Ingeniero Químico
cel 317-709-0956

Karsten Hilbert

unread,
Oct 26, 2014, 12:27:30 PM10/26/14
to wxpytho...@googlegroups.com
On Sun, Oct 26, 2014 at 11:21:34AM -0500, sebastián wrote:

> if i used SetValue and GetValue methods i'll get the default text, so i
> would like to manipulate the renderer

Have you read up on wx.EVT_TEXT ?

Karsten
> 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-user...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--

sebastián lópez

unread,
Oct 26, 2014, 7:22:56 PM10/26/14
to wxpytho...@googlegroups.com

Hi

 

I append my approach by using wx.EVT_KEY_DOWN and wx.EVT_KEY_UP  but I also like to know if it’s possible to change the text color in the control to being sometimes black color and sometimes grey color.

 

 

defaultTxtTest.py

Yoriz

unread,
Oct 26, 2014, 7:31:10 PM10/26/14
to wxpytho...@googlegroups.com

You could use a wx.SearchCtrl with the SearchButton, CancelButton ect set to not be shown and use the method SetDescriptiveText for setting your default text.

The search control is a wx.TextCtrl with added functionality.

 
 

Nathan McCorkle

unread,
Oct 26, 2014, 9:00:12 PM10/26/14
to wxpytho...@googlegroups.com
I would use EVT_SET_FOCUS and EVT_KILL_FOCUS.

By default on startup you'd set the color style of the TextCtrl to light-grey and set ChangeValue to the default text. Then in the EVT_SET_FOCUS handler, if the default text is shown ChangeValue('') and set the text style to the normal black color. In the EVT_KILL_FOCUS handler, if the GetValue() is '' (blank), set the light-grey text style and ChangeValue(defaultText).

Tim Roberts

unread,
Oct 27, 2014, 1:46:38 PM10/27/14
to wxpytho...@googlegroups.com
Nathan McCorkle wrote:
I would use EVT_SET_FOCUS and EVT_KILL_FOCUS.

By default on startup you'd set the color style of the TextCtrl to light-grey and set ChangeValue to the default text. Then in the EVT_SET_FOCUS handler, if the default text is shown ChangeValue('') and set the text style to the normal black color. In the EVT_KILL_FOCUS handler, if the GetValue() is '' (blank), set the light-grey text style and ChangeValue(defaultText).

I don't think that's the right model.  He's looking for the same functionality as the "placeholder" attribute in a modern HTML <input> tag.  ANY time the box goes empty, it displays the placeholder property in a grayed color.  As soon as one character is entered, the placeholder goes away and it displays the entered text in black.

I think you have to use key up and key down.  Either that, or subclass the edit control and draw the placeholder during the paint event.
-- 
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.
Reply all
Reply to author
Forward
0 new messages