Changing attributes of of a textCtrl

I'm trying to alter set up a text entry with differing
text atrributes. I have the object:

self.keyEntry = wx.TextCtrl(self,-1, "", size=100)

In some cases, I need to set this to a normal text
field, other times it needs to be a password or read
only field. I know that if I add:
style=wx_TEREADONLY or wx_TEPASSWORD and get what I
want. However, I want to pass the function a parm, in
which case when I want regular text, and I don't know
how to say, "style=wx_TEJUSTNORMALTEXT" (so to speak).

I tried to modify the textCtrl after creation, looking
on the page:

http://wxwidgets.org/manuals/2.5.3/wx_wxtextctrl.html#wxtextctrl

I've taken the example from the doc and tried:

self.keyEntry.SetDefaultStyle(wxTextAttr(*wxRED)) and
it doesn't turn the field red and I've tried to place
wxTE_PASSWORD into the parens, but the interpreter
yaks on me and say it's expecting a color.

I've tried SetStyle (0, 100, wxTE_PASSWORD) but I'm
told:

typeError: argument number 4: a 'wxTextAttr *' is
expected, 'int(2048)' is received

Could someone not only enlighten me, but point me to
the documentation so I can understand this better?

I suspect this is an easy one...but not for me so far.

Mike Brown

···

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

mike brown wrote:

I'm trying to alter set up a text entry with differing
text atrributes. I have the object:

self.keyEntry = wx.TextCtrl(self,-1, "", size=100)

In some cases, I need to set this to a normal text
field, other times it needs to be a password or read
only field. I know that if I add: style=wx_TEREADONLY or wx_TEPASSWORD and get what I
want. However, I want to pass the function a parm, in
which case when I want regular text, and I don't know
how to say, "style=wx_TEJUSTNORMALTEXT" (so to speak).

I tried to modify the textCtrl after creation, looking
on the page:

http://wxwidgets.org/manuals/2.5.3/wx_wxtextctrl.html#wxtextctrl

I've taken the example from the doc and tried:

self.keyEntry.SetDefaultStyle(wxTextAttr(*wxRED)) and
it doesn't turn the field red and I've tried to place
wxTE_PASSWORD into the parens, but the interpreter
yaks on me and say it's expecting a color.

I've tried SetStyle (0, 100, wxTE_PASSWORD) but I'm
told:

typeError: argument number 4: a 'wxTextAttr *' is
expected, 'int(2048)' is received

Could someone not only enlighten me, but point me to
the documentation so I can understand this better?

I suspect this is an easy one...but not for me so far.

Mike Brown

   Well' I'm not sure I understood what you need,
   anyway:
   - if you want to change the style of a widget, you
     have to use SetWindowStyle and not SetStyle (but
     it seems not to have immediate effect, at least
     in the cases I tried).
   - if you do not need to have the widget style changed
     dynamically, but you can state it at the moment of
     its creation you can try something like

     def textCtrlCreateFoo (..., myParamStyles):
        tcStyle = 0
        if something(myParamStyles): #I want it readonly
            tcStyle |= wx.TE_READONLY
        if somethingelse(myParamStyles): #I want it password
            tcStyle |= wx.TE_PASSWORD

        myTextCtrl = wx.TextCtrl (parent, id, ..., style=tcStyle)

  Hope it helps, sorry but I'm quite a newbie too

···

--
----
   Massimiliano Sartor
   - Hyperborea s.c. -
   Via Giuntini n. 13
   56023 Navacchio(PI)
   050754246-050754241

   - if you want to change the style of a widget,you
     have to use SetWindowStyle and not SetStyle(but
     it seems not to have immediate effect

I've tried the SetWindowStyle with .Refresh() and
.Update(), but I didn't have any luck with these
either. If anyone else knows how to change it after
the fact, I'd be curious.

     def textCtrlCreateFoo (..., myParamStyles):
        tcStyle = 0
        if something(myParamStyles):
            tcStyle |= wx.TE_READONLY

This works. I wasn't familiar with this particular
approach of "|=" but I didn't realize that setting the
style "= 0" is the same as having
wxTE_JUST-NORMAL-TEXT.

Thanks...

Mike

···

______________________________________________________
Yahoo! for Good
Donate to the Hurricane Katrina relief effort.
http://store.yahoo.com/redcross-donate3/

There are some style settings that need to be set before the object is created; password style and read-only are such styles. From the wxWidgets documentation:

"Please note that some styles cannot be changed after the window creation and that Refresh() might be called after changing the others for the change to take place immediately."

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

···

On Sep 27, 2005, at 12:28 PM, mike brown wrote:

I've tried the SetWindowStyle with .Refresh() and
.Update(), but I didn't have any luck with these
either. If anyone else knows how to change it after
the fact, I'd be curious.