draw dashed line under specific words in wxrichtextctrl?

I don’t want use Underline feature in Richtextctrl for some reasons. I’m trying to draw a dashed line under specific words when the user checked the “checkbox1”. I have a problem in x,y coordinates and I don’t know how to get these coordinates correctly.

Here is the code:

could anyone please tell me how I can convert the text caret position to pixel that would help me to get the coordinates correctly.

···

On Friday, December 4, 2015 at 4:34:26 PM UTC-5, a.m.n....@gmail.com wrote:

I don’t want use Underline feature in Richtextctrl for some reasons. I’m trying to draw a dashed line under specific words when the user checked the “checkbox1”. I have a problem in x,y coordinates and I don’t know how to get these coordinates correctly.

Here is the code:

could anyone please tell me how I can convert the text caret position to
pixel that would help me to get the coordinates correctly.

Unfortunately, it seems there is no good solution for this already out
there (that is, it is not currently possible). See this thread on the
wxWidgets list from earlier in 2015:

https://groups.google.com/forum/#!msg/wx-users/Hdko3XdUBXw/5_AdvgStCQAJ

Maybe you could experiment with a hack of your own in which you figure out
a way to do this. So, as a start, PositionToXY() will return the column and
line number. As I understand this, if you are always going to do one column
text, then the column information will be always the same, but the line
number is helpful to get the vertical position on the screen: maybe you can
use the current font size as a way to get the y screen position for the
bottom of the word. Something like:

   y_screen_position = line_number * font_size * some_scaling_factor

Now you need to get the x component. Here you might be able to get the
number of characters in that line up to the word you want to get the start
of x, and then the number of characters in the word itself would give you
the end of x. Again, something like:

   x_screen_position_start = num_of_characters_to_word * font_size *
some_other_scaling_factor

   word_length = num_of_characters_in_word * font_size *
some_other_scaling_factor

   x_screen_position_end = x_screen_position_start + word_length

I have not tested any of this and have no idea if this would really work.
It seems like it should, but it also really seems to me that there is so
reason why this is too simplistic and is missing out on something critical.
The good news is you can test it out and see if it is viable in a fairly
short amount of time, I'd think.

C

···

On Sun, Dec 6, 2015 at 11:07 AM, <a.m.n.alsubhi@gmail.com> wrote:

On Friday, December 4, 2015 at 4:34:26 PM UTC-5, a.m.n....@gmail.com > wrote:

I don't want use Underline feature in Richtextctrl for some reasons. I'm
trying to draw a dashed line under specific words when the user checked the
"checkbox1". I have a problem in x,y coordinates and I don't know how to
get these coordinates correctly.

<https://lh3.googleusercontent.com/-uome5QJQ5js/VmIFKHHjfXI/AAAAAAAAAAM/BCoydHW3cA4/s1600/dashedline.png&gt;

Here is the code:

<https://lh3.googleusercontent.com/-MkzVXIaepHs/VmIGXg5xfDI/AAAAAAAAAAU/ESpA-Tj_4Xc/s1600/code.jpg&gt;

--

You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

