]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/lib/editor/editor.py
it is now possible to add custom buttons into wxHtmlHelpFrame's toolbar
[wxWidgets.git] / utils / wxPython / lib / editor / editor.py
CommitLineData
1b55cabf
RD
1#----------------------------------------------------------------------
2# Name: wxPython.lib.editor.wxEditor
3# Purpose: An intelligent text editor with colorization capabilities.
4#
5# Author: Dirk Holtwic, Robin Dunn
6#
7# Created: 15-Dec-1999
8# RCS-ID: $Id$
9# Copyright: (c) 1999 by Dirk Holtwick, 1999
10# Licence: wxWindows license
11#----------------------------------------------------------------------
12
f0b0b7d4
RD
13
14# PLEASE NOTE: This is experimental code. It needs an overhall in the
15# drawing and update code, and there is occasionally a
16# mysteriously disappearing line...
17#
18# I am working on a StyledTextEditor that will likely
19# render this editor obsolete... But this one is at
20# least somewhat functional now while the other is still
21# vapor.
22#
23# - Robin
24
25
1b55cabf
RD
26from wxPython.wx import *
27from string import *
28from keyword import *
29from regsub import *
30from tokenizer import *
31
32#---------------------------------------------------------------------------
33
1b55cabf
RD
34
35class Line:
36 def __init__(self, text=""):
37 self.text = text # the string itself
38 self.syntax = [] # the colors of the line
39 self.editable = true # edit?
40 self.visible = 0 # will be incremented if not
41 self.indent = 0 # not used yet
42
43#----------------------------------------------------------------------
44
45class wxEditor(wxScrolledWindow):
46
f2a497dc
RD
47 def __init__(self, parent, id,
48 pos=wxDefaultPosition, size=wxDefaultSize, style=0):
1b55cabf
RD
49 ###############################################################
50 """
51 Alles hat einen Anfang
52 """
53
54 wxScrolledWindow.__init__(self, parent, id,
f2a497dc
RD
55 pos, size,
56 style|wxWANTS_CHARS)
1b55cabf
RD
57
58 # the syntax informations, if they don't exist,
59 # all syntax stuff will be ignored
60
61 # cursor pos
62 self.cx = 0
63 self.cy = 0
64
65 # the lines that are visible
66 self.lines = []
67 self.line = 0
68 self.len = 0
69
70 self.ocy = 0
71
72 # border pos
73 #self.bx = 0
74 #self.by = 0
75
76 # screen
77 self.sx = 0
78 self.sy = 0
79 self.sw = 0
80 self.sh = 0
f0b0b7d4
RD
81 self.osx= 0
82 self.osy= 0
1b55cabf
RD
83
84 # font
85 dc = wxClientDC(self)
86
f0b0b7d4
RD
87 if wxPlatform == "__WXMSW__":
88 self.font = wxFont(10, wxMODERN, wxNORMAL, wxNORMAL)
89 else:
90 self.font = wxFont(12, wxMODERN, wxNORMAL, wxNORMAL, false)
1b55cabf
RD
91 dc.SetFont(self.font)
92
93 # font weight, height
94 self.fw = dc.GetCharWidth()
95 self.fh = dc.GetCharHeight()
96
97 # back, for colour
98 self.bcol = wxNamedColour('white')
99 self.fcol = wxNamedColour('black')
100
101 self.cfcol = wxNamedColour('black')
102 self.cbcol = wxNamedColour('red')
103
104 # nicht edierbare zeile (hintergrund)
105 self.nedcol = wxNamedColour('grey')
106
107 self.SetBackgroundColour(self.bcol)
108 #dc.SetForegroundColour(self.fcol)
109
110 # events
111 EVT_LEFT_DOWN(self, self.OnMouseClick)
112 EVT_RIGHT_DOWN(self, self.OnMouseClick)
113 EVT_SCROLLWIN(self, self.OnScroll)
114
115 self.o_cx = self.cx
116 self.o_cy = self.cy
117 self.o_sx = self.sx
118 self.o_sy = self.sy
119 self.o_line = self.line
120 self.sco_x = 0
121 self.sco_y = 0
122
123 self.tabsize = 4
124
125 self.update = true
126 self.in_scroll =FALSE
f0b0b7d4
RD
127 self.inUpdate = FALSE
128
1b55cabf
RD
129
130 bw,bh = self.GetSizeTuple()
131 # double buffering
132 self.mdc = wxMemoryDC()
133 self.mdc.SelectObject(wxEmptyBitmap(bw,bh))
134 # disable physical scrolling because invisible parts are not drawn
135 self.EnableScrolling(FALSE, FALSE)
136
137 # the ordinary text as it is
138 self.SetText()
139 self.SetFocus()
140
141
142#---------------------------------------------------------------------------
143
144 def CalcLines(self):
145 ###############################################################
146 self.lines = []
147 x =maxlen =0
148 for line in self.text:
149 if line.visible==0:
150 self.lines.append(x)
151 else:
152 if len(line.text) >maxlen:
153 maxlen =len(line.text)
154 x = x + 1
155 self.len = len(self.lines)
156 self.max_linelength =maxlen
157
f0b0b7d4 158
1b55cabf
RD
159 def SetFontTab(self, fonttab):
160 ###############################################################
161 """ Fonttabelle zum schnellen Zugriff """
162 self.ftab = fonttab
163
f0b0b7d4 164
1b55cabf
RD
165 def SetText(self, text = [""]):
166 ###############################################################
167 """ Text mittels Liste setzen """
168 self.cx = 0
169 self.cy = 0
170 self.text = []
171
172 for t in text:
173 self.text.append(Line(t))
174
175 for l in range(0,len(text)-1):
176 #self.UpdateSyntax(l)
177 self.OnUpdateHighlight(l)
178
179 self.OnInit()
180
181 self.update = true
182 self.UpdateView(None, true)
183
f0b0b7d4 184
1b55cabf
RD
185 # show new text
186 def GetText(self):
187 ###############################################################
188 """ Der gesamte Text als Liste """
189 text = []
190 for line in self.text:
191 text.append(line.text)
192 return text
193
f0b0b7d4 194
1b55cabf
RD
195 def IsEmpty(self):
196 ###############################################################
197 """see if at least one text line is not empty"""
198 for line in self.text:
199 if line.text: return 0
200 return 1
201
f0b0b7d4 202
1b55cabf
RD
203 def IsLine(self, line):
204 ###############################################################
205