The problem I'm having involves using RichTextControl and EVT_CHAR to
capture characters that user types, and then I write a different
character in response. That is, instead of using the default
character writing, I use WriteText with the character I choose. The
specific issue is that when the entries run beyond the vertical length
of the window and it starts to scroll, the entries are no longer
visible. I've tried using GetInsertionPoint and ShowPosition to make
this visible, but oddly, this only works for every other line of
entered text, where the alternate lines are invisible as they are
being typed.
Below is a small example that just writes random characters. Note
that if you enter characters beyond the length of the window, the
lines are only alternately visible, but if the Bind line is commented
out, the visibility is fine.
I would be very grateful if anyone has any ideas on this. The default
behavior is very crisp and nice looking, but I just can't seem to re-
create it with my own management.
Tom
import wx
import wx.richtext as rtcm
import random
class MyRTC(rtcm.RichTextCtrl):
def __init__(self, parent):
rtcm.RichTextCtrl.__init__(self, parent, -1,
style=wx.VSCROLL|wx.HSCROLL|wx.NO_BORDER|
wx.WANTS_CHARS)
self.BeginFontSize(20)
# comment out the line below to get correct behavior
self.Bind(wx.EVT_CHAR, self.VisibleWrite)
def VisibleWrite(self, evt):
x = evt.GetKeyCode()
if x>=33 and x<=126: # make a random char for each typed
char.
x = random.randrange(33, 126+1)
self.WriteText(unichr(x))
# the lines below should make the typed text visible, but
don't
ipos = self.GetInsertionPoint()
self.ShowPosition(100000)
app = wx.PySimpleApp()
frame = wx.Frame(None, -1, "RTC demo", size=(100,100))
frame.Show(True)
tc = MyRTC(frame)
app.MainLoop()