Deselecting a selection wxTextCtrl blues

Hi everybody,
I have a wxMiniFrame with a wxTextCtrl in it, when I create the frame I want the text control to display the text without a selection and with the insertion point at the end of the string. But the #!=%6€ thing doesn't want to. Is there anybody out there who can spot what I'm missing?
This works as it should in OSX but in XP ( pro ), all text is selected ( and hightlighted ) when the textcontrol shows.
= ( .

from wxPython.wx import *

class MyMiniFrame(wxMiniFrame):
     def __init__(self, parent, title, text = " ", pos=wxDefaultPosition, size=wxDefaultSize,
                  style=wxDEFAULT_FRAME_STYLE ):
         self.parent = parent
         wxMiniFrame.__init__(self, parent, -1, title, pos, size, style)

         self.textCtrl = wxTextCtrl(self, -1, text , style=wxTE_MULTILINE)
         self.textCtrl.SetInsertionPoint(0)
         #self.textCtrl.SetSelection( self.textCtrl.GetLastPosition() - 1, self.textCtrl.GetLastPosition() )

         sizer_1 = wxBoxSizer(wxVERTICAL)
         sizer_1.Add(self.textCtrl, 1, wxEXPAND, 0)
         self.SetAutoLayout(1)
         self.SetSizer(sizer_1)
         sizer_1.Fit(self)
         sizer_1.SetSizeHints(self)
         self.Layout()

         EVT_CLOSE(self, self.OnCloseWindow)
         EVT_TEXT(self, self.textCtrl.GetId() , self.OnControlEnter )
         EVT_KILL_FOCUS( self, self.test )

     def test( self, event ):
       self.textCtrl.SetFocus()

     def OnControlEnter( self, event ):
       if event.GetString() and event.GetString()[-1] == '\n':
         #self.parent.setPostItText( self.textCtrl.GetValue()[:-1] )
         print self.textCtrl.GetValue()
         self.Destroy()

     def OnCloseWindow(self, event):
       #self.parent.setPostItText( self.textCtrl.GetValue() )
       print self.textCtrl.GetValue()
       self.Destroy()

class MyFrame(wxFrame):
     def __init__(self, *args, **kwds):
         # begin wxGlade: MyFrame.__init__
         kwds["style"] = wxDEFAULT_FRAME_STYLE
         wxFrame.__init__(self, *args, **kwds)

         self.but = wxButton( self, 1003, "pop" )
         EVT_BUTTON( self, self.but.GetId(), self.pop )

     def pop( self, event ):
       win = MyMiniFrame(self,
                         "",
                         "testing",
                         #pos=(250,250), size=(200,200),
                         style=wxDEFAULT_FRAME_STYLE | wxTINY_CAPTION_HORIZ
                         )
       win.SetSize((200, 200))
       win.CenterOnParent(wxBOTH)
       self.otherWin = win
       win.Show(True)

# end of class MyFrame

class MyApp(wxApp):
     def OnInit(self):
         wxInitAllImageHandlers()
         frame_1 = MyFrame(None, -1, "")
         self.SetTopWindow(frame_1)
         frame_1.Show(1)
         return 1

# end of class MyApp

if __name__ == "__main__":
     app = MyApp()
     app.MainLoop()

Here's an idea that I use in general circumstances like that:

  self.textCtrl.SetInsertionPoint(0)
  wx.CallAfter(self.textCtrl.SetInsertionPoint, 0)

So the first call should do the trick, but for platforms that refuse to
cooperate, the CallAfter makes it happen. Although I suppose you really
only need the last call.

Let me know if it works.

···

On Saturday 26 April 2003 12:33 pm, Ronald Jaramillo wrote:

self.textCtrl.SetInsertionPoint(0)

--
Chuck
http://ChuckEsterbrook.com

I try that and I get the following error
  AttributeError: 'module' object has no attribute 'CallAfter' = (

/ronald

···

On Saturday, April 26, 2003, at 09:56 PM, Chuck Esterbrook wrote:

On Saturday 26 April 2003 12:33 pm, Ronald Jaramillo wrote:

self.textCtrl.SetInsertionPoint(0)

Here's an idea that I use in general circumstances like that:

  self.textCtrl.SetInsertionPoint(0)
  wx.CallAfter(self.textCtrl.SetInsertionPoint, 0)

So the first call should do the trick, but for platforms that refuse to
cooperate, the CallAfter makes it happen. Although I suppose you really
only need the last call.

Let me know if it works.

--
Chuck
http://ChuckEsterbrook.com

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

If you haven't made Patrick's wx module switch, try wxCallAfter...

···

--- Ronald Jaramillo <ronald@manoamano.dk> wrote:

I try that and I get the following error
  AttributeError: 'module' object has no attribute 'CallAfter'

=====
Donnal Walter
Arkansas Children's Hospital

Thanks Donnal & Chuck
wxCallAfter did the trick!
cheers
Ronald

···

On Sunday, April 27, 2003, at 12:07 AM, Donnal Walter wrote:

--- Ronald Jaramillo <ronald@manoamano.dk> wrote:

I try that and I get the following error
  AttributeError: 'module' object has no attribute 'CallAfter'

If you haven't made Patrick's wx module switch, try wxCallAfter...

=====
Donnal Walter
Arkansas Children's Hospital

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Ronald Jaramillo wrote:

Hi everybody,
I have a wxMiniFrame with a wxTextCtrl in it, when I create the frame I want the text control to display the text without a selection and with the insertion point at the end of the string. But the #!=%6€ thing doesn't want to. Is there anybody out there who can spot what I'm missing?
This works as it should in OSX but in XP ( pro ), all text is selected ( and hightlighted ) when the textcontrol shows.
= ( .

This is the default on Windows since many apps select the text when you tab into a field. IIRC, it happens after the EVT_SET_FOCUS so the answer is to use wxCallAfter as you've already found out.

···

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

Robin Dunn wrote:

Ronald Jaramillo wrote:

Hi everybody,
I have a wxMiniFrame with a wxTextCtrl in it, when I create the frame I want the text control to display the text without a selection and with the insertion point at the end of the string. But the #!=%6€ thing doesn't want to. Is there anybody out there who can spot what I'm missing?
This works as it should in OSX but in XP ( pro ), all text is selected ( and hightlighted ) when the textcontrol shows.
= ( .

This is the default on Windows since many apps select the text when you tab into a field. IIRC, it happens after the EVT_SET_FOCUS so the answer is to use wxCallAfter as you've already found out.

Or apply submitted patch to sf bugtracker - just (MS) windows handler first generates set focus event and later uses normal windows way where text selection ocurs.
After changing two lines I can run any function over control without wxCallAfter helper - just in OnSetFocus handler.

Grzegorz Makarewicz