[wxPython] wxStyledTextCtrl.ReplaceTarget

Why doesn't ReplaceTarget work in OnModified?

···

------------------------------------------------------
from wxPython.wx import *
from wxPython.stc import *

class MySTC(wxStyledTextCtrl):
    def __init__(self, parent):
        WID = wxNewId()
        wxStyledTextCtrl.__init__(self, parent, WID)
        self.SetText("Hallo world!")
        self.SetTargetStart(1)
        self.SetTargetEnd(2)
        self.ReplaceTarget("e") # OK
        EVT_STC_MODIFIED(self, WID, self.OnModified)

    def OnModified(self, event):
        self.SetTargetStart(1)
        self.SetTargetEnd(2)
        self.ReplaceTarget("X") # This doesn't work

class MyApp(wxApp):
    def OnInit(self):
        frame = wxFrame(None, -1, "hi")
        MySTC(frame)
        frame.Show(1)
        self.SetTopWindow(frame)
        return 1

MyApp().MainLoop()
------------------------------------------------------

Thanks
Marco Barisione

Marco Barisione:

Why doesn't ReplaceTarget work in OnModified?

   No modifications are permitted during OnModified which is a very low
level event as it leads to complex reentrance with potential for bugs. Defer
the modifications to an idle task or use one of the higher level events such
as CharAdded.

   Neil

   No modifications are permitted during OnModified which is a very low
level event as it leads to complex reentrance with potential for bugs.
Defer the modifications to an idle task or use one of the higher level
events such as CharAdded.

I need to know the text added to the control but event.GetText() doesn't
work in OnCharAdded or in OnChange.

···

--
Marco Barisione

Marco Barisione:

I need to know the text added to the control but event.GetText() doesn't
work in OnCharAdded or in OnChange.

   OnCharAdded provides the character typed which you should be able to
access through GetKey().

   Neil

   OnCharAdded provides the character typed which you should be able to
access through GetKey().

I need to know every modification of the text (text from clipboard, text
deleted...).

···

--
Marco Barisione

Marco Barisione:

I need to know every modification of the text (text from clipboard, text
deleted...).

   Then you will have to queue your changes to be handled by an idle or
timer task.

   Neil

Neil Hodgson wrote:

   Then you will have to queue your changes to be handled by an idle or
timer task.

I think it wouldn't work in my case.

I need to allow no more then MAX_LINE chars in wxStyledTextCtrl, for
instance if MAX_LINE is 18 this text:

Python wxPython www.xxxx.it
Microsoft Bill Gates Guido van Rossum Italia Pizza Spaghetti

becomes:

Python wxPython
http://www.xxxx.it/xxxx.htm
Microsoft Bill
Gates Italia Pizza
Spaghetti Guido
van Rossum

So I thought to add a "\n" if a line is longer than MAX_LINE and to memorize
the position of this fake end of lines (they will become real eols only when
the message is posted) in a list. When text is added fake eols are replaced
by white spaces and then calculated again. Is there a way to do this?

I hope you can understand in spite of my English.

···

--
Marco Barisione

Marco Barisione:

I think it wouldn't work in my case.

I need to allow no more then MAX_LINE chars in wxStyledTextCtrl, for
instance if MAX_LINE is 18 this text:
...

   Line wrapping will be supported in a future version of Scintilla. Today's
1.42 release contains an experimental version of line wrapping. It may take
months to make this work well and for it to be included in wxStyledTextCtrl.

   Neil