1 #----------------------------------------------------------------------
2 # Name: wxPython.lib.editor.wxEditor
3 # Purpose: An intelligent text editor with colorization capabilities.
6 # Authors: Dirk Holtwic, Robin Dunn
9 # Authors: Adam Feuer, Steve Howell
12 # This code used to support a fairly complex subclass that did
13 # syntax coloring and outliner collapse mode. Adam and Steve
14 # inherited the code, and added a lot of basic editor
15 # functionality that had not been there before, such as cut-and-paste.
18 # Created: 15-Dec-1999
20 # Copyright: (c) 1999 by Dirk Holtwick, 1999
21 # Licence: wxWindows license
22 #----------------------------------------------------------------------
26 from wxPython
.wx
import *
31 #----------------------------
33 def ForceBetween(min, val
, max):
41 def LineTrimmer(lineOfText
):
42 if len(lineOfText
) == 0:
44 elif lineOfText
[-1] == '\r':
45 return lineOfText
[:-1]
49 def LineSplitter(text
):
50 return map (LineTrimmer
, text
.split('\n'))
53 #----------------------------
56 def __init__(self
, parent
):
63 def SetScrollbars(self
, fw
, fh
, w
, h
, x
, y
):
64 if (self
.ow
!= w
or self
.oh
!= h
or self
.ox
!= x
or self
.oy
!= y
):
65 self
.parent
.SetScrollbars(fw
, fh
, w
, h
, x
, y
)
71 #----------------------------------------------------------------------
73 class wxEditor(wxScrolledWindow
):
75 def __init__(self
, parent
, id,
76 pos
=wxDefaultPosition
, size
=wxDefaultSize
, style
=0):
78 wxScrolledWindow
.__init
__(self
, parent
, id,
87 self
.InitDoubleBuffering()
94 ##------------------ Init stuff
109 EVT_LEFT_DOWN(self
, self
.OnLeftDown
)
110 EVT_LEFT_UP(self
, self
.OnLeftUp
)
111 EVT_MOTION(self
, self
.OnMotion
)
112 EVT_SCROLLWIN(self
, self
.OnScroll
)
113 EVT_CHAR(self
, self
.OnChar
)
114 EVT_PAINT(self
, self
.OnPaint
)
115 EVT_SIZE(self
, self
.OnSize
)
116 EVT_WINDOW_DESTROY(self
, self
.OnDestroy
)
117 EVT_ERASE_BACKGROUND(self
, self
.OnEraseBackground
)
119 ##------------------- Platform-specific stuff
121 def NiceFontForPlatform(self
):
122 if wxPlatform
== "__WXMSW__":
123 return wxFont(10, wxMODERN
, wxNORMAL
, wxNORMAL
)
125 return wxFont(12, wxMODERN
, wxNORMAL
, wxNORMAL
, False)
127 def UnixKeyHack(self
, key
):
128 # this will be obsolete when we get the new wxWindows patch
133 ##-------------------- UpdateView/Cursor code
135 def OnSize(self
, event
):
136 self
.AdjustScrollbars()
139 def SetCharDimensions(self
):
140 # TODO: We need a code review on this. It appears that Linux
141 # improperly reports window dimensions when the scrollbar's there.
142 self
.bw
, self
.bh
= self
.GetClientSizeTuple()
144 if wxPlatform
== "__WXMSW__":
145 self
.sh
= self
.bh
/ self
.fh
146 self
.sw
= (self
.bw
/ self
.fw
) - 1
148 self
.sh
= self
.bh
/ self
.fh
149 if self
.LinesInFile() >= self
.sh
:
150 self
.bw
= self
.bw
- wxSystemSettings_GetSystemMetric(wxSYS_VSCROLL_X
)
151 self
.sw
= (self
.bw
/ self
.fw
) - 1
153 self
.sw
= (self
.bw
/ self
.fw
) - 1
154 if self
.CalcMaxLineLen() >= self
.sw
:
155 self
.bh
= self
.bh
- wxSystemSettings_GetSystemMetric(wxSYS_HSCROLL_Y
)
156 self
.sh
= self
.bh
/ self
.fh
159 def UpdateView(self
, dc
= None):
161 dc
= wxClientDC(self
)
163 self
.SetCharDimensions()
164 self
.KeepCursorOnScreen()
165 self
.DrawSimpleCursor(0,0,dc
, True)
168 def OnPaint(self
, event
):
171 self
.AdjustScrollbars()
173 def OnEraseBackground(self
, evt
):
176 ##-------------------- Drawing code
179 dc
= wxClientDC(self
)
180 self
.font
= self
.NiceFontForPlatform()
181 dc
.SetFont(self
.font
)
182 self
.fw
= dc
.GetCharWidth()
183 self
.fh
= dc
.GetCharHeight()
186 self
.fgColor
= wxNamedColour('black')
187 self
.bgColor
= wxNamedColour('white')
188 self
.selectColor
= wxColour(238, 220, 120) # r, g, b = emacsOrange
190 def InitDoubleBuffering(self
):
193 def DrawEditText(self
, t
, x
, y
, dc
):
194 dc
.DrawText(t
, x
* self
.fw
, y
* self
.fh
)
196 def DrawLine(self
, line
, dc
):
197 if self
.IsLine(line
):
200 dc
.SetTextForeground(self
.fgColor
)
201 fragments
= selection
.Selection(
202 self
.SelectBegin
, self
.SelectEnd
,
203 self
.sx
, self
.sw
, line
, t
)
205 for (data
, selected
) in fragments
:
207 dc
.SetTextBackground(self
.selectColor
)
208 if x
== 0 and len(data
) == 0 and len(fragments
) == 1:
211 dc
.SetTextBackground(self
.bgColor
)
212 self
.DrawEditText(data
, x
, line
- self
.sy
, dc
)
215 def Draw(self
, odc
=None):
217 odc
= wxClientDC(self
)
219 bmp
= wxEmptyBitmap(max(1,self
.bw
), max(1,self
.bh
))
220 dc
= wxBufferedDC(odc
, bmp
)
222 dc
.SetFont(self
.font
)
223 dc
.SetBackgroundMode(wxSOLID
)
224 dc
.SetTextBackground(self
.bgColor
)
225 dc
.SetTextForeground(self
.fgColor
)
227 for line
in range(self
.sy
, self
.sy
+ self
.sh
):
228 self
.DrawLine(line
, dc
)
229 if len(self
.lines
) < self
.sh
+ self
.sy
:
230 self
.DrawEofMarker(dc
)
233 ##------------------ eofMarker stuff
235 def LoadImages(self
):
236 self
.eofMarker
= images
.GetBitmap(images
.EofImageData
)
238 def DrawEofMarker(self
,dc
):
240 y
= (len(self
.lines
) - self
.sy
) * self
.fh
242 dc
.DrawBitmap(self
.eofMarker
, x
, y
, hasTransparency
)
244 ##------------------ cursor-related functions
246 def DrawCursor(self
, dc
= None):
248 dc
= wxClientDC(self
)
250 if (self
.LinesInFile())<self
.cy
: #-1 ?
251 self
.cy
= self
.LinesInFile()-1
252 s
= self
.lines
[self
.cy
]
254 x
= self
.cx
- self
.sx
255 y
= self
.cy
- self
.sy
256 self
.DrawSimpleCursor(x
, y
, dc
)
259 def DrawSimpleCursor(self
, xp
, yp
, dc
= None, old
=False):
261 dc
= wxClientDC(self
)
271 dc
.Blit(x
,y
,szx
,szy
,dc
,x
,y
,wxSRC_INVERT
)
275 ##-------- Enforcing screen boundaries, cursor movement
277 def CalcMaxLineLen(self
):
278 """get length of longest line on screen"""
280 for line
in self
.lines
[self
.sy
:self
.sy
+self
.sh
]:
281 if len(line
) >maxlen
:
285 def KeepCursorOnScreen(self
):
286 self
.sy
= ForceBetween(max(0, self
.cy
-self
.sh
), self
.sy
, self
.cy
)
287 self
.sx
= ForceBetween(max(0, self
.cx
-self
.sw
), self
.sx
, self
.cx
)
288 self
.AdjustScrollbars()
290 def HorizBoundaries(self
):
291 self
.SetCharDimensions()
292 maxLineLen
= self
.CalcMaxLineLen()
293 self
.sx
= ForceBetween(0, self
.sx
, max(self
.sw
, maxLineLen
- self
.sw
+ 1))
294 self
.cx
= ForceBetween(self
.sx
, self
.cx
, self
.sx
+ self
.sw
- 1)
296 def VertBoundaries(self
):
297 self
.SetCharDimensions()
298 self
.sy
= ForceBetween(0, self
.sy
, max(self
.sh
, self
.LinesInFile() - self
.sh
+ 1))
299 self
.cy
= ForceBetween(self
.sy
, self
.cy
, self
.sy
+ self
.sh
- 1)
301 def cVert(self
, num
):
302 self
.cy
= self
.cy
+ num
303 self
.cy
= ForceBetween(0, self
.cy
, self
.LinesInFile() - 1)
304 self
.sy
= ForceBetween(self
.cy
- self
.sh
+ 1, self
.sy
, self
.cy
)
305 self
.cx
= min(self
.cx
, self
.CurrentLineLength())
307 def cHoriz(self
, num
):
308 self
.cx
= self
.cx
+ num
309 self
.cx
= ForceBetween(0, self
.cx
, self
.CurrentLineLength())
310 self
.sx
= ForceBetween(self
.cx
- self
.sw
+ 1, self
.sx
, self
.cx
)
312 def AboveScreen(self
, row
):
315 def BelowScreen(self
, row
):
316 return row
>= self
.sy
+ self
.sh
318 def LeftOfScreen(self
, col
):
321 def RightOfScreen(self
, col
):
322 return col
>= self
.sx
+ self
.sw
324 ##----------------- data structure helper functions
329 def SetText(self
, lines
):
334 self
.AdjustScrollbars()
335 self
.UpdateView(None)
337 def IsLine(self
, lineNum
):
338 return (0<=lineNum
) and (lineNum
<self
.LinesInFile())
340 def GetTextLine(self
, lineNum
):
341 if self
.IsLine(lineNum
):
342 return self
.lines
[lineNum
]
345 def SetTextLine(self
, lineNum
, text
):
346 if self
.IsLine(lineNum
):
347 self
.lines
[lineNum
] = text
349 def CurrentLineLength(self
):
350 return len(self
.lines
[self
.cy
])
352 def LinesInFile(self
):
353 return len(self
.lines
)
355 def UnTouchBuffer(self
):
356 self
.bufferTouched
= False
358 def BufferWasTouched(self
):
359 return self
.bufferTouched
361 def TouchBuffer(self
):
362 self
.bufferTouched
= True
365 ##-------------------------- Mouse scroll timing functions
367 def InitScrolling(self
):
368 # we don't rely on the windows system to scroll for us; we just
369 # redraw the screen manually every time
370 self
.EnableScrolling(False, False)
371 self
.nextScrollTime
= 0
372 self
.SCROLLDELAY
= 0.050 # seconds
373 self
.scrollTimer
= wxTimer(self
)
374 self
.scroller
= Scroller(self
)
377 if time
.time() > self
.nextScrollTime
:
378 self
.nextScrollTime
= time
.time() + self
.SCROLLDELAY
383 def SetScrollTimer(self
):
385 self
.scrollTimer
.Start(1000*self
.SCROLLDELAY
/2, oneShot
)
386 EVT_TIMER(self
, -1, self
.OnTimer
)
388 def OnTimer(self
, event
):
389 screenX
, screenY
= wxGetMousePosition()
390 x
, y
= self
.ScreenToClientXY(screenX
, screenY
)
395 ##-------------------------- Mouse off screen functions
397 def HandleAboveScreen(self
, row
):
398 self
.SetScrollTimer()
404 def HandleBelowScreen(self
, row
):
405 self
.SetScrollTimer()
407 row
= self
.sy
+ self
.sh
408 row
= min(row
, self
.LinesInFile() - 1)
411 def HandleLeftOfScreen(self
, col
):
412 self
.SetScrollTimer()
418 def HandleRightOfScreen(self
, col
):
419 self
.SetScrollTimer()
421 col
= self
.sx
+ self
.sw
422 col
= min(col
, self
.CurrentLineLength())
425 ##------------------------ mousing functions
427 def MouseToRow(self
, mouseY
):
428 row
= self
.sy
+ (mouseY
/ self
.fh
)
429 if self
.AboveScreen(row
):
430 self
.HandleAboveScreen(row
)
431 elif self
.BelowScreen(row
):
432 self
.HandleBelowScreen(row
)
434 self
.cy
= min(row
, self
.LinesInFile() - 1)
436 def MouseToCol(self
, mouseX
):
437 col
= self
.sx
+ (mouseX
/ self
.fw
)
438 if self
.LeftOfScreen(col
):
439 self
.HandleLeftOfScreen(col
)
440 elif self
.RightOfScreen(col
):
441 self
.HandleRightOfScreen(col
)
443 self
.cx
= min(col
, self
.CurrentLineLength())
445 def MouseToCursor(self
, event
):
446 self
.MouseToRow(event
.GetY())
447 self
.MouseToCol(event
.GetX())
449 def OnMotion(self
, event
):
450 if event
.LeftIsDown() and self
.HasCapture():
451 self
.Selecting
= True
452 self
.MouseToCursor(event
)
455 def OnLeftDown(self
, event
):
456 self
.MouseToCursor(event
)
457 self
.SelectBegin
= (self
.cy
, self
.cx
)
458 self
.SelectEnd
= None
462 def OnLeftUp(self
, event
):
463 if not self
.HasCapture():
466 if self
.SelectEnd
is None:
469 self
.Selecting
= False
470 self
.SelectNotify(False, self
.SelectBegin
, self
.SelectEnd
)
473 self
.scrollTimer
.Stop()
476 #------------------------- Scrolling
478 def HorizScroll(self
, event
, eventType
):
479 maxLineLen
= self
.CalcMaxLineLen()
481 if eventType
== wxEVT_SCROLLWIN_LINEUP
:
483 elif eventType
== wxEVT_SCROLLWIN_LINEDOWN
:
485 elif eventType
== wxEVT_SCROLLWIN_PAGEUP
:
487 elif eventType
== wxEVT_SCROLLWIN_PAGEDOWN
:
489 elif eventType
== wxEVT_SCROLLWIN_TOP
:
490 self
.sx
= self
.cx
= 0
491 elif eventType
== wxEVT_SCROLLWIN_BOTTOM
:
492 self
.sx
= maxLineLen
- self
.sw
495 self
.sx
= event
.GetPosition()
497 self
.HorizBoundaries()
499 def VertScroll(self
, event
, eventType
):
500 if eventType
== wxEVT_SCROLLWIN_LINEUP
:
502 elif eventType
== wxEVT_SCROLLWIN_LINEDOWN
:
504 elif eventType
== wxEVT_SCROLLWIN_PAGEUP
:
506 elif eventType
== wxEVT_SCROLLWIN_PAGEDOWN
:
508 elif eventType
== wxEVT_SCROLLWIN_TOP
:
509 self
.sy
= self
.cy
= 0
510 elif eventType
== wxEVT_SCROLLWIN_BOTTOM
:
511 self
.sy
= self
.LinesInFile() - self
.sh
512 self
.cy
= self
.LinesInFile()
514 self
.sy
= event
.GetPosition()
516 self
.VertBoundaries()
518 def OnScroll(self
, event
):
519 dir = event
.GetOrientation()
520 eventType
= event
.GetEventType()
521 if dir == wxHORIZONTAL
:
522 self
.HorizScroll(event
, eventType
)
524 self
.VertScroll(event
, eventType
)
528 def AdjustScrollbars(self
):
530 self
.SetCharDimensions()
531 self
.scroller
.SetScrollbars(
533 self
.CalcMaxLineLen()+3, max(self
.LinesInFile()+1, self
.sh
),
536 #------------ backspace, delete, return
538 def BreakLine(self
, event
):
539 if self
.IsLine(self
.cy
):
540 t
= self
.lines
[self
.cy
]
541 self
.lines
= self
.lines
[:self
.cy
] + [t
[:self
.cx
],t
[self
.cx
:]] + self
.lines
[self
.cy
+1:]
546 def InsertChar(self
,char
):
547 if self
.IsLine(self
.cy
):
548 t
= self
.lines
[self
.cy
]
549 t
= t
[:self
.cx
] + char
+ t
[self
.cx
:]
550 self
.SetTextLine(self
.cy
, t
)
555 t1
= self
.lines
[self
.cy
]
556 t2
= self
.lines
[self
.cy
+1]
558 self
.lines
= self
.lines
[:self
.cy
] + [t1
+ t2
] + self
.lines
[self
.cy
+2:]
562 def DeleteChar(self
,x
,y
,oldtext
):
563 newtext
= oldtext
[:x
] + oldtext
[x
+1:]
564 self
.SetTextLine(y
, newtext
)
568 def BackSpace(self
, event
):
569 t
= self
.GetTextLine(self
.cy
)
571 self
.DeleteChar(self
.cx
-1,self
.cy
,t
)
582 def Delete(self
, event
):
583 t
= self
.GetTextLine(self
.cy
)
585 self
.DeleteChar(self
.cx
,self
.cy
,t
)
588 if self
.cy
< len(self
.lines
) - 1:
592 def Escape(self
, event
):
595 def TabKey(self
, event
):
596 numSpaces
= self
.SpacesPerTab
- (self
.cx
% self
.SpacesPerTab
)
597 self
.SingleLineInsert(' ' * numSpaces
)
599 ##----------- selection routines
601 def SelectUpdate(self
):
602 self
.SelectEnd
= (self
.cy
, self
.cx
)
603 self
.SelectNotify(self
.Selecting
, self
.SelectBegin
, self
.SelectEnd
)
606 def NormalizedSelect(self
):
607 (begin
, end
) = (self
.SelectBegin
, self
.SelectEnd
)
620 def FindSelection(self
):
621 if self
.SelectEnd
is None or self
.SelectBegin
is None:
624 (begin
, end
) = self
.NormalizedSelect()
627 return (bRow
, bCol
, eRow
, eCol
)
630 self
.SelectBegin
= None
631 self
.SelectEnd
= None
632 self
.Selecting
= False
633 self
.SelectNotify(False,None,None)
635 def CopySelection(self
, event
):
636 selection
= self
.FindSelection()
637 if selection
is None:
639 (bRow
, bCol
, eRow
, eCol
) = selection
642 self
.SingleLineCopy(bRow
, bCol
, eCol
)
644 self
.MultipleLineCopy(bRow
, bCol
, eRow
, eCol
)
646 def OnCopySelection(self
, event
):
647 self
.CopySelection(event
)
650 def CopyToClipboard(self
, linesOfText
):
651 do
= wxTextDataObject()
652 do
.SetText(os
.linesep
.join(linesOfText
))
653 wxTheClipboard
.Open()
654 wxTheClipboard
.SetData(do
)
655 wxTheClipboard
.Close()
657 def SingleLineCopy(self
, Row
, bCol
, eCol
):
658 Line
= self
.GetTextLine(Row
)
659 self
.CopyToClipboard([Line
[bCol
:eCol
]])
661 def MultipleLineCopy(self
, bRow
, bCol
, eRow
, eCol
):
662 bLine
= self
.GetTextLine(bRow
)[bCol
:]
663 eLine
= self
.GetTextLine(eRow
)[:eCol
]
664 self
.CopyToClipboard([bLine
] + [l
for l
in self
.lines
[bRow
+ 1:eRow
]] + [eLine
])
666 def OnDeleteSelection(self
, event
):
667 selection
= self
.FindSelection()
668 if selection
is None:
670 (bRow
, bCol
, eRow
, eCol
) = selection
673 self
.SingleLineDelete(bRow
, bCol
, eCol
)
675 self
.MultipleLineDelete(bRow
, bCol
, eRow
, eCol
)
685 def SingleLineDelete(self
, Row
, bCol
, eCol
):
686 ModLine
= self
.GetTextLine(Row
)
687 ModLine
= ModLine
[:bCol
] + ModLine
[eCol
:]
688 self
.SetTextLine(Row
,ModLine
)
690 def MultipleLineDelete(self
, bRow
, bCol
, eRow
, eCol
):
691 bLine
= self
.GetTextLine(bRow
)
692 eLine
= self
.GetTextLine(eRow
)
693 ModLine
= bLine
[:bCol
] + eLine
[eCol
:]
694 self
.lines
[bRow
:eRow
+ 1] = [ModLine
]
696 def OnPaste(self
, event
):
697 do
= wxTextDataObject()
698 wxTheClipboard
.Open()
699 success
= wxTheClipboard
.GetData(do
)
700 wxTheClipboard
.Close()
702 pastedLines
= LineSplitter(do
.GetText())
706 if len(pastedLines
) == 0:
709 elif len(pastedLines
) == 1:
710 self
.SingleLineInsert(pastedLines
[0])
712 self
.MultipleLinePaste(pastedLines
)
714 def SingleLineInsert(self
, newText
):
715 ModLine
= self
.GetTextLine(self
.cy
)
716 ModLine
= ModLine
[:self
.cx
] + newText
+ ModLine
[self
.cx
:]
717 self
.SetTextLine(self
.cy
, ModLine
)
718 self
.cHoriz(len(newText
))
722 def MultipleLinePaste(self
, pastedLines
):
723 FirstLine
= LastLine
= self
.GetTextLine(self
.cy
)
724 FirstLine
= FirstLine
[:self
.cx
] + pastedLines
[0]
725 LastLine
= pastedLines
[-1] + LastLine
[self
.cx
:]
727 NewSlice
= [FirstLine
]
728 NewSlice
+= [l
for l
in pastedLines
[1:-1]]
729 NewSlice
+= [LastLine
]
730 self
.lines
[self
.cy
:self
.cy
+ 1] = NewSlice
732 self
.cy
= self
.cy
+ len(pastedLines
)-1
733 self
.cx
= len(pastedLines
[-1])
737 def OnCutSelection(self
,event
):
738 self
.CopySelection(event
)
739 self
.OnDeleteSelection(event
)
741 #-------------- Keyboard movement implementations
743 def MoveDown(self
, event
):
746 def MoveUp(self
, event
):
749 def MoveLeft(self
, event
):
755 self
.cx
= self
.CurrentLineLength()
759 def MoveRight(self
, event
):
760 linelen
= self
.CurrentLineLength()
761 if self
.cx
== linelen
:
762 if self
.cy
== len(self
.lines
) - 1:
771 def MovePageDown(self
, event
):
774 def MovePageUp(self
, event
):
777 def MoveHome(self
, event
):
780 def MoveEnd(self
, event
):
781 self
.cx
= self
.CurrentLineLength()
783 def MoveStartOfFile(self
, event
):
787 def MoveEndOfFile(self
, event
):
788 self
.cy
= len(self
.lines
) - 1
789 self
.cx
= self
.CurrentLineLength()
791 #-------------- Key handler mapping tables
793 def SetMoveSpecialFuncs(self
, action
):
794 action
[WXK_DOWN
] = self
.MoveDown
795 action
[WXK_UP
] = self
.MoveUp
796 action
[WXK_LEFT
] = self
.MoveLeft
797 action
[WXK_RIGHT
] = self
.MoveRight
798 action
[WXK_NEXT
] = self
.MovePageDown
799 action
[WXK_PRIOR
] = self
.MovePageUp
800 action
[WXK_HOME
] = self
.MoveHome
801 action
[WXK_END
] = self
.MoveEnd
803 def SetMoveSpecialControlFuncs(self
, action
):
804 action
[WXK_HOME
] = self
.MoveStartOfFile
805 action
[WXK_END
] = self
.MoveEndOfFile
807 def SetAltFuncs(self
, action
):
808 # subclass implements
811 def SetControlFuncs(self
, action
):
812 action
['c'] = self
.OnCopySelection
813 action
['d'] = self
.OnDeleteSelection
814 action
['v'] = self
.OnPaste
815 action
['x'] = self
.OnCutSelection
817 def SetSpecialControlFuncs(self
, action
):
818 action
[WXK_INSERT
] = self
.OnCopySelection
820 def SetShiftFuncs(self
, action
):
821 action
[WXK_DELETE
] = self
.OnCutSelection
822 action
[WXK_INSERT
] = self
.OnPaste
824 def SetSpecialFuncs(self
, action
):
825 action
[WXK_BACK
] = self
.BackSpace
826 action
[WXK_DELETE
] = self
.Delete
827 action
[WXK_RETURN
] = self
.BreakLine
828 action
[WXK_ESCAPE
] = self
.Escape
829 action
[WXK_TAB
] = self
.TabKey
831 ##-------------- Logic for key handlers
834 def Move(self
, keySettingFunction
, key
, event
):
836 keySettingFunction(action
)
838 if not action
.has_key(key
):
841 if event
.ShiftDown():
842 if not self
.Selecting
:
843 self
.Selecting
= True
844 self
.SelectBegin
= (self
.cy
, self
.cx
)
846 self
.SelectEnd
= (self
.cy
, self
.cx
)
850 self
.Selecting
= False
852 self
.SelectNotify(self
.Selecting
, self
.SelectBegin
, self
.SelectEnd
)
856 def MoveSpecialKey(self
, event
, key
):
857 return self
.Move(self
.SetMoveSpecialFuncs
, key
, event
)
859 def MoveSpecialControlKey(self
, event
, key
):
860 if not event
.ControlDown():
862 return self
.Move(self
.SetMoveSpecialControlFuncs
, key
, event
)
864 def Dispatch(self
, keySettingFunction
, key
, event
):
866 keySettingFunction(action
)
867 if action
.has_key(key
):
873 def ModifierKey(self
, key
, event
, modifierKeyDown
, MappingFunc
):
874 if not modifierKeyDown
:
877 key
= self
.UnixKeyHack(key
)
882 if not self
.Dispatch(MappingFunc
, key
, event
):
886 def ControlKey(self
, event
, key
):
887 return self
.ModifierKey(key
, event
, event
.ControlDown(), self
.SetControlFuncs
)
889 def AltKey(self
, event
, key
):
890 return self
.ModifierKey(key
, event
, event
.AltDown(), self
.SetAltFuncs
)
892 def SpecialControlKey(self
, event
, key
):
893 if not event
.ControlDown():
895 if not self
.Dispatch(self
.SetSpecialControlFuncs
, key
, event
):
899 def ShiftKey(self
, event
, key
):
900 if not event
.ShiftDown():
902 return self
.Dispatch(self
.SetShiftFuncs
, key
, event
)
904 def NormalChar(self
, event
, key
):
908 if not self
.Dispatch(self
.SetSpecialFuncs
, key
, event
):
909 if (key
>31) and (key
<256):
910 self
.InsertChar(chr(key
))
915 self
.AdjustScrollbars()
917 def OnChar(self
, event
):
918 key
= event
.KeyCode()
919 filters
= [self
.AltKey
,
920 self
.MoveSpecialControlKey
,
922 self
.SpecialControlKey
,
926 for filter in filters
:
927 if filter(event
,key
):
931 #----------------------- Eliminate memory leaks
933 def OnDestroy(self
, event
):
939 self
.selectColor
= None
940 self
.scrollTimer
= None
941 self
.eofMarker
= None
943 #-------------------- Abstract methods for subclasses
948 def SelectNotify(self
, Selecting
, SelectionBegin
, SelectionEnd
):