SetInsertionPoint()

314 views
Skip to first unread message

Keith Bolton

unread,
Sep 30, 2004, 6:33:01 PM9/30/04
to wxPytho...@lists.wxwidgets.org
My question is due to a problem I'm facing when Setting the Value within
a text ctrl.
On Focus of the ctrl, the value is set to the current time.
The cursor moves to the end of the text value.
I tried to Set the insertion point back at the beginning of the text,
but I cannot.

So I thought what if I could call the KeyEvent WXK.HOME after the text
value is set. In effect putting the cursor back to the beginning of the
text field.

My main question is how to create this KeyEvent programmatically?

Or maybe someone has another suggestion for how to go about this.

Thank you very much all,

Keith Bolton
BPC

Franz Steinhäusler

unread,
Oct 1, 2004, 7:47:02 AM10/1/04
to wxpytho...@lists.wxwindows.org
On Thu, 30 Sep 2004 15:33:01 -0700, "Keith Bolton"
<Keith....@batescapital.com> wrote:

> I tried to Set the insertion point back at the beginning of the text,
>but I cannot.

Do you mean, nothing happens?

Maybe you could try: SetSelection (0,0)


--
Franz Steinhäusler

DrPython (Project Developer)
http://drpython.sourceforge.net/
http://sourceforge.net/projects/drpython/


Keith Bolton

unread,
Oct 1, 2004, 1:04:58 PM10/1/04
to wxPytho...@lists.wxwidgets.org
Thank you for the suggestion franz, however, I can't get it to work.

Here's my code snippet:

def onFocusCurrentTime(self, event):
#When this field gets focus...

if self.buttondef == 0:
#If some condition is set, calculate the
current time.

self.endtime.SetValue(wx.DateTime_Now().Format("%H:%M"))
#Sets the value of field to current time(SetValue by default puts the
cursor at the end).

self.endtime.SetInsertionPoint(-1)
#I want the cursor to be at the
beginning of the text. This part doesn't work.

elif self.buttondef <> 0:
#If the other condition, don't do anything.

event.Skip()


Thanks,

Keith


>>> franz.ste...@gmx.at 10/01/04 04:47:02 AM >>>


--
Franz Steinhäusler


---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-user...@lists.wxwidgets.org

For additional commands, e-mail:
wxPython-...@lists.wxwidgets.org


Jean-Michel Fauth

unread,
Oct 1, 2004, 3:47:32 PM10/1/04
to wxPytho...@lists.wxwindows.org
It seems it is an endless story... I think, there is a wiki page about this.

class MyPanel(wx.Panel):

def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize)

self.txt1 = wx.TextCtrl(self, wx.NewId(), 'aa bb cc', (20, 20), (500, 20))
self.txt1.SetValue('999')

wx.CallAfter(self.JobCallAfter) <<<<<<<<<<<<<<<<<<<<

def JobCallAfter(self):
#~ self.txt1.SetLabel('aaa bbb')
#~ self.txt1.SetInsertionPointEnd()
self.txt1.SetInsertionPoint(0)
#~ self.txt1.SetSelection(0, 3)

Jean-Michel Fauth, Switzerland

Robin Dunn

unread,
Oct 5, 2004, 7:15:43 PM10/5/04
to wxPytho...@lists.wxwidgets.org
Keith Bolton wrote:
> My question is due to a problem I'm facing when Setting the Value within
> a text ctrl.
> On Focus of the ctrl, the value is set to the current time.
> The cursor moves to the end of the text value.
> I tried to Set the insertion point back at the beginning of the text,
> but I cannot.
>
> So I thought what if I could call the KeyEvent WXK.HOME after the text
> value is set. In effect putting the cursor back to the beginning of the
> text field.
>
> My main question is how to create this KeyEvent programmatically?

You can't, not in a way that the native control will get the event anyway.


>
> Or maybe someone has another suggestion for how to go about this.

Do this:

wx.CallAfter(textctrl.SetInsertionPoint, 0)

And in the next EVT_IDLE the SetInsertionPoint will be called with a
parameter of zero.


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


Reply all
Reply to author
Forward
0 new messages