好了,所以這裏的地方我得:
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」選項,它都會變成梨形。我真的需要這樣做語法高亮的錯誤,但如果我不能啓用該選項,我註定要單色 - 噓!
有關如何阻止對富編輯控件進行滾動的更多想法?
好點 - 看起來像我不經意地調用窗口框架而不是嵌套的CTextCtrl。 我仍然停留在滾動範圍底部時停止滾動的東西... – 2008-09-30 22:46:09