wxWidgets / Phoenix

wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.
http://wxpython.org/
2.29k stars 516 forks source link

wx.TextCtrl's insertionPoint is not honored after freeze/thaw of parent. #1698

Open chriskiehl opened 4 years ago

chriskiehl commented 4 years ago

Operating system: Ubuntu 16.04 wxPython version & source: WxPython 4.0.7 (using the prebuilt wheel provided here) Python version & source: Python 3.5, stock

Description of the problem:

When a parent Freeze/Thaws, wx.TextCtrl's "lose" their insertion point in the UI and snap back to the top of the input. Note that this is only in the actual UI. The internal state of the TextCtrl's InsertionPoint remains the same before/after thawing. Additionally, all that's needed to work around this is to 'jiggle' the component after thawing by setting its InsertionPoint to the same value it already contains.

textctrl.SetInsertionPoint(textctrl.GetInsertionPoint())

Example of the issue:

This'll launch an app, then fill in the text control with enough data to force it to scroll down. Then, shortly after, it'll freeze/thaw the main Window, and the TextCtrl's insertion will snap back to the top of the input.

import wx

class ExampleApplication(wx.Frame):
    def __init__(self, *args, **kwargs):
        super(ExampleApplication, self).__init__(None, *args, **kwargs)
        self.textbox = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE | wx.TE_READONLY)

        wx.CallLater(100, self.stuff)
        wx.CallLater(1000, self.freezeThaw)

    def stuff(self, *args, **kwargs):
        print(args, kwargs)
        for i in range(100):
            self.textbox.AppendText( str(i) + '\n')

    def freezeThaw(self):
        print(self.textbox.GetInsertionPoint())
        self.Freeze()
        self.Thaw()
        # the insertionPoints are the same after thaw
        # but the actual position in the UI has snapped to the top
        print(self.textbox.GetInsertionPoint())

app = wx.App()
frame = ExampleApplication()
frame.Show()
app.MainLoop()

image

RobinD42 commented 4 years ago

I this is likely a wxWidgets issue, or an issue in the native widget that may be able to be worked around in wxWidgets. Please create a ticket for this at https://trac.wxwidgets.org/, if one doesn't already exist, and add a link to the ticket here so we can track it.

bje- commented 4 years ago

@chriskiehl I will open the wxWidgets bug report for you.

bje- commented 4 years ago

Confirmed with a C++ program using wxWidgets.

bje- commented 4 years ago

https://trac.wxwidgets.org/ticket/18808

I think this issue can be closed now. It's not a bug in wxPython.

bje- commented 4 years ago

This is not a high priority bug for wxWidgets as there is a workaround. Is it possible that the workaround could be implemented in wxPython so that it least it works for every wxPython application?

https://trac.wxwidgets.org/ticket/18808#comment:1

RobinD42 commented 4 years ago

Is it possible that the workaround could be implemented in wxPython so that it least it works for every wxPython application?

Probably not. There isn't a clear way to do it that would be transparent, not impose unnecessary overhead, and not have a possibility of causing other problems or side-effects.

bje- commented 4 years ago

OK. We might as well close this issue, then.