Hello,
I have found that wxTextCtrl momentarily selects the range of text to
which a style is being applied. Please consider the simple example at
the end of the mail which illustrates the point.
The application is supposed to create a simple window with a wxTextCtrl
as the main widget. The text control ignores all keys except CTRL-A at
which time it inserts a string into the text control and changes the
style to some value.
The problem is that when the range of SetStyle is large, there is
a momentary flicker where the whole file is seen selected. This causes
an annoying "flashing" effect.
I am wondering if there is a way to avoid this...
Thanks,
Srinath
from wxPython.wx import *
class MainWindow(wxFrame):
def __init__(self, parent):
wxFrame.__init__(self, parent, -1, "My Application",
style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
self.editor = SimpleTextCtrl(self)
self.Show(true)
class SimpleTextCtrl(wxTextCtrl):
def __init__(self, parent):
wxTextCtrl.__init__(self, parent, 1,
style=wxTE_MULTILINE|wxTE_RICH2|wxTE_DONTWRAP)
EVT_KEY_DOWN(self, self.OnChar)
def OnChar(self, event):
if event.KeyCode() == ord('A') and event.ControlDown():
self.Append('Hello World!\n'*2000)
return
def Append(self, text):
freeze = 1
if freeze:
self.Freeze()
self.AppendText(text)
self.SetInsertionPoint(0)
wxUsleep(500)
self.SetStyle(0, self.GetLastPosition(),
wxTextAttr("#0000FF", "#FFFFFF", wxFont(10, wxSWISS,
wxNORMAL, wxNORMAL, False, 'Times New Roman')))
if freeze:
self.Thaw()
def main():
app = wxPySimpleApp()
frame = MainWindow(None)
app.MainLoop()
if __name__ == "__main__":
main()