wx.TextCtrl - initial text value is only partially visible

Hello,

I am using two wx.TextCtrl’s and I set a long text as the initial value of both controls with the SetValue method. The text from the first control is only partially visible (shifted to the left side), in the second control, the full text is visible. The first control has the focus and the text is selected. Here is my code:

···

import wx

long_text = “Hello 0123456789012345678901234567890123456789”

class TestFrame(wx.Frame):

def __init__(self): 

    wx.Frame.__init__(self, None, -1, "Test") 

    panel = wx.Panel(self, -1) 

    sizer = wx.BoxSizer(wx.VERTICAL) 

    panel.SetSizer(sizer) 

    

    input0 = wx.TextCtrl(panel, -1) 

    sizer.Add(input0, 0, wx.EXPAND) 

    input0.SetValue(long_text)

    input1 = wx.TextCtrl(panel, -1) 

    sizer.Add(input1, 0, wx.EXPAND) 

    input1.SetValue(long_text)

app = wx.PySimpleApp()

TestFrame().Show()

app.MainLoop()


How can I enforce that the full text of the first control is visible ?

Versions:

wx 2.8.12.1

python 2.7.3

windows vista

Erwin

Yeah, this is a quirk of the textctrl on windows that happens because by default the whole content is selected and that leaves the caret at the end, and it scrolls a bit to make sure the caret is visible. The workaround is easy, just add something like this:

     wx.CallAfter(theTextCtrl.SetInsertionPoint, 0)

···

On 11/4/12 3:44 AM, ErwinP wrote:

Hello,

I am using two wx.TextCtrl's and I set a long text as the initial value
of both controls with the SetValue method. The text from the first
control is only partially visible (shifted to the left side), in the
second control, the full text is visible. The first control has the
focus and the text is selected. Here is my code:

How can I enforce that the full text of the first control is visible ?

--
Robin Dunn
Software Craftsman

Thanks for your answer. Unfortunately SetInsertion removes the selection. I use the following workaround which does what I want:

    input0.SetValue(long_text)

    def quirk_workaround(inp):

        selection = inp.GetSelection()

        inp.SetInsertionPoint(inp.GetInsertionPoint())

        inp.SetSelection(*selection) 

    wx.CallAfter(lambda: quirk_workaround(input0))

Erwin

···

Am Montag, 5. November 2012 21:58:43 UTC+1 schrieb Robin Dunn:

The workaround is easy, just add something like this:

 wx.CallAfter(theTextCtrl.SetInsertionPoint, 0)