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():
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 self
.SelectEnd
is None:
468 self
.Selecting
= false
469 self
.SelectNotify(false
, self
.SelectBegin
, self
.SelectEnd
)
472 self
.scrollTimer
.Stop()
475 #------------------------- Scrolling
477 def HorizScroll(self
, event
, eventType
):
478 maxLineLen
= self
.CalcMaxLineLen()
480 if eventType
== wxEVT_SCROLLWIN_LINEUP
:
482 elif eventType
== wxEVT_SCROLLWIN_LINEDOWN
:
484 elif eventType
== wxEVT_SCROLLWIN_PAGEUP
:
486 elif eventType
== wxEVT_SCROLLWIN_PAGEDOWN
:
488 elif eventType
== wxEVT_SCROLLWIN_TOP
:
489 self
.sx
= self
.cx
= 0
490 elif eventType
== wxEVT_SCROLLWIN_BOTTOM
:
491 self
.sx
= maxLineLen
- self
.sw
494 self
.sx
= event
.GetPosition()
496 self
.HorizBoundaries()
498 def VertScroll(self
, event
, eventType
):
499 if eventType
== wxEVT_SCROLLWIN_LINEUP
:
501 elif eventType
== wxEVT_SCROLLWIN_LINEDOWN
:
503 elif eventType
== wxEVT_SCROLLWIN_PAGEUP
:
505 elif eventType
== wxEVT_SCROLLWIN_PAGEDOWN
:
507 elif eventType
== wxEVT_SCROLLWIN_TOP
:
508 self
.sy
= self
.cy
= 0
509 elif eventType
== wxEVT_SCROLLWIN_BOTTOM
:
510 self
.sy
= self
.LinesInFile() - self
.sh
511 self
.cy
= self
.LinesInFile()
513 self
.sy
= event
.GetPosition()
515 self
.VertBoundaries()
517 def OnScroll(self
, event
):
518 dir = event
.GetOrientation()
519 eventType
= event
.GetEventType()
520 if dir == wxHORIZONTAL
:
521 self
.HorizScroll(event
, eventType
)
523 self
.VertScroll(event
, eventType
)
527 def AdjustScrollbars(self
):
529 self
.SetCharDimensions()
530 self
.scroller
.SetScrollbars(
532 self
.CalcMaxLineLen()+3, max(self
.LinesInFile()+1, self
.sh
),
535 #------------ backspace, delete, return
537 def BreakLine(self
, event
):
538 if self
.IsLine(self
.cy
):
539 t
= self
.lines
[self
.cy
]
540 self
.lines
= self
.lines
[:self
.cy
] + [t
[:self
.cx
],t
[self
.cx
:]] + self
.lines
[self
.cy
+1:]
545 def InsertChar(self
,char
):
546 if self
.IsLine(self
.cy
):
547 t
= self
.lines
[self
.cy
]
548 t
= t
[:self
.cx
] + char
+ t
[self
.cx
:]
549 self
.SetTextLine(self
.cy
, t
)
554 t1
= self
.lines
[self
.cy
]
555 t2
= self
.lines
[self
.cy
+1]
557 self
.lines
= self
.lines
[:self
.cy
] + [t1
+ t2
] + self
.lines
[self
.cy
+2:]
561 def DeleteChar(self
,x
,y
,oldtext
):
562 newtext
= oldtext
[:x
] + oldtext
[x
+1:]
563 self
.SetTextLine(y
, newtext
)
567 def BackSpace(self
, event
):
568 t
= self
.GetTextLine(self
.cy
)
570 self
.DeleteChar(self
.cx
-1,self
.cy
,t
)
581 def Delete(self
, event
):
582 t
= self
.GetTextLine(self
.cy
)
584 self
.DeleteChar(self
.cx
,self
.cy
,t
)
587 if self
.cy
< len(self
.lines
) - 1:
591 def Escape(self
, event
):
594 def TabKey(self
, event
):
595 numSpaces
= self
.SpacesPerTab
- (self
.cx
% self
.SpacesPerTab
)
596 self
.SingleLineInsert(' ' * numSpaces
)
598 ##----------- selection routines
600 def SelectUpdate(self
):
601 self
.SelectEnd
= (self
.cy
, self
.cx
)
602 self
.SelectNotify(self
.Selecting
, self
.SelectBegin
, self
.SelectEnd
)
605 def NormalizedSelect(self
):
606 (begin
, end
) = (self
.SelectBegin
, self
.SelectEnd
)
619 def FindSelection(self
):
620 if self
.SelectEnd
is None or self
.SelectBegin
is None:
623 (begin
, end
) = self
.NormalizedSelect()
626 return (bRow
, bCol
, eRow
, eCol
)
629 self
.SelectBegin
= None
630 self
.SelectEnd
= None
631 self
.Selecting
= false
632 self
.SelectNotify(false
,None,None)
634 def CopySelection(self
, event
):
635 selection
= self
.FindSelection()
636 if selection
is None:
638 (bRow
, bCol
, eRow
, eCol
) = selection
641 self
.SingleLineCopy(bRow
, bCol
, eCol
)
643 self
.MultipleLineCopy(bRow
, bCol
, eRow
, eCol
)
645 def OnCopySelection(self
, event
):
646 self
.CopySelection(event
)
649 def CopyToClipboard(self
, linesOfText
):
650 do
= wxTextDataObject()
651 do
.SetText(string
.join(linesOfText
, os
.linesep
))
652 wxTheClipboard
.Open()
653 wxTheClipboard
.SetData(do
)
654 wxTheClipboard
.Close()
656 def SingleLineCopy(self
, Row
, bCol
, eCol
):
657 Line
= self
.GetTextLine(Row
)
658 self
.CopyToClipboard([Line
[bCol
:eCol
]])
660 def MultipleLineCopy(self
, bRow
, bCol
, eRow
, eCol
):
661 bLine
= self
.GetTextLine(bRow
)[bCol
:]
662 eLine
= self
.GetTextLine(eRow
)[:eCol
]
663 self
.CopyToClipboard([bLine
] + [l
for l
in self
.lines
[bRow
+ 1:eRow
]] + [eLine
])
665 def OnDeleteSelection(self
, event
):
666 selection
= self
.FindSelection()
667 if selection
is None:
669 (bRow
, bCol
, eRow
, eCol
) = selection
672 self
.SingleLineDelete(bRow
, bCol
, eCol
)
674 self
.MultipleLineDelete(bRow
, bCol
, eRow
, eCol
)
684 def SingleLineDelete(self
, Row
, bCol
, eCol
):
685 ModLine
= self
.GetTextLine(Row
)
686 ModLine
= ModLine
[:bCol
] + ModLine
[eCol
:]
687 self
.SetTextLine(Row
,ModLine
)
689 def MultipleLineDelete(self
, bRow
, bCol
, eRow
, eCol
):
690 bLine
= self
.GetTextLine(bRow
)
691 eLine
= self
.GetTextLine(eRow
)
692 ModLine
= bLine
[:bCol
] + eLine
[eCol
:]
693 self
.lines
[bRow
:eRow
+ 1] = [ModLine
]
695 def OnPaste(self
, event
):
696 do
= wxTextDataObject()
697 wxTheClipboard
.Open()
698 success
= wxTheClipboard
.GetData(do
)
699 wxTheClipboard
.Close()
701 pastedLines
= LineSplitter(do
.GetText())
705 if len(pastedLines
) == 0:
708 elif len(pastedLines
) == 1:
709 self
.SingleLineInsert(pastedLines
[0])
711 self
.MultipleLinePaste(pastedLines
)
713 def SingleLineInsert(self
, newText
):
714 ModLine
= self
.GetTextLine(self
.cy
)
715 ModLine
= ModLine
[:self
.cx
] + newText
+ ModLine
[self
.cx
:]
716 self
.SetTextLine(self
.cy
, ModLine
)
717 self
.cHoriz(len(newText
))
721 def MultipleLinePaste(self
, pastedLines
):
722 FirstLine
= LastLine
= self
.GetTextLine(self
.cy
)
723 FirstLine
= FirstLine
[:self
.cx
] + pastedLines
[0]
724 LastLine
= pastedLines
[-1] + LastLine
[self
.cx
:]
726 NewSlice
= [FirstLine
]
727 NewSlice
+= [l
for l
in pastedLines
[1:-1]]
728 NewSlice
+= [LastLine
]
729 self
.lines
[self
.cy
:self
.cy
+ 1] = NewSlice
731 self
.cy
= self
.cy
+ len(pastedLines
)-1
732 self
.cx
= len(pastedLines
[-1])
736 def OnCutSelection(self
,event
):
737 self
.CopySelection(event
)
738 self
.OnDeleteSelection(event
)
740 #-------------- Keyboard movement implementations
742 def MoveDown(self
, event
):
745 def MoveUp(self
, event
):
748 def MoveLeft(self
, event
):
754 self
.cx
= self
.CurrentLineLength()
758 def MoveRight(self
, event
):
759 linelen
= self
.CurrentLineLength()
760 if self
.cx
== linelen
:
761 if self
.cy
== len(self
.lines
) - 1:
770 def MovePageDown(self
, event
):
773 def MovePageUp(self
, event
):
776 def MoveHome(self
, event
):
779 def MoveEnd(self
, event
):
780 self
.cx
= self
.CurrentLineLength()
782 def MoveStartOfFile(self
, event
):
786 def MoveEndOfFile(self
, event
):
787 self
.cy
= len(self
.lines
) - 1
788 self
.cx
= self
.CurrentLineLength()
790 #-------------- Key handler mapping tables
792 def SetMoveSpecialFuncs(self
, action
):
793 action
[WXK_DOWN
] = self
.MoveDown
794 action
[WXK_UP
] = self
.MoveUp
795 action
[WXK_LEFT
] = self
.MoveLeft
796 action
[WXK_RIGHT
] = self
.MoveRight
797 action
[WXK_NEXT
] = self
.MovePageDown
798 action
[WXK_PRIOR
] = self
.MovePageUp
799 action
[WXK_HOME
] = self
.MoveHome
800 action
[WXK_END
] = self
.MoveEnd
802 def SetMoveSpecialControlFuncs(self
, action
):
803 action
[WXK_HOME
] = self
.MoveStartOfFile
804 action
[WXK_END
] = self
.MoveEndOfFile
806 def SetAltFuncs(self
, action
):
807 # subclass implements
810 def SetControlFuncs(self
, action
):
811 action
['c'] = self
.OnCopySelection
812 action
['d'] = self
.OnDeleteSelection
813 action
['v'] = self
.OnPaste
814 action
['x'] = self
.OnCutSelection
816 def SetSpecialControlFuncs(self
, action
):
817 action
[WXK_INSERT
] = self
.OnCopySelection
819 def SetShiftFuncs(self
, action
):
820 action
[WXK_DELETE
] = self
.OnCutSelection
821 action
[WXK_INSERT
] = self
.OnPaste
823 def SetSpecialFuncs(self
, action
):
824 action
[WXK_BACK
] = self
.BackSpace
825 action
[WXK_DELETE
] = self
.Delete
826 action
[WXK_RETURN
] = self
.BreakLine
827 action
[WXK_ESCAPE
] = self
.Escape
828 action
[WXK_TAB
] = self
.TabKey
830 ##-------------- Logic for key handlers
833 def Move(self
, keySettingFunction
, key
, event
):
835 keySettingFunction(action
)
837 if not action
.has_key(key
):
840 if event
.ShiftDown():
841 if not self
.Selecting
:
842 self
.Selecting
= true
843 self
.SelectBegin
= (self
.cy
, self
.cx
)
845 self
.SelectEnd
= (self
.cy
, self
.cx
)
849 self
.Selecting
= false
851 self
.SelectNotify(self
.Selecting
, self
.SelectBegin
, self
.SelectEnd
)
855 def MoveSpecialKey(self
, event
, key
):
856 return self
.Move(self
.SetMoveSpecialFuncs
, key
, event
)
858 def MoveSpecialControlKey(self
, event
, key
):
859 if not event
.ControlDown():
861 return self
.Move(self
.SetMoveSpecialControlFuncs
, key
, event
)
863 def Dispatch(self
, keySettingFunction
, key
, event
):
865 keySettingFunction(action
)
866 if action
.has_key(key
):
872 def ModifierKey(self
, key
, event
, modifierKeyDown
, MappingFunc
):
873 if not modifierKeyDown
:
876 key
= self
.UnixKeyHack(key
)
881 if not self
.Dispatch(MappingFunc
, key
, event
):
885 def ControlKey(self
, event
, key
):
886 return self
.ModifierKey(key
, event
, event
.ControlDown(), self
.SetControlFuncs
)
888 def AltKey(self
, event
, key
):
889 return self
.ModifierKey(key
, event
, event
.AltDown(), self
.SetAltFuncs
)
891 def SpecialControlKey(self
, event
, key
):
892 if not event
.ControlDown():
894 if not self
.Dispatch(self
.SetSpecialControlFuncs
, key
, event
):
898 def ShiftKey(self
, event
, key
):
899 if not event
.ShiftDown():
901 return self
.Dispatch(self
.SetShiftFuncs
, key
, event
)
903 def NormalChar(self
, event
, key
):
907 if not self
.Dispatch(self
.SetSpecialFuncs
, key
, event
):
908 if (key
>31) and (key
<256):
909 self
.InsertChar(chr(key
))
914 self
.AdjustScrollbars()
916 def OnChar(self
, event
):
917 key
= event
.KeyCode()
918 filters
= [self
.AltKey
,
919 self
.MoveSpecialControlKey
,
921 self
.SpecialControlKey
,
925 for filter in filters
:
926 if filter(event
,key
):
930 #----------------------- Eliminate memory leaks
932 def OnDestroy(self
, event
):
938 self
.selectColor
= None
939 self
.scrollTimer
= None
940 self
.eofMarker
= None
942 #-------------------- Abstract methods for subclasses
947 def SelectNotify(self
, Selecting
, SelectionBegin
, SelectionEnd
):