好的,这就是我必须要做的:
import wx
from threading import Timer
import time
class Form1(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.logger = wx.TextCtrl(self,5, "",wx.Point(20,20), wx.Size(200,200), \
wx.TE_MULTILINE | wx.TE_READONLY)# | wx.TE_RICH2)
t = Timer(0.1, self.AddText)
t.start()
def AddText(self):
# Resart the timer
t = Timer(0.25, self.AddText)
t.start()
# Work out if we're at the end of the file
currentCaretPosition = self.logger.GetInsertionPoint()
currentLengthOfText = self.logger.GetLastPosition()
if currentCaretPosition != currentLengthOfText:
self.holdingBack = True
else:
self.holdingBack = False
timeStamp = str(time.time())
# If we're not at the end of the file, we're holding back
if self.holdingBack:
print "%s FROZEN"%(timeStamp)
self.logger.Freeze()
(currentSelectionStart, currentSelectionEnd) = self.logger.GetSelection()
self.logger.AppendText(timeStamp+"\n")
self.logger.SetInsertionPoint(currentCaretPosition)
self.logger.SetSelection(currentSelectionStart, currentSelectionEnd)
self.logger.Thaw()
else:
print "%s THAWED"%(timeStamp)
self.logger.AppendText(timeStamp+"\n")
app = wx.PySimpleApp()
frame = wx.Frame(None, size=(550,425))
Form1(frame)
frame.Show(1)
app.MainLoop()
这个简单的演示应用程序几乎可以完美运行。除非用户单击不在文本末尾的行,否则它会整齐地滚动。此后它保持良好状态,因此您可以选择文本(注意:那里仍然存在一个错误,如果您选择向上而不是向下,它会清除您的选择)。
最大的烦恼是,如果我尝试启用“| wx.TE_RICH2”选项,一切都会变得有点像梨形。我真的需要这个来对错误进行语法高亮显示,但是如果我不能启用该选项,我注定要单色 - 嘘!
关于如何阻止富编辑控件滚动的更多想法?