Fixes to avoid an endless event looping for wxGTK

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5171 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn 2000-01-02 05:26:21 +00:00
parent f4abae9cd7
commit f0b0b7d4b8
3 changed files with 82 additions and 23 deletions

View File

@ -16,7 +16,8 @@ def runTest(frame, nb, log):
ed.SetText(["",
"This is a simple text editor, the class name is",
"wxEditor. Type a few lines and try it out."])
"wxEditor. Type a few lines and try it out.",
""])
pyed.SetText(["# This one is a derived class named wxPyEditor.",
"# It adds syntax highlighting, folding (press",

View File

@ -0,0 +1,10 @@
PLEASE NOTE: This is experimental code. It needs an overhall in the
drawing and update code, and there is occasionally a
mysteriously disappearing line...
I am working on a StyledTextEditor that will likely
render this editor obsolete... But this one is at
least somewhat functional now while the other is still
vapor.
- Robin

View File

@ -10,6 +10,19 @@
# Licence: wxWindows license
#----------------------------------------------------------------------
# PLEASE NOTE: This is experimental code. It needs an overhall in the
# drawing and update code, and there is occasionally a
# mysteriously disappearing line...
#
# I am working on a StyledTextEditor that will likely
# render this editor obsolete... But this one is at
# least somewhat functional now while the other is still
# vapor.
#
# - Robin
from wxPython.wx import *
from string import *
from keyword import *
@ -18,9 +31,6 @@ from tokenizer import *
#---------------------------------------------------------------------------
#EDITOR_STD_LINE = ("", [], (0,0,0))
#---------
class Line:
def __init__(self, text=""):
@ -67,14 +77,16 @@ class wxEditor(wxScrolledWindow):
self.sy = 0
self.sw = 0
self.sh = 0
self.osx= 0
self.osy= 0
# font
dc = wxClientDC(self)
#if wxPlatform == "__WXMSW__":
self.font = wxFont(12, wxMODERN, wxNORMAL, wxNORMAL)
#else:
# self.font = wxFont(12, wxMODERN, wxNORMAL, wxNORMAL, false)
if wxPlatform == "__WXMSW__":
self.font = wxFont(10, wxMODERN, wxNORMAL, wxNORMAL)
else:
self.font = wxFont(12, wxMODERN, wxNORMAL, wxNORMAL, false)
dc.SetFont(self.font)
# font weight, height
@ -111,6 +123,8 @@ class wxEditor(wxScrolledWindow):
self.update = true
self.in_scroll =FALSE
self.inUpdate = FALSE
bw,bh = self.GetSizeTuple()
# double buffering
@ -140,11 +154,13 @@ class wxEditor(wxScrolledWindow):
self.len = len(self.lines)
self.max_linelength =maxlen
def SetFontTab(self, fonttab):
###############################################################
""" Fonttabelle zum schnellen Zugriff """
self.ftab = fonttab
def SetText(self, text = [""]):
###############################################################
""" Text mittels Liste setzen """
@ -164,6 +180,7 @@ class wxEditor(wxScrolledWindow):
self.update = true
self.UpdateView(None, true)
# show new text
def GetText(self):
###############################################################
@ -173,6 +190,7 @@ class wxEditor(wxScrolledWindow):
text.append(line.text)
return text
def IsEmpty(self):
###############################################################
"""see if at least one text line is not empty"""
@ -180,19 +198,23 @@ class wxEditor(wxScrolledWindow):
if line.text: return 0
return 1
def IsLine(self, line):
###############################################################
""" Schauen, ob alles im grünen Bereich ist """
return (line>=0) and (line<self.len)
def IsEditable(self, line):
###############################################################
return self.text[self.GetLine(line)].editable
def GetLine(self, line):
###############################################################
return self.lines[line]
def GetTextLine(self, line):
###############################################################
""" Text holen """
@ -200,6 +222,7 @@ class wxEditor(wxScrolledWindow):
return self.text[self.GetLine(line)].text
return ""
def SetTextLine(self, line, text):
###############################################################
""" Nur den Text ändern """
@ -269,41 +292,49 @@ class wxEditor(wxScrolledWindow):
self.sco_x = xp
self.sco_y = yp
def OnScroll(self, event):
dir =event.GetOrientation()
evt =event.GetEventType()
if dir ==wxHORIZONTAL:
if evt ==wxEVT_SCROLLWIN_LINEUP: self.sx =self.sx -1
if evt ==wxEVT_SCROLLWIN_LINEUP: self.sx =self.sx -1
elif evt ==wxEVT_SCROLLWIN_LINEDOWN: self.sx =self.sx +1
elif evt ==wxEVT_SCROLLWIN_PAGEUP: self.sx =self.sx -self.sw
elif evt ==wxEVT_SCROLLWIN_PAGEUP: self.sx =self.sx -self.sw
elif evt ==wxEVT_SCROLLWIN_PAGEDOWN: self.sx =self.sx +self.sw
elif evt ==wxEVT_SCROLLWIN_TOP: self.sx =self.cx =0
elif evt ==wxEVT_SCROLLWIN_TOP: self.sx =self.cx =0
elif evt ==wxEVT_SCROLLWIN_BOTTOM:
self.sx =self.max_linelength -self.sw
self.cx =self.max_linelength
else: self.sx =event.GetPosition()
else:
self.sx =event.GetPosition()
if self.sx >(self.max_linelength -self.sw +1):
self.sx =self.max_linelength -self.sw +1
if self.sx <0: self.sx =0
if self.sx <0: self.sx =0
if self.cx >(self.sx +self.sw -1): self.cx =self.sx +self.sw -1
if self.cx <self.sx: self.cx =self.sx
else:
if evt ==wxEVT_SCROLLWIN_LINEUP: self.sy =self.sy -1
if evt ==wxEVT_SCROLLWIN_LINEUP: self.sy =self.sy -1
elif evt ==wxEVT_SCROLLWIN_LINEDOWN: self.sy =self.sy +1
elif evt ==wxEVT_SCROLLWIN_PAGEUP: self.sy =self.sy -self.sh
elif evt ==wxEVT_SCROLLWIN_PAGEUP: self.sy =self.sy -self.sh
elif evt ==wxEVT_SCROLLWIN_PAGEDOWN: self.sy =self.sy +self.sh
elif evt ==wxEVT_SCROLLWIN_TOP: self.sy =self.cy =0
elif evt ==wxEVT_SCROLLWIN_TOP: self.sy =self.cy =0
elif evt ==wxEVT_SCROLLWIN_BOTTOM:
self.sy =self.len -self.sh
self.cy =self.len
else: self.sy =event.GetPosition()
else:
self.sy =event.GetPosition()
if self.sy >(self.len -self.sh +1):
self.sy =self.len -self.sh +1
if self.sy <0: self.sy =0
if self.cy >(self.sy +self.sh -1): self.cy =self.sy +self.sh -1
if self.cy <self.sy: self.cy =self.sy
self.UpdateView()
def AdjustScrollbars(self):
# there appears to be endless recursion:
# SetScrollbars issue EvtPaint which calls UpdateView
@ -316,8 +347,10 @@ class wxEditor(wxScrolledWindow):
# even if current position >0
max(self.len +1, self.sy +self.sh),
self.sx, self.sy)
self.osx, self.osy = self.sx, self.sy
self.in_scroll =FALSE
# adapts the output to what it should be
def UpdateView(self, dc = None, doup=false):
###############################################################
@ -325,6 +358,9 @@ class wxEditor(wxScrolledWindow):
Diese Routine wird immer dann aufgerufen, wenn
sich etwas verändert hat
"""
if self.inUpdate:
return
self.inUpdate = true
self.CalcLines()
@ -351,20 +387,25 @@ class wxEditor(wxScrolledWindow):
self.ocy = self.cy
# alles beim alten
self.AdjustScrollbars()
if self.osx != self.sx or self.osy != self.sy:
self.AdjustScrollbars()
self.DrawSimpleCursor(0,0,dc, true)
# [als] i don't really understand how the following condition works
if self.update or doup:
self.Draw(dc)
self.update = false
else:
self.DrawCursor(dc)
#if self.update or doup:
self.Draw(dc)
# self.update = false
#else:
# self.DrawCursor(dc)
self.o_cx = self.cx
self.o_cy = self.cy
self.o_sx = self.sx
self.o_sy = self.sy
self.o_line = self.line
self.inUpdate = false
def DrawEditText(self, t, x, y, dc = None):
@ -376,6 +417,7 @@ class wxEditor(wxScrolledWindow):
dc.SetFont(self.font)
dc.DrawText(t, x * self.fw, y * self.fh)
def DrawLine(self, line, dc=None):
###############################################################
"""
@ -419,6 +461,7 @@ class wxEditor(wxScrolledWindow):
dc.SetTextForeground(self.ftab[col])
self.DrawEditText(t[pos:], (pos-ll), y, dc)
def Draw(self, odc=None):
###############################################################
"""
@ -456,6 +499,7 @@ class wxEditor(wxScrolledWindow):
linelen =len(self.text[self.GetLine(cy)].text)
if self.cx >linelen: self.cx =linelen
def cHoriz(self, num):
###############################################################
""" Horizontale Cursorverschiebung
@ -469,6 +513,7 @@ class wxEditor(wxScrolledWindow):
elif cx <self.sx: self.sx =cx
self.cx =cx
def InsertText(self, text):
###############################################################
"""
@ -586,6 +631,7 @@ class wxEditor(wxScrolledWindow):
self.bw,self.bh = self.GetSizeTuple()
self.UpdateView(dc, true)
#-----------------------------------------------------------------------------------------
def GetIndent(self, line):
@ -596,6 +642,7 @@ class wxEditor(wxScrolledWindow):
else: break
return p
def Goto(self, pos):
self.cVert(pos-self.cy-1)
self.UpdateView()
@ -617,3 +664,4 @@ class wxEditor(wxScrolledWindow):
def OnFold(self):
pass