OK, try the enclosed edit to your sample. On Windows 7, wxPython 3.0.2.0 msw (classic), Python 2.7, it works now. However, you’ll have to determine if you are satisfied with the way it works: during the user resizing the window, the underlines disappear until the resizing stops, and then they reappear in the correct places. I think it looks reasonably good, for what it’s worth.
The reason why it wasn’t working before when you resized is because when you resize the window gets repainted, but your OnPaint method was not bound to anything at all, so it was never called at any point. In the future, if you would want it to be called, you would bind it to a paint event, like either of:
self.Bind(wx.EVT_PAINT, OnPaint) #binds to the frame
self.m_richText3.Bind(wx.EVT_PAINT, OnPaint) #binds to the richtextctrl
And then it would be called on every need to paint or repaint the bound object. For reasons I discuss below, I decided to just bind the richtext to an idle event, which was then directed to the UnderlineWords() method so the underlining would be done once the user stopped resizing.
I think if you are going to do this in pure Python, you probably have two less than ideal options, and this is one of them. The other might be to prevent updating repainting the window at all until the dragging/resize stops, and then repainting all the words in the new positions and the underlines at that time as well. I tried that briefly but wasn’t able to get it to work yet (that’s why I bound to the idle event instead).
The reason I think these are your main two options is that if you write this to repaint the text (which will flow depending on the size it has to occupy) and the determine the underscores and repaint them *continually* as the user quickly drags the frame size, it is asking too much and it is going to lock up. Obviously, this doesn't happen to the text-flowing-on-resize normally, but I would guess it is because this part is written in C++ and compiled and so is way faster, but introducing your code into this paint step would slow things down too much.
If this is good enough, great. If not, again, asking on the wxWidgets list (http://www.wxwidgets.org/support/mailing-lists/) might get you more insight, such as using Catalin’s suggestion in the thread we posted of wxRichTextCtrl::PaintAboveContent(), but I’m not sure how to do that (so ask them). Or Robin might have a better set of suggestions for this when he next pops in here.
Che
sample_edited.py (4.84 KB)