From f0b0b7d4b803b59ead09d076402df3d5f2c10e2f Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sun, 2 Jan 2000 05:26:21 +0000 Subject: [PATCH] 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 --- utils/wxPython/demo/wxEditor.py | 3 +- utils/wxPython/lib/editor/README.txt | 10 +++ utils/wxPython/lib/editor/editor.py | 92 +++++++++++++++++++++------- 3 files changed, 82 insertions(+), 23 deletions(-) create mode 100644 utils/wxPython/lib/editor/README.txt diff --git a/utils/wxPython/demo/wxEditor.py b/utils/wxPython/demo/wxEditor.py index ffbea7d2ee..a798b9a8f6 100644 --- a/utils/wxPython/demo/wxEditor.py +++ b/utils/wxPython/demo/wxEditor.py @@ -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", diff --git a/utils/wxPython/lib/editor/README.txt b/utils/wxPython/lib/editor/README.txt new file mode 100644 index 0000000000..6072b4360d --- /dev/null +++ b/utils/wxPython/lib/editor/README.txt @@ -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 diff --git a/utils/wxPython/lib/editor/editor.py b/utils/wxPython/lib/editor/editor.py index 3b0df9c4c9..247afba036 100644 --- a/utils/wxPython/lib/editor/editor.py +++ b/utils/wxPython/lib/editor/editor.py @@ -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.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.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 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