Thanks for the advice Robin. Based on the link you mentioned, I wrote
my own Python method to control the scrolling so the cursor stays on
the screen. I've included it below (called _ShowPosition in the
code). It's not thoroughly tested, but is seems to work well enough
on my Mac running Snow Leopard and wxPython 2.8.10.1
I set this up to work a little differently than the default. Here, if
one is entering characters at the end of the document it automatically
scrolls so that the entered characters are on screen. Also, though,
if one is entering characters in the middle of a document, when the
cursor goes off screen, it scrolls so that the cursor moves to the
middle of the window.
Thanks again,
Tom
import wx
import wx.richtext as rtcm
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)
self.Bind(wx.EVT_KEY_DOWN, self.VisibleWrite)
self.center_caret = True
def VisibleWrite(self, evt):
x = evt.GetKeyCode()
self.WriteText(unichr(x))
ipos = self.GetInsertionPoint()
self._ShowPosition(ipos)
def _ShowPosition(self, ipos):
line = self.GetVisibleLineForCaretPosition(ipos)
ppuX, ppuY = self.GetScrollPixelsPerUnit() #unit = scroll
step
startYUnits = self.GetViewStart()[1]
sy = self.GetVirtualSize()[1]
if ppuY==0:
return False # since there's no scrolling, hence no
adjusting
syUnits = sy/ppuY
r = line.GetRect()
ry = r.GetY()
rh = r.GetHeight()
csY = self.GetClientSize()[1]
csY -= self.GetBuffer().GetBottomMargin()
if self.center_caret:
if ry >= startYUnits*ppuY + csY - rh/2:
yUnits = startYUnits + csY/ppuY/2
self.SetScrollbars(ppuX, ppuY, 0, syUnits, 0, yUnits)
self.PositionCaret()
return True
return False
app = wx.PySimpleApp()
frame = wx.Frame(None, -1, "RTC demo", size=(100,100))
frame.Show(True)
tc = MyRTC(frame)
app.MainLoop()
>
http://trac.wxwidgets.org/browser/wxWidgets/branches/WX_2_8_BRANCH/sr...
>
> --
> Robin Dunn
> Software Craftsmanhttp://wxPython.org