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 *
32 #----------------------------
34 def ForceBetween(min, val
, max):
42 def LineTrimmer(lineOfText
):
43 if len(lineOfText
) == 0:
45 elif lineOfText
[-1] == '\r':
46 return lineOfText
[:-1]
50 def LineSplitter(text
):
51 return map (LineTrimmer
, text
.split('\n'))
54 #----------------------------
57 def __init__(self
, parent
):
64 def SetScrollbars(self
, fw
, fh
, w
, h
, x
, y
):
65 if (self
.ow
!= w
or self
.oh
!= h
or self
.ox
!= x
or self
.oy
!= y
):
66 self
.parent
.SetScrollbars(fw
, fh
, w
, h
, x
, y
)
72 #----------------------------------------------------------------------
74 class wxEditor(wxScrolledWindow
):
76 def __init__(self
, parent
, id,
77 pos
=wxDefaultPosition
, size
=wxDefaultSize
, style
=0):
79 wxScrolledWindow
.__init
__(self
, parent
, id,
88 self
.InitDoubleBuffering()
95 ##------------------ Init stuff
110 EVT_LEFT_DOWN(self
, self
.OnLeftDown
)
111 EVT_LEFT_UP(self
, self
.OnLeftUp
)
112 EVT_MOTION(self
, self
.OnMotion
)
113 EVT_SCROLLWIN(self
, self
.OnScroll
)
114 EVT_CHAR(self
, self
.OnChar
)
115 EVT_PAINT(self
, self
.OnPaint
)
116 EVT_SIZE(self
, self
.OnSize
)
117 EVT_WINDOW_DESTROY(self
, self
.OnDestroy
)
118 EVT_ERASE_BACKGROUND(self
, self
.OnEraseBackground
)
120 ##------------------- Platform-specific stuff
122 def NiceFontForPlatform(self
):
123 if wxPlatform
== "__WXMSW__":
124 return wxFont(10, wxMODERN
, wxNORMAL
, wxNORMAL
)
126 return wxFont(12, wxMODERN
, wxNORMAL
, wxNORMAL
, false
)
128 def UnixKeyHack(self
, key
):
129 # this will be obsolete when we get the new wxWindows patch
134 ##-------------------- UpdateView/Cursor code
136 def OnSize(self
, event
):
137 self
.AdjustScrollbars()
140 def SetCharDimensions(self
):
141 # TODO: We need a code review on this. It appears that Linux
142 # improperly reports window dimensions when the scrollbar's there.
143 self
.bw
, self
.bh
= self
.GetClientSizeTuple()
145 if wxPlatform
== "__WXMSW__":
146 self
.sh
= self
.bh
/ self
.fh
147 self
.sw
= (self
.bw
/ self
.fw
) - 1
149 self
.sh
= self
.bh
/ self
.fh
150 if self
.LinesInFile() >= self
.sh
:
151 self
.bw
= self
.bw
- wxSystemSettings_GetSystemMetric(wxSYS_VSCROLL_X
)
152 self
.sw
= (self
.bw
/ self
.fw
) - 1
154 self
.sw
= (self
.bw
/ self
.fw
) - 1
155 if self
.CalcMaxLineLen() >= self
.sw
:
156 self
.bh
= self
.bh
- wxSystemSettings_GetSystemMetric(wxSYS_HSCROLL_Y
)
157 self
.sh
= self
.bh
/ self
.fh
160 def UpdateView(self
, dc
= None):
162 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
):
191 bw
,bh
= self
.GetClientSizeTuple()
192 self
.mdc
= wxMemoryDC()
193 self
.mdc
.SelectObject(wxEmptyBitmap(bw
,bh
))
195 def DrawEditText(self
, t
, x
, y
, dc
):
196 dc
.DrawText(t
, x
* self
.fw
, y
* self
.fh
)
198 def DrawLine(self
, line
, dc
):
199 if self
.IsLine(line
):
202 dc
.SetTextForeground(self
.fgColor
)
203 fragments
= selection
.Selection(
204 self
.SelectBegin
, self
.SelectEnd
,
205 self
.sx
, self
.sw
, line
, t
)
207 for (data
, selected
) in fragments
:
209 dc
.SetTextBackground(self
.selectColor
)
210 if x
== 0 and len(data
) == 0 and len(fragments
) == 1:
213 dc
.SetTextBackground(self
.bgColor
)
214 self
.DrawEditText(data
, x
, line
- self
.sy
, dc
)
217 def Draw(self
, odc
=None):
219 odc
= wxClientDC(self
)
222 dc
.SetFont(self
.font
)
223 dc
.SelectObject(wxEmptyBitmap(self
.bw
,self
.bh
))
224 dc
.SetBackgroundMode(wxSOLID
)
225 dc
.SetTextBackground(self
.bgColor
)
226 dc
.SetTextForeground(self
.fgColor
)
228 for line
in range(self
.sy
, self
.sy
+ self
.sh
):
229 self
.DrawLine(line
, dc
)
230 if len(self
.lines
) < self
.sh
+ self
.sy
:
231 self
.DrawEofMarker(dc
)
232 odc
.Blit(0,0,self
.bw
,self
.bh
,dc
,0,0,wxCOPY
)
235 ##------------------ eofMarker stuff
237 def LoadImages(self
):
238 self
.eofMarker
= images
.GetBitmap(images
.EofImageData
)
240 def DrawEofMarker(self
,dc
):
242 y
= (len(self
.lines
) - self
.sy
) * self
.fh
244 dc
.DrawBitmap(self
.eofMarker
, x
, y
, hasTransparency
)
246 ##------------------ cursor-related functions
248 def DrawCursor(self
, dc
= None):
250 dc
= wxClientDC(self
)
252 if (self
.LinesInFile())<self
.cy
: #-1 ?
253 self
.cy
= self
.LinesInFile()-1
254 s
= self
.lines
[self
.cy
]
256 x
= self
.cx
- self
.sx
257 y
= self
.cy
- self
.sy
258 self
.DrawSimpleCursor(x
, y
, dc
)
261 def DrawSimpleCursor(self
, xp
, yp
, dc
= None, old
=false
):
263 dc
= wxClientDC(self
)
273 dc
.Blit(x
,y
,szx
,szy
,dc
,x
,y
,wxSRC_INVERT
)
277 ##-------- Enforcing screen boundaries, cursor movement
279 def CalcMaxLineLen(self
):
280 """get length of longest line on screen"""
282 for line
in self
.lines
[self
.sy
:self
.sy
+self
.sh
]:
283 if len(line
) >maxlen
:
287 def KeepCursorOnScreen(self
):
288 self
.sy
= ForceBetween(max(0, self
.cy
-self
.sh
), self
.sy
, self
.cy
)
289 self
.sx
= ForceBetween(max(0, self
.cx
-self
.sw
), self
.sx
, self
.cx
)
290 self
.AdjustScrollbars()
292 def HorizBoundaries(self
):
293 self
.SetCharDimensions()
294 maxLineLen
= self
.CalcMaxLineLen()
295 self
.sx
= ForceBetween(0, self
.sx
, max(self
.sw
, maxLineLen
- self
.sw
+ 1))
296 self
.cx
= ForceBetween(self
.sx
, self
.cx
, self
.sx
+ self
.sw
- 1)
298 def VertBoundaries(self
):
299 self
.SetCharDimensions()
300 self
.sy
= ForceBetween(0, self
.sy
, max(self
.sh
, self
.LinesInFile() - self
.sh
+ 1))
301 self
.cy
= ForceBetween(self
.sy
, self
.cy
, self
.sy
+ self
.sh
- 1)
303 def cVert(self
, num
):
304 self
.cy
= self
.cy
+ num
305 self
.cy
= ForceBetween(0, self
.cy
, self
.LinesInFile() - 1)
306 self
.sy
= ForceBetween(self
.cy
- self
.sh
+ 1, self
.sy
, self
.cy
)
307 self
.cx
= min(self
.cx
, self
.CurrentLineLength())
309 def cHoriz(self
, num
):
310 self
.cx
= self
.cx
+ num
311 self
.cx
= ForceBetween(0, self
.cx
, self
.CurrentLineLength())
312 self
.sx
= ForceBetween(self
.cx
- self
.sw
+ 1, self
.sx
, self
.cx
)
314 def AboveScreen(self
, row
):
317 def BelowScreen(self
, row
):
318 return row
>= self
.sy
+ self
.sh
320 def LeftOfScreen(self
, col
):
323 def RightOfScreen(self
, col
):
324 return col
>= self
.sx
+ self
.sw
326 ##----------------- data structure helper functions
331 def SetText(self
, lines
):
336 self
.AdjustScrollbars()
337 self
.UpdateView(None)
339 def IsLine(self
, lineNum
):
340 return (0<=lineNum
) and (lineNum
<self
.LinesInFile())
342 def GetTextLine(self
, lineNum
):
343 if self
.IsLine(lineNum
):
344 return self
.lines
[lineNum
]
347 def SetTextLine(self
, lineNum
, text
):
348 if self
.IsLine(lineNum
):
349 self
.lines
[lineNum
] = text
351 def CurrentLineLength(self
):
352 return len(self
.lines
[self
.cy
])
354 def LinesInFile(self
):
355 return len(self
.lines
)
357 def UnTouchBuffer(self
):
358 self
.bufferTouched
= FALSE
360 def BufferWasTouched(self
):
361 return self
.bufferTouched
363 def TouchBuffer(self
):
364 self
.bufferTouched
= TRUE
367 ##-------------------------- Mouse scroll timing functions
369 def InitScrolling(self
):
370 # we don't rely on the windows system to scroll for us; we just
371 # redraw the screen manually every time
372 self
.EnableScrolling(FALSE
, FALSE
)
373 self
.nextScrollTime
= 0
374 self
.SCROLLDELAY
= 0.050 # seconds
375 self
.scrollTimer
= wxTimer(self
)
376 self
.scroller
= Scroller(self
)
379 if time
.time() > self
.nextScrollTime
:
380 self
.nextScrollTime
= time
.time() + self
.SCROLLDELAY
385 def SetScrollTimer(self
):
387 self
.scrollTimer
.Start(1000*self
.SCROLLDELAY
/2, oneShot
)
388 EVT_TIMER(self
, -1, self
.OnTimer
)
390 def OnTimer(self
, event
):
391 screenX
, screenY
= wxGetMousePosition()
392 x
, y
= self
.ScreenToClientXY(screenX
, screenY
)
397 ##-------------------------- Mouse off screen functions
399 def HandleAboveScreen(self
, row
):
400 self
.SetScrollTimer()
406 def HandleBelowScreen(self
, row
):
407 self
.SetScrollTimer()
409 row
= self
.sy
+ self
.sh
410 row
= min(row
, self
.LinesInFile() - 1)
413 def HandleLeftOfScreen(self
, col
):
414 self
.SetScrollTimer()
420 def HandleRightOfScreen(self
, col
):
421 self
.SetScrollTimer()
423 col
= self
.sx
+ self
.sw
424 col
= min(col
, self
.CurrentLineLength())
427 ##------------------------ mousing functions
429 def MouseToRow(self
, mouseY
):
430 row
= self
.sy
+ (mouseY
/ self
.fh
)
431 if self
.AboveScreen(row
):
432 self
.HandleAboveScreen(row
)
433 elif self
.BelowScreen(row
):
434 self
.HandleBelowScreen(row
)
436 self
.cy
= min(row
, self
.LinesInFile() - 1)
438 def MouseToCol(self
, mouseX
):
439 col
= self
.sx
+ (mouseX
/ self
.fw
)
440 if self
.LeftOfScreen(col
):
441 self
.HandleLeftOfScreen(col
)
442 elif self
.RightOfScreen(col
):
443 self
.HandleRightOfScreen(col
)
445 self
.cx
= min(col
, self
.CurrentLineLength())
447 def MouseToCursor(self
, event
):
448 self
.MouseToRow(event
.GetY())
449 self
.MouseToCol(event
.GetX())
451 def OnMotion(self
, event
):
452 if event
.LeftIsDown() and self
.HasCapture():
453 self
.Selecting
= true
454 self
.MouseToCursor(event
)
457 def OnLeftDown(self
, event
):
458 self
.MouseToCursor(event
)
459 self
.SelectBegin
= (self
.cy
, self
.cx
)
460 self
.SelectEnd
= None
464 def OnLeftUp(self
, event
):
465 if not self
.HasCapture():
468 if self
.SelectEnd
is None:
471 self
.Selecting
= false
472 self
.SelectNotify(false
, self
.SelectBegin
, self
.SelectEnd
)
475 self
.scrollTimer
.Stop()
478 #------------------------- Scrolling
480 def HorizScroll(self
, event
, eventType
):
481 maxLineLen
= self
.CalcMaxLineLen()
483 if eventType
== wxEVT_SCROLLWIN_LINEUP
:
485 elif eventType
== wxEVT_SCROLLWIN_LINEDOWN
:
487 elif eventType
== wxEVT_SCROLLWIN_PAGEUP
:
489 elif eventType
== wxEVT_SCROLLWIN_PAGEDOWN
:
491 elif eventType
== wxEVT_SCROLLWIN_TOP
:
492 self
.sx
= self
.cx
= 0
493 elif eventType
== wxEVT_SCROLLWIN_BOTTOM
:
494 self
.sx
= maxLineLen
- self
.sw
497 self
.sx
= event
.GetPosition()
499 self
.HorizBoundaries()
501 def VertScroll(self
, event
, eventType
):
502 if eventType
== wxEVT_SCROLLWIN_LINEUP
:
504 elif eventType
== wxEVT_SCROLLWIN_LINEDOWN
:
506 elif eventType
== wxEVT_SCROLLWIN_PAGEUP
:
508 elif eventType
== wxEVT_SCROLLWIN_PAGEDOWN
:
510 elif eventType
== wxEVT_SCROLLWIN_TOP
:
511 self
.sy
= self
.cy
= 0
512 elif eventType
== wxEVT_SCROLLWIN_BOTTOM
:
513 self
.sy
= self
.LinesInFile() - self
.sh
514 self
.cy
= self
.LinesInFile()
516 self
.sy
= event
.GetPosition()
518 self
.VertBoundaries()
520 def OnScroll(self
, event
):
521 dir = event
.GetOrientation()
522 eventType
= event
.GetEventType()
523 if dir == wxHORIZONTAL
:
524 self
.HorizScroll(event
, eventType
)
526 self
.VertScroll(event
, eventType
)
530 def AdjustScrollbars(self
):
532 self
.SetCharDimensions()
533 self
.scroller
.SetScrollbars(
535 self
.CalcMaxLineLen()+3, max(self
.LinesInFile()+1, self
.sh
),
538 #------------ backspace, delete, return
540 def BreakLine(self
, event
):
541 if self
.IsLine(self
.cy
):
542 t
= self
.lines
[self
.cy
]
543 self
.lines
= self
.lines
[:self
.cy
] + [t
[:self
.cx
],t
[self
.cx
:]] + self
.lines
[self
.cy
+1:]
548 def InsertChar(self
,char
):
549 if self
.IsLine(self
.cy
):
550 t
= self
.lines
[self
.cy
]
551 t
= t
[:self
.cx
] + char
+ t
[self
.cx
:]
552 self
.SetTextLine(self
.cy
, t
)
557 t1
= self
.lines
[self
.cy
]
558 t2
= self
.lines
[self
.cy
+1]
560 self
.lines
= self
.lines
[:self
.cy
] + [t1
+ t2
] + self
.lines
[self
.cy
+2:]
564 def DeleteChar(self
,x
,y
,oldtext
):
565 newtext
= oldtext
[:x
] + oldtext
[x
+1:]
566 self
.SetTextLine(y
, newtext
)
570 def BackSpace(self
, event
):
571 t
= self
.GetTextLine(self
.cy
)
573 self
.DeleteChar(self
.cx
-1,self
.cy
,t
)
584 def Delete(self
, event
):
585 t
= self
.GetTextLine(self
.cy
)
587 self
.DeleteChar(self
.cx
,self
.cy
,t
)
590 if self
.cy
< len(self
.lines
) - 1:
594 def Escape(self
, event
):
597 def TabKey(self
, event
):
598 numSpaces
= self
.SpacesPerTab
- (self
.cx
% self
.SpacesPerTab
)
599 self
.SingleLineInsert(' ' * numSpaces
)
601 ##----------- selection routines
603 def SelectUpdate(self
):
604 self
.SelectEnd
= (self
.cy
, self
.cx
)
605 self
.SelectNotify(self
.Selecting
, self
.SelectBegin
, self
.SelectEnd
)
608 def NormalizedSelect(self
):
609 (begin
, end
) = (self
.SelectBegin
, self
.SelectEnd
)
622 def FindSelection(self
):
623 if self
.SelectEnd
is None or self
.SelectBegin
is None:
626 (begin
, end
) = self
.NormalizedSelect()
629 return (bRow
, bCol
, eRow
, eCol
)
632 self
.SelectBegin
= None
633 self
.SelectEnd
= None
634 self
.Selecting
= false
635 self
.SelectNotify(false
,None,None)
637 def CopySelection(self
, event
):
638 selection
= self
.FindSelection()
639 if selection
is None:
641 (bRow
, bCol
, eRow
, eCol
) = selection
644 self
.SingleLineCopy(bRow
, bCol
, eCol
)
646 self
.MultipleLineCopy(bRow
, bCol
, eRow
, eCol
)
648 def OnCopySelection(self
, event
):
649 self
.CopySelection(event
)
652 def CopyToClipboard(self
, linesOfText
):
653 do
= wxTextDataObject()
654 do
.SetText(string
.join(linesOfText
, os
.linesep
))
655 wxTheClipboard
.Open()
656 wxTheClipboard
.SetData(do
)
657 wxTheClipboard
.Close()
659 def SingleLineCopy(self
, Row
, bCol
, eCol
):
660 Line
= self
.GetTextLine(Row
)
661 self
.CopyToClipboard([Line
[bCol
:eCol
]])
663 def MultipleLineCopy(self
, bRow
, bCol
, eRow
, eCol
):
664 bLine
= self
.GetTextLine(bRow
)[bCol
:]
665 eLine
= self
.GetTextLine(eRow
)[:eCol
]
666 self
.CopyToClipboard([bLine
] + [l
for l
in self
.lines
[bRow
+ 1:eRow
]] + [eLine
])
668 def OnDeleteSelection(self
, event
):
669 selection
= self
.FindSelection()
670 if selection
is None:
672 (bRow
, bCol
, eRow
, eCol
) = selection
675 self
.SingleLineDelete(bRow
, bCol
, eCol
)
677 self
.MultipleLineDelete(bRow
, bCol
, eRow
, eCol
)
687 def SingleLineDelete(self
, Row
, bCol
, eCol
):
688 ModLine
= self
.GetTextLine(Row
)
689 ModLine
= ModLine
[:bCol
] + ModLine
[eCol
:]
690 self
.SetTextLine(Row
,ModLine
)
692 def MultipleLineDelete(self
, bRow
, bCol
, eRow
, eCol
):
693 bLine
= self
.GetTextLine(bRow
)
694 eLine
= self
.GetTextLine(eRow
)
695 ModLine
= bLine
[:bCol
] + eLine
[eCol
:]
696 self
.lines
[bRow
:eRow
+ 1] = [ModLine
]
698 def OnPaste(self
, event
):
699 do
= wxTextDataObject()
700 wxTheClipboard
.Open()
701 success
= wxTheClipboard
.GetData(do
)
702 wxTheClipboard
.Close()
704 pastedLines
= LineSplitter(do
.GetText())
708 if len(pastedLines
) == 0:
711 elif len(pastedLines
) == 1:
712 self
.SingleLineInsert(pastedLines
[0])
714 self
.MultipleLinePaste(pastedLines
)
716 def SingleLineInsert(self
, newText
):
717 ModLine
= self
.GetTextLine(self
.cy
)
718 ModLine
= ModLine
[:self
.cx
] + newText
+ ModLine
[self
.cx
:]
719 self
.SetTextLine(self
.cy
, ModLine
)
720 self
.cHoriz(len(newText
))
724 def MultipleLinePaste(self
, pastedLines
):
725 FirstLine
= LastLine
= self
.GetTextLine(self
.cy
)
726 FirstLine
= FirstLine
[:self
.cx
] + pastedLines
[0]
727 LastLine
= pastedLines
[-1] + LastLine
[self
.cx
:]
729 NewSlice
= [FirstLine
]
730 NewSlice
+= [l
for l
in pastedLines
[1:-1]]
731 NewSlice
+= [LastLine
]
732 self
.lines
[self
.cy
:self
.cy
+ 1] = NewSlice
734 self
.cy
= self
.cy
+ len(pastedLines
)-1
735 self
.cx
= len(pastedLines
[-1])
739 def OnCutSelection(self
,event
):
740 self
.CopySelection(event
)
741 self
.OnDeleteSelection(event
)
743 #-------------- Keyboard movement implementations
745 def MoveDown(self
, event
):
748 def MoveUp(self
, event
):
751 def MoveLeft(self
, event
):
757 self
.cx
= self
.CurrentLineLength()
761 def MoveRight(self
, event
):
762 linelen
= self
.CurrentLineLength()
763 if self
.cx
== linelen
:
764 if self
.cy
== len(self
.lines
) - 1:
773 def MovePageDown(self
, event
):
776 def MovePageUp(self
, event
):
779 def MoveHome(self
, event
):
782 def MoveEnd(self
, event
):
783 self
.cx
= self
.CurrentLineLength()
785 def MoveStartOfFile(self
, event
):
789 def MoveEndOfFile(self
, event
):
790 self
.cy
= len(self
.lines
) - 1
791 self
.cx
= self
.CurrentLineLength()
793 #-------------- Key handler mapping tables
795 def SetMoveSpecialFuncs(self
, action
):
796 action
[WXK_DOWN
] = self
.MoveDown
797 action
[WXK_UP
] = self
.MoveUp
798 action
[WXK_LEFT
] = self
.MoveLeft
799 action
[WXK_RIGHT
] = self
.MoveRight
800 action
[WXK_NEXT
] = self
.MovePageDown
801 action
[WXK_PRIOR
] = self
.MovePageUp
802 action
[WXK_HOME
] = self
.MoveHome
803 action
[WXK_END
] = self
.MoveEnd
805 def SetMoveSpecialControlFuncs(self
, action
):
806 action
[WXK_HOME
] = self
.MoveStartOfFile
807 action
[WXK_END
] = self
.MoveEndOfFile
809 def SetAltFuncs(self
, action
):
810 # subclass implements
813 def SetControlFuncs(self
, action
):
814 action
['c'] = self
.OnCopySelection
815 action
['d'] = self
.OnDeleteSelection
816 action
['v'] = self
.OnPaste
817 action
['x'] = self
.OnCutSelection
819 def SetSpecialControlFuncs(self
, action
):
820 action
[WXK_INSERT
] = self
.OnCopySelection
822 def SetShiftFuncs(self
, action
):
823 action
[WXK_DELETE
] = self
.OnCutSelection
824 action
[WXK_INSERT
] = self
.OnPaste
826 def SetSpecialFuncs(self
, action
):
827 action
[WXK_BACK
] = self
.BackSpace
828 action
[WXK_DELETE
] = self
.Delete
829 action
[WXK_RETURN
] = self
.BreakLine
830 action
[WXK_ESCAPE
] = self
.Escape
831 action
[WXK_TAB
] = self
.TabKey
833 ##-------------- Logic for key handlers
836 def Move(self
, keySettingFunction
, key
, event
):
838 keySettingFunction(action
)
840 if not action
.has_key(key
):
843 if event
.ShiftDown():
844 if not self
.Selecting
:
845 self
.Selecting
= true
846 self
.SelectBegin
= (self
.cy
, self
.cx
)
848 self
.SelectEnd
= (self
.cy
, self
.cx
)
852 self
.Selecting
= false
854 self
.SelectNotify(self
.Selecting
, self
.SelectBegin
, self
.SelectEnd
)
858 def MoveSpecialKey(self
, event
, key
):
859 return self
.Move(self
.SetMoveSpecialFuncs
, key
, event
)
861 def MoveSpecialControlKey(self
, event
, key
):
862 if not event
.ControlDown():
864 return self
.Move(self
.SetMoveSpecialControlFuncs
, key
, event
)
866 def Dispatch(self
, keySettingFunction
, key
, event
):
868 keySettingFunction(action
)
869 if action
.has_key(key
):
875 def ModifierKey(self
, key
, event
, modifierKeyDown
, MappingFunc
):
876 if not modifierKeyDown
:
879 key
= self
.UnixKeyHack(key
)
884 if not self
.Dispatch(MappingFunc
, key
, event
):
888 def ControlKey(self
, event
, key
):
889 return self
.ModifierKey(key
, event
, event
.ControlDown(), self
.SetControlFuncs
)
891 def AltKey(self
, event
, key
):
892 return self
.ModifierKey(key
, event
, event
.AltDown(), self
.SetAltFuncs
)
894 def SpecialControlKey(self
, event
, key
):
895 if not event
.ControlDown():
897 if not self
.Dispatch(self
.SetSpecialControlFuncs
, key
, event
):
901 def ShiftKey(self
, event
, key
):
902 if not event
.ShiftDown():
904 return self
.Dispatch(self
.SetShiftFuncs
, key
, event
)
906 def NormalChar(self
, event
, key
):
910 if not self
.Dispatch(self
.SetSpecialFuncs
, key
, event
):
911 if (key
>31) and (key
<256):
912 self
.InsertChar(chr(key
))
917 self
.AdjustScrollbars()
919 def OnChar(self
, event
):
920 key
= event
.KeyCode()
921 filters
= [self
.AltKey
,
922 self
.MoveSpecialControlKey
,
924 self
.SpecialControlKey
,
928 for filter in filters
:
929 if filter(event
,key
):
933 #----------------------- Eliminate memory leaks
935 def OnDestroy(self
, event
):
941 self
.selectColor
= None
942 self
.scrollTimer
= None
943 self
.eofMarker
= None
945 #-------------------- Abstract methods for subclasses
950 def SelectNotify(self
, Selecting
, SelectionBegin
, SelectionEnd
):