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:
parent
f4abae9cd7
commit
f0b0b7d4b8
@ -16,7 +16,8 @@ def runTest(frame, nb, log):
|
|||||||
|
|
||||||
ed.SetText(["",
|
ed.SetText(["",
|
||||||
"This is a simple text editor, the class name is",
|
"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.",
|
pyed.SetText(["# This one is a derived class named wxPyEditor.",
|
||||||
"# It adds syntax highlighting, folding (press",
|
"# It adds syntax highlighting, folding (press",
|
||||||
|
10
utils/wxPython/lib/editor/README.txt
Normal file
10
utils/wxPython/lib/editor/README.txt
Normal 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
|
@ -10,6 +10,19 @@
|
|||||||
# Licence: wxWindows license
|
# 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 wxPython.wx import *
|
||||||
from string import *
|
from string import *
|
||||||
from keyword import *
|
from keyword import *
|
||||||
@ -18,9 +31,6 @@ from tokenizer import *
|
|||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
#EDITOR_STD_LINE = ("", [], (0,0,0))
|
|
||||||
|
|
||||||
#---------
|
|
||||||
|
|
||||||
class Line:
|
class Line:
|
||||||
def __init__(self, text=""):
|
def __init__(self, text=""):
|
||||||
@ -67,14 +77,16 @@ class wxEditor(wxScrolledWindow):
|
|||||||
self.sy = 0
|
self.sy = 0
|
||||||
self.sw = 0
|
self.sw = 0
|
||||||
self.sh = 0
|
self.sh = 0
|
||||||
|
self.osx= 0
|
||||||
|
self.osy= 0
|
||||||
|
|
||||||
# font
|
# font
|
||||||
dc = wxClientDC(self)
|
dc = wxClientDC(self)
|
||||||
|
|
||||||
#if wxPlatform == "__WXMSW__":
|
if wxPlatform == "__WXMSW__":
|
||||||
self.font = wxFont(12, wxMODERN, wxNORMAL, wxNORMAL)
|
self.font = wxFont(10, wxMODERN, wxNORMAL, wxNORMAL)
|
||||||
#else:
|
else:
|
||||||
# self.font = wxFont(12, wxMODERN, wxNORMAL, wxNORMAL, false)
|
self.font = wxFont(12, wxMODERN, wxNORMAL, wxNORMAL, false)
|
||||||
dc.SetFont(self.font)
|
dc.SetFont(self.font)
|
||||||
|
|
||||||
# font weight, height
|
# font weight, height
|
||||||
@ -111,6 +123,8 @@ class wxEditor(wxScrolledWindow):
|
|||||||
|
|
||||||
self.update = true
|
self.update = true
|
||||||
self.in_scroll =FALSE
|
self.in_scroll =FALSE
|
||||||
|
self.inUpdate = FALSE
|
||||||
|
|
||||||
|
|
||||||
bw,bh = self.GetSizeTuple()
|
bw,bh = self.GetSizeTuple()
|
||||||
# double buffering
|
# double buffering
|
||||||
@ -140,11 +154,13 @@ class wxEditor(wxScrolledWindow):
|
|||||||
self.len = len(self.lines)
|
self.len = len(self.lines)
|
||||||
self.max_linelength =maxlen
|
self.max_linelength =maxlen
|
||||||
|
|
||||||
|
|
||||||
def SetFontTab(self, fonttab):
|
def SetFontTab(self, fonttab):
|
||||||
###############################################################
|
###############################################################
|
||||||
""" Fonttabelle zum schnellen Zugriff """
|
""" Fonttabelle zum schnellen Zugriff """
|
||||||
self.ftab = fonttab
|
self.ftab = fonttab
|
||||||
|
|
||||||
|
|
||||||
def SetText(self, text = [""]):
|
def SetText(self, text = [""]):
|
||||||
###############################################################
|
###############################################################
|
||||||
""" Text mittels Liste setzen """
|
""" Text mittels Liste setzen """
|
||||||
@ -164,6 +180,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
self.update = true
|
self.update = true
|
||||||
self.UpdateView(None, true)
|
self.UpdateView(None, true)
|
||||||
|
|
||||||
|
|
||||||
# show new text
|
# show new text
|
||||||
def GetText(self):
|
def GetText(self):
|
||||||
###############################################################
|
###############################################################
|
||||||
@ -173,6 +190,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
text.append(line.text)
|
text.append(line.text)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
def IsEmpty(self):
|
def IsEmpty(self):
|
||||||
###############################################################
|
###############################################################
|
||||||
"""see if at least one text line is not empty"""
|
"""see if at least one text line is not empty"""
|
||||||
@ -180,19 +198,23 @@ class wxEditor(wxScrolledWindow):
|
|||||||
if line.text: return 0
|
if line.text: return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
def IsLine(self, line):
|
def IsLine(self, line):
|
||||||
###############################################################
|
###############################################################
|
||||||
""" Schauen, ob alles im grünen Bereich ist """
|
""" Schauen, ob alles im grünen Bereich ist """
|
||||||
return (line>=0) and (line<self.len)
|
return (line>=0) and (line<self.len)
|
||||||
|
|
||||||
|
|
||||||
def IsEditable(self, line):
|
def IsEditable(self, line):
|
||||||
###############################################################
|
###############################################################
|
||||||
return self.text[self.GetLine(line)].editable
|
return self.text[self.GetLine(line)].editable
|
||||||
|
|
||||||
|
|
||||||
def GetLine(self, line):
|
def GetLine(self, line):
|
||||||
###############################################################
|
###############################################################
|
||||||
return self.lines[line]
|
return self.lines[line]
|
||||||
|
|
||||||
|
|
||||||
def GetTextLine(self, line):
|
def GetTextLine(self, line):
|
||||||
###############################################################
|
###############################################################
|
||||||
""" Text holen """
|
""" Text holen """
|
||||||
@ -200,6 +222,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
return self.text[self.GetLine(line)].text
|
return self.text[self.GetLine(line)].text
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def SetTextLine(self, line, text):
|
def SetTextLine(self, line, text):
|
||||||
###############################################################
|
###############################################################
|
||||||
""" Nur den Text ändern """
|
""" Nur den Text ändern """
|
||||||
@ -269,41 +292,49 @@ class wxEditor(wxScrolledWindow):
|
|||||||
self.sco_x = xp
|
self.sco_x = xp
|
||||||
self.sco_y = yp
|
self.sco_y = yp
|
||||||
|
|
||||||
|
|
||||||
def OnScroll(self, event):
|
def OnScroll(self, event):
|
||||||
dir =event.GetOrientation()
|
dir =event.GetOrientation()
|
||||||
evt =event.GetEventType()
|
evt =event.GetEventType()
|
||||||
if dir ==wxHORIZONTAL:
|
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_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_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:
|
elif evt ==wxEVT_SCROLLWIN_BOTTOM:
|
||||||
self.sx =self.max_linelength -self.sw
|
self.sx =self.max_linelength -self.sw
|
||||||
self.cx =self.max_linelength
|
self.cx =self.max_linelength
|
||||||
else: self.sx =event.GetPosition()
|
else:
|
||||||
|
self.sx =event.GetPosition()
|
||||||
|
|
||||||
if self.sx >(self.max_linelength -self.sw +1):
|
if self.sx >(self.max_linelength -self.sw +1):
|
||||||
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.sw -1): self.cx =self.sx +self.sw -1
|
||||||
if self.cx <self.sx: self.cx =self.sx
|
if self.cx <self.sx: self.cx =self.sx
|
||||||
|
|
||||||
else:
|
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_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_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:
|
elif evt ==wxEVT_SCROLLWIN_BOTTOM:
|
||||||
self.sy =self.len -self.sh
|
self.sy =self.len -self.sh
|
||||||
self.cy =self.len
|
self.cy =self.len
|
||||||
else: self.sy =event.GetPosition()
|
else:
|
||||||
|
self.sy =event.GetPosition()
|
||||||
|
|
||||||
if self.sy >(self.len -self.sh +1):
|
if self.sy >(self.len -self.sh +1):
|
||||||
self.sy =self.len -self.sh +1
|
self.sy =self.len -self.sh +1
|
||||||
if self.sy <0: self.sy =0
|
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.sh -1): self.cy =self.sy +self.sh -1
|
||||||
if self.cy <self.sy: self.cy =self.sy
|
if self.cy <self.sy: self.cy =self.sy
|
||||||
|
|
||||||
self.UpdateView()
|
self.UpdateView()
|
||||||
|
|
||||||
|
|
||||||
def AdjustScrollbars(self):
|
def AdjustScrollbars(self):
|
||||||
# there appears to be endless recursion:
|
# there appears to be endless recursion:
|
||||||
# SetScrollbars issue EvtPaint which calls UpdateView
|
# SetScrollbars issue EvtPaint which calls UpdateView
|
||||||
@ -316,8 +347,10 @@ class wxEditor(wxScrolledWindow):
|
|||||||
# even if current position >0
|
# even if current position >0
|
||||||
max(self.len +1, self.sy +self.sh),
|
max(self.len +1, self.sy +self.sh),
|
||||||
self.sx, self.sy)
|
self.sx, self.sy)
|
||||||
|
self.osx, self.osy = self.sx, self.sy
|
||||||
self.in_scroll =FALSE
|
self.in_scroll =FALSE
|
||||||
|
|
||||||
|
|
||||||
# adapts the output to what it should be
|
# adapts the output to what it should be
|
||||||
def UpdateView(self, dc = None, doup=false):
|
def UpdateView(self, dc = None, doup=false):
|
||||||
###############################################################
|
###############################################################
|
||||||
@ -325,6 +358,9 @@ class wxEditor(wxScrolledWindow):
|
|||||||
Diese Routine wird immer dann aufgerufen, wenn
|
Diese Routine wird immer dann aufgerufen, wenn
|
||||||
sich etwas verändert hat
|
sich etwas verändert hat
|
||||||
"""
|
"""
|
||||||
|
if self.inUpdate:
|
||||||
|
return
|
||||||
|
self.inUpdate = true
|
||||||
|
|
||||||
self.CalcLines()
|
self.CalcLines()
|
||||||
|
|
||||||
@ -351,20 +387,25 @@ class wxEditor(wxScrolledWindow):
|
|||||||
self.ocy = self.cy
|
self.ocy = self.cy
|
||||||
|
|
||||||
# alles beim alten
|
# alles beim alten
|
||||||
self.AdjustScrollbars()
|
if self.osx != self.sx or self.osy != self.sy:
|
||||||
|
self.AdjustScrollbars()
|
||||||
|
|
||||||
self.DrawSimpleCursor(0,0,dc, true)
|
self.DrawSimpleCursor(0,0,dc, true)
|
||||||
# [als] i don't really understand how the following condition works
|
# [als] i don't really understand how the following condition works
|
||||||
if self.update or doup:
|
#if self.update or doup:
|
||||||
self.Draw(dc)
|
self.Draw(dc)
|
||||||
self.update = false
|
# self.update = false
|
||||||
else:
|
#else:
|
||||||
self.DrawCursor(dc)
|
# self.DrawCursor(dc)
|
||||||
|
|
||||||
self.o_cx = self.cx
|
self.o_cx = self.cx
|
||||||
self.o_cy = self.cy
|
self.o_cy = self.cy
|
||||||
self.o_sx = self.sx
|
self.o_sx = self.sx
|
||||||
self.o_sy = self.sy
|
self.o_sy = self.sy
|
||||||
self.o_line = self.line
|
self.o_line = self.line
|
||||||
|
self.inUpdate = false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def DrawEditText(self, t, x, y, dc = None):
|
def DrawEditText(self, t, x, y, dc = None):
|
||||||
@ -376,6 +417,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
dc.SetFont(self.font)
|
dc.SetFont(self.font)
|
||||||
dc.DrawText(t, x * self.fw, y * self.fh)
|
dc.DrawText(t, x * self.fw, y * self.fh)
|
||||||
|
|
||||||
|
|
||||||
def DrawLine(self, line, dc=None):
|
def DrawLine(self, line, dc=None):
|
||||||
###############################################################
|
###############################################################
|
||||||
"""
|
"""
|
||||||
@ -419,6 +461,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
dc.SetTextForeground(self.ftab[col])
|
dc.SetTextForeground(self.ftab[col])
|
||||||
self.DrawEditText(t[pos:], (pos-ll), y, dc)
|
self.DrawEditText(t[pos:], (pos-ll), y, dc)
|
||||||
|
|
||||||
|
|
||||||
def Draw(self, odc=None):
|
def Draw(self, odc=None):
|
||||||
###############################################################
|
###############################################################
|
||||||
"""
|
"""
|
||||||
@ -456,6 +499,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
linelen =len(self.text[self.GetLine(cy)].text)
|
linelen =len(self.text[self.GetLine(cy)].text)
|
||||||
if self.cx >linelen: self.cx =linelen
|
if self.cx >linelen: self.cx =linelen
|
||||||
|
|
||||||
|
|
||||||
def cHoriz(self, num):
|
def cHoriz(self, num):
|
||||||
###############################################################
|
###############################################################
|
||||||
""" Horizontale Cursorverschiebung
|
""" Horizontale Cursorverschiebung
|
||||||
@ -469,6 +513,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
elif cx <self.sx: self.sx =cx
|
elif cx <self.sx: self.sx =cx
|
||||||
self.cx =cx
|
self.cx =cx
|
||||||
|
|
||||||
|
|
||||||
def InsertText(self, text):
|
def InsertText(self, text):
|
||||||
###############################################################
|
###############################################################
|
||||||
"""
|
"""
|
||||||
@ -586,6 +631,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
self.bw,self.bh = self.GetSizeTuple()
|
self.bw,self.bh = self.GetSizeTuple()
|
||||||
self.UpdateView(dc, true)
|
self.UpdateView(dc, true)
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def GetIndent(self, line):
|
def GetIndent(self, line):
|
||||||
@ -596,6 +642,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
else: break
|
else: break
|
||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
||||||
def Goto(self, pos):
|
def Goto(self, pos):
|
||||||
self.cVert(pos-self.cy-1)
|
self.cVert(pos-self.cy-1)
|
||||||
self.UpdateView()
|
self.UpdateView()
|
||||||
@ -617,3 +664,4 @@ class wxEditor(wxScrolledWindow):
|
|||||||
|
|
||||||
def OnFold(self):
|
def OnFold(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user