There is also this, maybe you can make use of?:

 [wxTextCtrlHitTestResult](http://docs.wxwidgets.org/trunk/textctrl_8h.html#a0ca70276b66011b1ca0a120b8c20fd16)

Finds the character at the given position in pixels.

pt is in device coords (not adjusted for the client area origin nor for scrolling).

···

On Sun, Dec 6, 2015 at 12:22 PM, C M cmpython@gmail.com wrote:

On Sun, Dec 6, 2015 at 11:07 AM, a.m.n.alsubhi@gmail.com wrote:

could anyone please tell me how I can convert the text caret position to pixel that would help me to get the coordinates correctly.

Unfortunately, it seems there is no good solution for this already out there (that is, it is not currently possible). See this thread on the wxWidgets list from earlier in 2015:

https://groups.google.com/forum/#!msg/wx-users/Hdko3XdUBXw/5_AdvgStCQAJ

Maybe you could experiment with a hack of your own in which you figure out a way to do this. So, as a start, PositionToXY() will return the column and line number. As I understand this, if you are always going to do one column text, then the column information will be always the same, but the line number is helpful to get the vertical position on the screen: maybe you can use the current font size as a way to get the y screen position for the bottom of the word. Something like:

y_screen_position = line_number * font_size * some_scaling_factor

Now you need to get the x component. Here you might be able to get the number of characters in that line up to the word you want to get the start of x, and then the number of characters in the word itself would give you the end of x. Again, something like:

x_screen_position_start = num_of_characters_to_word * font_size * some_other_scaling_factor

word_length = num_of_characters_in_word * font_size * some_other_scaling_factor

x_screen_position_end = x_screen_position_start + word_length

I have not tested any of this and have no idea if this would really work. It seems like it should, but it also really seems to me that there is so reason why this is too simplistic and is missing out on something critical. The good news is you can test it out and see if it is viable in a fairly short amount of time, I’d think.

C

On Friday, December 4, 2015 at 4:34:26 PM UTC-5, a.m.n....@gmail.com wrote:

I don’t want use Underline feature in Richtextctrl for some reasons. I’m trying to draw a dashed line under specific words when the user checked the “checkbox1”. I have a problem in x,y coordinates and I don’t know how to get these coordinates correctly.

Here is the code:

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Thanks guys. I figured out how to do it. I just store the start and end position for each word using this code:
pos1=self.m_richText.GetCaret().GetPosition()

Now the problem is when I re-size the window all lines disappeared. If you have any idea about how to redraw the lines when the window resized, it would be helpful.

···

On Friday, December 4, 2015 at 4:34:26 PM UTC-5, a.m.n....@gmail.com wrote:

I don’t want use Underline feature in Richtextctrl for some reasons. I’m trying to draw a dashed line under specific words when the user checked the “checkbox1”. I have a problem in x,y coordinates and I don’t know how to get these coordinates correctly.

Here is the code:

I found this function PositionToCoords(self,pos) to convert given text position to client coordinates in pixels. the problem with this function is returning -1 always. am I use it wrong? This function seems helpful to get the position of the text on the screen in order to draw dashed underline.

···

On Friday, December 4, 2015 at 4:34:26 PM UTC-5, a.m.n....@gmail.com wrote:

I don’t want use Underline feature in Richtextctrl for some reasons. I’m trying to draw a dashed line under specific words when the user checked the “checkbox1”. I have a problem in x,y coordinates and I don’t know how to get these coordinates correctly.

Here is the code:

I don't know. How can I know that without seeing your code? :smiley:

The docs say this: "On success returns a * Point*
<http://wxpython.org/Phoenix/docs/html/Point.html#point&gt; which contains
client coordinates for the given position in pixels, otherwise returns
DefaultPosition ."

Looks like you are not having "success". I am unclear as to what it means,
in this case, to succeed or fail.

Please post a small "runnable" sample (
MakingSampleApps - wxPyWiki) of your code.

C

···

On Wed, Dec 16, 2015 at 4:59 PM, <a.m.n.alsubhi@gmail.com> wrote:

I found this function PositionToCoords(*self*,*pos*) to convert given
text position to client coordinates in pixels. the problem with this
function is returning -1 always. am I use it wrong?

I tried to draw the dashed underline using wx.dc but the result is not satisfying. I have been searching for three weeks, and I couldn’t find any useful information maybe because the wxwidgets framework is written in C++. I found a similar question on the wx-users mailing list:
https://groups.google.com/d/msg/wx-user … AdvgStCQAJ
one of the suggested solution is using richtextrenderer . I searched about how to write a custom richtextrenderer in wxpython and i couldn’t find any. please any help would be appreciated.

···

On Wednesday, December 16, 2015 at 6:53:40 PM UTC-5, Che M wrote:

On Wed, Dec 16, 2015 at 4:59 PM, a.m.n....@gmail.com wrote:

I found this function PositionToCoords(self,pos) to convert given text position to client coordinates in pixels. the problem with this function is returning -1 always. am I use it wrong?

I don’t know. How can I know that without seeing your code? :smiley:

The docs say this: “On success returns a Point which contains client coordinates for the given position in pixels, otherwise returns DefaultPosition .”

Looks like you are not having “success”. I am unclear as to what it means, in this case, to succeed or fail.

Please post a small “runnable” sample (http://wiki.wxpython.org/MakingSampleApps) of your code.

C

I tried to draw the dashed underline using wx.dc but the result is not
satisfying. I have been searching for three weeks, and I couldn't find any
useful information maybe because the wxwidgets framework is written in C++.
I found a similar question on the wx-users mailing list:
https://groups.google.com/d/msg/wx-user ... AdvgStCQAJ
<https://groups.google.com/d/msg/wx-users/Hdko3XdUBXw/5_AdvgStCQAJ&gt;

Yes, that's the same message I found and mentioned to you a couple of weeks
ago.

one of the suggested solution is using richtextrenderer . I searched about
how to write a custom richtextrenderer in wxpython and i couldn't find any.
please any help would be appreciated.

That's the wxWidgets (written in C++) list people discussing it. You might
want to ask on that list directly. One of them mentions overriding
wxRichTextCtrl.PaintAboveContent(), but I have no idea if that is even
possible in wxPython (http://www.wiki.wxpython.org/OverridingMethods) at
this point, nor how you would do it.

As I originally wrote, I don't think there is any easy way to do what you
want to do without writing some new feature yourself. What is unsatisfying
about the result you already have?

···

On Thu, Dec 17, 2015 at 7:53 PM, <a.m.n.alsubhi@gmail.com> wrote:

My application doesn’t allow the user to enter any text. It just read docx files and display it in richtextbox. I store the text position index for a list of words that I want to highlight by underlining. When the user check the first checkbox , the application draws underlines perfectly, but when the window is resized all lines are erased to solve this problem I tryed to bind the rich textbox with paint event to redraw the lines. As a result I got flicker underlines while the user customizes the window size and when the resized is stop the underlines are erased.
this is checkbox:

if self.m_checkBox1.GetValue():

w, h = self.m_richText3.GetTextExtent(‘ridiculous’)

r11=self.m_richText3.SetInsertionPoint(dic1[‘ridiculous’][0]+1)

p=self.m_richText3.GetCaret().GetPosition()

x1=p[0]

x2=x1+w

y=p[1]+h

dc1.SetPen(wx.Pen(wx.BLUE,1, wx.DOT))

dc1.DrawLine(x1,y,x2,y)

self.m_richText3.Bind( wx.EVT_PAINT, self.OnPaint)

Here is the repaint event:

def OnPaint(self,event):

#print “re paint”

dc1 = wx.ClientDC(self.m_richText3)

w, h = self.m_richText3.GetTextExtent(‘ridiculous’)

self.m_richText3.SetInsertionPoint(dic1[‘ridiculous’][0]+1)

p=self.m_richText3.GetCaret().GetPosition()

print “convert”,p

x1=p[0]

x2=x1+w

y=p[1]+h

print x1,x2

dc1.SetPen(wx.Pen(wx.BLUE,1, wx.DOT))

dc1.DrawLine(x1,y,x2,y)

···

On Friday, December 4, 2015 at 4:34:26 PM UTC-5, a.m.n....@gmail.com wrote:

I don’t want use Underline feature in Richtextctrl for some reasons. I’m trying to draw a dashed line under specific words when the user checked the “checkbox1”. I have a problem in x,y coordinates and I don’t know how to get these coordinates correctly.

Here is the code:

Well, that's a good start. At least it is underlining the right words to
begin with.

In terms of the flickering/disappearing, what happens if you change from a
ClientDC to a wx.BufferedPaintDC ?

If that doesn't help, could you please post a small runnable sample app (
MakingSampleApps - wxPyWiki) and I will play with it and see
if I can get it to work?

C

···

On Fri, Dec 18, 2015 at 10:26 AM, <a.m.n.alsubhi@gmail.com> wrote:

My application doesn't allow the user to enter any text. It just read docx
files and display it in richtextbox. I store the text position index for a
list of words that I want to highlight by underlining. When the user check
the first checkbox , the application draws underlines perfectly, but when
the window is resized all lines are erased to solve this problem I tryed to
bind the rich textbox with paint event to redraw the lines. As a result I
got flicker underlines while the user customizes the window size and when
the resized is stop the underlines are erased.
this is checkbox:

if self.m_checkBox1.GetValue():

                        w, h = self.m_richText3.GetTextExtent('ridiculous')

r11=self.m_richText3.SetInsertionPoint(dic1['ridiculous'][0]+1)
                        p=self.m_richText3.GetCaret().GetPosition()
                        x1=p[0]
                        x2=x1+w
                        y=p[1]+h
                        dc1.SetPen(wx.Pen(wx.BLUE,1, wx.DOT))
                        dc1.DrawLine(x1,y,x2,y)
                        self.m_richText3.Bind( wx.EVT_PAINT, self.OnPaint)

Here is the repaint event:

def OnPaint(self,event):
                #print "re paint"
                dc1 = wx.ClientDC(self.m_richText3)

                w, h = self.m_richText3.GetTextExtent('ridiculous')

                self.m_richText3.SetInsertionPoint(dic1['ridiculous'][0]+1)
                p=self.m_richText3.GetCaret().GetPosition()
                print "convert",p
                x1=p[0]
                x2=x1+w
                y=p[1]+h
                print x1,x2
                dc1.SetPen(wx.Pen(wx.BLUE,1, wx.DOT))
                dc1.DrawLine(x1,y,x2,y)

I don’t know if this is helpful, but I found that underlines in the
RichTextCtrl only disappear if the line spacing is too small. If
you increase your line spacing a couple of points, the problem
should go away.

I could really use .docx import.  (I wrote .rtf import, and .docx is

next on my list.) Is your code available for an open-source
project? (Sorry, I’m coming to this thread a bit late and missed
earlier posts if you already pointed to your code.)

David
···

On Fri, Dec 18, 2015 at 10:26 AM, a.m.n.alsubhi@gmail.com
wrote:

            My application doesn't allow the user to

enter any text. It just read docx files and display it
in richtextbox. I store the text position index for a
list of words that I want to highlight by underlining.
When the user check the first checkbox , the application
draws underlines perfectly, but when the window is
resized all lines are erased to solve this problem I
tryed to bind the rich textbox with paint event to
redraw the lines. As a result I got flicker underlines
while the user customizes the window size and when the
resized is stop the underlines are erased.
this is checkbox:

if self.m_checkBox1.GetValue():

                w, h =

self.m_richText3.GetTextExtent(‘ridiculous’)

r11=self.m_richText3.SetInsertionPoint(dic1[‘ridiculous’][0]+1)

p=self.m_richText3.GetCaret().GetPosition()

x1=p[0]

x2=x1+w

y=p[1]+h

dc1.SetPen(wx.Pen(wx.BLUE,1, wx.DOT))

dc1.DrawLine(x1,y,x2,y)

                self.m_richText3.Bind(

wx.EVT_PAINT, self.OnPaint)

Here is the repaint event:

def OnPaint(self,event):

#print “re paint”

                dc1 =

wx.ClientDC(self.m_richText3)

                w, h =

self.m_richText3.GetTextExtent(‘ridiculous’)

self.m_richText3.SetInsertionPoint(dic1[‘ridiculous’][0]+1)

p=self.m_richText3.GetCaret().GetPosition()

print “convert”,p

x1=p[0]

x2=x1+w

y=p[1]+h

print x1,x2

                dc1.SetPen(wx.Pen(wx.BLUE,1,

wx.DOT))

dc1.DrawLine(x1,y,x2,y)

          Well, that's a good start. At least it is underlining

the right words to begin with.

          In terms of the flickering/disappearing, what happens

if you change from a ClientDC to a wx.BufferedPaintDC ?

          If that doesn't help, could you please post a small

runnable sample app (http://wiki.wxpython.org/MakingSampleApps )
and I will play with it and see if I can get it to work?

C

I’m using python-docx model to import docx file. I don’t want to use underline feature in wxrichtextctrl because it doesn’t support dashed style(only solid line) and different color from text .

···

On Friday, December 18, 2015 at 11:47:28 AM UTC-5, David wrote:

On 12/18/2015 10:41 AM, C M wrote:

On Fri, Dec 18, 2015 at 10:26 AM, a.m.n....@gmail.com > > wrote:

            My application doesn't allow the user to

enter any text. It just read docx files and display it
in richtextbox. I store the text position index for a
list of words that I want to highlight by underlining.
When the user check the first checkbox , the application
draws underlines perfectly, but when the window is
resized all lines are erased to solve this problem I
tryed to bind the rich textbox with paint event to
redraw the lines. As a result I got flicker underlines
while the user customizes the window size and when the
resized is stop the underlines are erased.
this is checkbox:

if self.m_checkBox1.GetValue():

                w, h =

self.m_richText3.GetTextExtent(‘ridiculous’)

r11=self.m_richText3.SetInsertionPoint(dic1[‘ridiculous’][0]+1)

p=self.m_richText3.GetCaret().GetPosition()

x1=p[0]

x2=x1+w

y=p[1]+h

dc1.SetPen(wx.Pen(wx.BLUE,1, wx.DOT))

dc1.DrawLine(x1,y,x2,y)

                self.m_richText3.Bind(

wx.EVT_PAINT, self.OnPaint)

Here is the repaint event:

def OnPaint(self,event):

#print “re paint”

                dc1 =

wx.ClientDC(self.m_richText3)

                w, h =

self.m_richText3.GetTextExtent(‘ridiculous’)

self.m_richText3.SetInsertionPoint(dic1[‘ridiculous’][0]+1)

p=self.m_richText3.GetCaret().GetPosition()

print “convert”,p

x1=p[0]

x2=x1+w

y=p[1]+h

print x1,x2

                dc1.SetPen(wx.Pen(wx.BLUE,1,

wx.DOT))

dc1.DrawLine(x1,y,x2,y)

          Well, that's a good start. At least it is underlining

the right words to begin with.

          In terms of the flickering/disappearing, what happens

if you change from a ClientDC to a wx.BufferedPaintDC ?

          If that doesn't help, could you please post a small

runnable sample app (http://wiki.wxpython.org/MakingSampleApps )
and I will play with it and see if I can get it to work?

C

I don't know if this is helpful, but I found that underlines in the

RichTextCtrl only disappear if the line spacing is too small. If
you increase your line spacing a couple of points, the problem
should go away.

I could really use .docx import.  (I wrote .rtf import, and .docx is

next on my list.) Is your code available for an open-source
project? (Sorry, I’m coming to this thread a bit late and missed
earlier posts if you already pointed to your code.)

David

when I changed from a ClientDC to a wx.BufferedPaintDC the whole richtextbox was flickering and I didn’t notice any line. When I use ClientDC at least I can see the line flickering during the window resizing process and then it disappeared.

···

On Friday, December 18, 2015 at 11:41:43 AM UTC-5, Che M wrote:

On Fri, Dec 18, 2015 at 10:26 AM, a.m.n....@gmail.com wrote:

My application doesn’t allow the user to enter any text. It just read docx files and display it in richtextbox. I store the text position index for a list of words that I want to highlight by underlining. When the user check the first checkbox , the application draws underlines perfectly, but when the window is resized all lines are erased to solve this problem I tryed to bind the rich textbox with paint event to redraw the lines. As a result I got flicker underlines while the user customizes the window size and when the resized is stop the underlines are erased.
this is checkbox:

if self.m_checkBox1.GetValue():

w, h = self.m_richText3.GetTextExtent(‘ridiculous’)

r11=self.m_richText3.SetInsertionPoint(dic1[‘ridiculous’][0]+1)

p=self.m_richText3.GetCaret().GetPosition()

x1=p[0]

x2=x1+w

y=p[1]+h

dc1.SetPen(wx.Pen(wx.BLUE,1, wx.DOT))

dc1.DrawLine(x1,y,x2,y)

self.m_richText3.Bind( wx.EVT_PAINT, self.OnPaint)

Here is the repaint event:

def OnPaint(self,event):

#print “re paint”

dc1 = wx.ClientDC(self.m_richText3)

w, h = self.m_richText3.GetTextExtent(‘ridiculous’)

self.m_richText3.SetInsertionPoint(dic1[‘ridiculous’][0]+1)

p=self.m_richText3.GetCaret().GetPosition()

print “convert”,p

x1=p[0]

x2=x1+w

y=p[1]+h

print x1,x2

dc1.SetPen(wx.Pen(wx.BLUE,1, wx.DOT))

dc1.DrawLine(x1,y,x2,y)

Well, that’s a good start. At least it is underlining the right words to begin with.

In terms of the flickering/disappearing, what happens if you change from a ClientDC to a wx.BufferedPaintDC ?

If that doesn’t help, could you please post a small runnable sample app (http://wiki.wxpython.org/MakingSampleApps) and I will play with it and see if I can get it to work?

C

I found RichTextDrawingHandler class in wxpython documentation. it says that this class is the base class for custom drawing handlers. It might help me to draw custom underline without any problem, but I couldn’t find any example to explain how we can use this class.
http://wxpython.org/Phoenix/docs/html/richtext.RichTextDrawingHandler.html

I’m really stuck in this point in my application and I tried every thing I could. Please if anyone has any idea, tell me about it.

···

On Friday, December 18, 2015 at 7:45:13 PM UTC-5, a.m.n....@gmail.com wrote:

when I changed from a ClientDC to a wx.BufferedPaintDC the whole richtextbox was flickering and I didn’t notice any line. When I use ClientDC at least I can see the line flickering during the window resizing process and then it disappeared.

On Friday, December 18, 2015 at 11:41:43 AM UTC-5, Che M wrote:

On Fri, Dec 18, 2015 at 10:26 AM, a.m.n....@gmail.com wrote:

My application doesn’t allow the user to enter any text. It just read docx files and display it in richtextbox. I store the text position index for a list of words that I want to highlight by underlining. When the user check the first checkbox , the application draws underlines perfectly, but when the window is resized all lines are erased to solve this problem I tryed to bind the rich textbox with paint event to redraw the lines. As a result I got flicker underlines while the user customizes the window size and when the resized is stop the underlines are erased.
this is checkbox:

if self.m_checkBox1.GetValue():

w, h = self.m_richText3.GetTextExtent(‘ridiculous’)

r11=self.m_richText3.SetInsertionPoint(dic1[‘ridiculous’][0]+1)

p=self.m_richText3.GetCaret().GetPosition()

x1=p[0]

x2=x1+w

y=p[1]+h

dc1.SetPen(wx.Pen(wx.BLUE,1, wx.DOT))

dc1.DrawLine(x1,y,x2,y)

self.m_richText3.Bind( wx.EVT_PAINT, self.OnPaint)

Here is the repaint event:

def OnPaint(self,event):

#print “re paint”

dc1 = wx.ClientDC(self.m_richText3)

w, h = self.m_richText3.GetTextExtent(‘ridiculous’)

self.m_richText3.SetInsertionPoint(dic1[‘ridiculous’][0]+1)

p=self.m_richText3.GetCaret().GetPosition()

print “convert”,p

x1=p[0]

x2=x1+w

y=p[1]+h

print x1,x2

dc1.SetPen(wx.Pen(wx.BLUE,1, wx.DOT))

dc1.DrawLine(x1,y,x2,y)

Well, that’s a good start. At least it is underlining the right words to begin with.

In terms of the flickering/disappearing, what happens if you change from a ClientDC to a wx.BufferedPaintDC ?

If that doesn’t help, could you please post a small runnable sample app (http://wiki.wxpython.org/MakingSampleApps) and I will play with it and see if I can get it to work?

C

I'm really stuck in this point in my application and I tried every thing I
could. Please if anyone has any idea, tell me about it.

I hear you, but you haven't yet posted a small runnable sample. Is there
some compelling reason you can't do that? I've found it is usually the
shortest path to a solution here, either because the solution occurs to you
while constructing the sample, or someone is able to play with your code
and figure it out and let you know. (Either that, or devise a Robinlight
and shine it onto a cloud in the night sky?)

I don’t want use Underline feature in Richtextctrl for some reasons. I’m trying to draw a dashed line under specific words when the user checked the “checkbox1”. I have a problem in x,y coordinates and I don’t know how to get these coordinates correctly.

Here is the code:

sample.py (5.12 KB)

···

On Friday, December 4, 2015 at 4:34:26 PM UTC-5, a.m.n....@gmail.com wrote:

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)

Sorry, my mistake. It was bound, but only from within the
m_checkBox1OnCheckBox() method, and that only was entered when there was a
checkbox event. Normal paint events due to resizing were never redirected
to your OnPaint method.

···

On Sat, Dec 19, 2015 at 5:50 PM, C M <cmpython@gmail.com> wrote:

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.

Dear Che M,
you are awesome. It works now yeah. I’m really thankful for you.

Again trillions thanks for you.

···

On Saturday, December 19, 2015 at 6:05:03 PM UTC-5, Che M wrote:

On Sat, Dec 19, 2015 at 5:50 PM, C M cmpy...@gmail.com wrote:

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.

Sorry, my mistake. It was bound, but only from within the m_checkBox1OnCheckBox() method, and that only was entered when there was a checkbox event. Normal paint events due to resizing were never redirected to your OnPaint method.