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):
41 #----------------------------
44 def __init__(self
, parent
):
51 def SetScrollbars(self
, fw
, fh
, w
, h
, x
, y
):
52 if (self
.ow
!= w
or self
.oh
!= h
or self
.ox
!= x
or self
.oy
!= y
):
53 self
.parent
.SetScrollbars(fw
, fh
, w
, h
, x
, y
)
59 #----------------------------------------------------------------------
61 class wxEditor(wxScrolledWindow
):
63 def __init__(self
, parent
, id,
64 pos
=wxDefaultPosition
, size
=wxDefaultSize
, style
=0):
66 wxScrolledWindow
.__init
__(self
, parent
, id,
75 self
.InitDoubleBuffering()
78 self
.CopiedData
= None
83 ##------------------ Init stuff
98 EVT_LEFT_DOWN(self
, self
.OnLeftDown
)
99 EVT_LEFT_UP(self
, self
.OnLeftUp
)
100 EVT_MOTION(self
, self
.OnMotion
)
101 EVT_SCROLLWIN(self
, self
.OnScroll
)
102 EVT_CHAR(self
, self
.OnChar
)
103 EVT_PAINT(self
, self
.OnPaint
)
104 EVT_SIZE(self
, self
.OnSize
)
105 EVT_WINDOW_DESTROY(self
, self
.OnDestroy
)
107 ##------------------- Platform-specific stuff
109 def NiceFontForPlatform(self
):
110 if wxPlatform
== "__WXMSW__":
111 return wxFont(10, wxMODERN
, wxNORMAL
, wxNORMAL
)
113 return wxFont(12, wxMODERN
, wxNORMAL
, wxNORMAL
, false
)
115 def UnixKeyHack(self
, key
):
116 # this will be obsolete when we get the new wxWindows patch
121 ##-------------------- UpdateView/Cursor code
123 def OnSize(self
, event
):
124 self
.AdjustScrollbars()
127 def SetCharDimensions(self
):
128 # TODO: We need a code review on this. It appears that Linux
129 # improperly reports window dimensions when the scrollbar's there.
130 self
.bw
, self
.bh
= self
.GetClientSizeTuple()
132 if wxPlatform
== "__WXMSW__":
133 self
.sh
= self
.bh
/ self
.fh
134 self
.sw
= (self
.bw
/ self
.fw
) - 1
136 self
.sh
= self
.bh
/ self
.fh
137 if self
.LinesInFile() >= self
.sh
:
138 self
.bw
= self
.bw
- wxSystemSettings_GetSystemMetric(wxSYS_VSCROLL_X
)
139 self
.sw
= (self
.bw
/ self
.fw
) - 1
141 self
.sw
= (self
.bw
/ self
.fw
) - 1
142 if self
.CalcMaxLineLen() >= self
.sw
:
143 self
.bh
= self
.bh
- wxSystemSettings_GetSystemMetric(wxSYS_HSCROLL_Y
)
144 self
.sh
= self
.bh
/ self
.fh
147 def UpdateView(self
, dc
= None):
149 dc
= wxClientDC(self
)
150 self
.SetCharDimensions()
151 self
.KeepCursorOnScreen()
152 self
.DrawSimpleCursor(0,0,dc
, true
)
155 def OnPaint(self
, event
):
158 self
.AdjustScrollbars()
160 ##-------------------- Drawing code
163 dc
= wxClientDC(self
)
164 self
.font
= self
.NiceFontForPlatform()
165 dc
.SetFont(self
.font
)
166 self
.fw
= dc
.GetCharWidth()
167 self
.fh
= dc
.GetCharHeight()
170 self
.fgColor
= wxNamedColour('black')
171 self
.bgColor
= wxNamedColour('white')
172 self
.selectColor
= wxColour(238, 220, 120) # r, g, b = emacsOrange
174 def InitDoubleBuffering(self
):
175 bw
,bh
= self
.GetClientSizeTuple()
176 self
.mdc
= wxMemoryDC()
177 self
.mdc
.SelectObject(wxEmptyBitmap(bw
,bh
))
179 def DrawEditText(self
, t
, x
, y
, dc
):
180 dc
.DrawText(t
, x
* self
.fw
, y
* self
.fh
)
182 def DrawLine(self
, line
, dc
):
183 if self
.IsLine(line
):
186 dc
.SetTextForeground(self
.fgColor
)
187 fragments
= selection
.Selection(
188 self
.SelectBegin
, self
.SelectEnd
,
189 self
.sx
, self
.sw
, line
, t
)
191 for (data
, selected
) in fragments
:
193 dc
.SetTextBackground(self
.selectColor
)
194 if x
== 0 and len(data
) == 0 and len(fragments
) == 1:
197 dc
.SetTextBackground(self
.bgColor
)
198 self
.DrawEditText(data
, x
, line
- self
.sy
, dc
)
201 def Draw(self
, odc
=None):
203 odc
= wxClientDC(self
)
206 dc
.SetFont(self
.font
)
207 dc
.SelectObject(wxEmptyBitmap(self
.bw
,self
.bh
))
208 dc
.SetBackgroundMode(wxSOLID
)
209 dc
.SetTextBackground(self
.bgColor
)
210 dc
.SetTextForeground(self
.fgColor
)
212 for line
in range(self
.sy
, self
.sy
+ self
.sh
):
213 self
.DrawLine(line
, dc
)
214 if len(self
.lines
) < self
.sh
+ self
.sy
:
215 self
.DrawEofMarker(dc
)
216 odc
.Blit(0,0,self
.bw
,self
.bh
,dc
,0,0,wxCOPY
)
219 ##------------------ eofMarker stuff
221 def LoadImages(self
):
222 self
.eofMarker
= images
.GetBitmap(images
.EofImageData
)
224 def DrawEofMarker(self
,dc
):
226 y
= (len(self
.lines
) - self
.sy
) * self
.fh
228 dc
.DrawBitmap(self
.eofMarker
, x
, y
, hasTransparency
)
230 ##------------------ cursor-related functions
232 def DrawCursor(self
, dc
= None):
234 dc
= wxClientDC(self
)
236 if (self
.LinesInFile())<self
.cy
: #-1 ?
237 self
.cy
= self
.LinesInFile()-1
238 s
= self
.lines
[self
.cy
]
240 x
= self
.cx
- self
.sx
241 y
= self
.cy
- self
.sy
242 self
.DrawSimpleCursor(x
, y
, dc
)
245 def DrawSimpleCursor(self
, xp
, yp
, dc
= None, old
=false
):
247 dc
= wxClientDC(self
)
257 dc
.Blit(x
,y
,szx
,szy
,dc
,x
,y
,wxSRC_INVERT
)
261 ##-------- Enforcing screen boundaries, cursor movement
263 def CalcMaxLineLen(self
):
264 """get length of longest line on screen"""
266 for line
in self
.lines
[self
.sy
:self
.sy
+self
.sh
]:
267 if len(line
) >maxlen
:
271 def KeepCursorOnScreen(self
):
272 self
.sy
= ForceBetween(max(0, self
.cy
-self
.sh
), self
.sy
, self
.cy
)
273 self
.sx
= ForceBetween(max(0, self
.cx
-self
.sw
), self
.sx
, self
.cx
)
274 self
.AdjustScrollbars()
276 def HorizBoundaries(self
):
277 self
.SetCharDimensions()
278 maxLineLen
= self
.CalcMaxLineLen()
279 self
.sx
= ForceBetween(0, self
.sx
, max(self
.sw
, maxLineLen
- self
.sw
+ 1))
280 self
.cx
= ForceBetween(self
.sx
, self
.cx
, self
.sx
+ self
.sw
- 1)
282 def VertBoundaries(self
):
283 self
.SetCharDimensions()
284 self
.sy
= ForceBetween(0, self
.sy
, max(self
.sh
, self
.LinesInFile() - self
.sh
+ 1))
285 self
.cy
= ForceBetween(self
.sy
, self
.cy
, self
.sy
+ self
.sh
- 1)
287 def cVert(self
, num
):
288 self
.cy
= self
.cy
+ num
289 self
.cy
= ForceBetween(0, self
.cy
, self
.LinesInFile() - 1)
290 self
.sy
= ForceBetween(self
.cy
- self
.sh
+ 1, self
.sy
, self
.cy
)
291 self
.cx
= min(self
.cx
, self
.CurrentLineLength())
293 def cHoriz(self
, num
):
294 self
.cx
= self
.cx
+ num
295 self
.cx
= ForceBetween(0, self
.cx
, self
.CurrentLineLength())
296 self
.sx
= ForceBetween(self
.cx
- self
.sw
+ 1, self
.sx
, self
.cx
)
298 def AboveScreen(self
, row
):
301 def BelowScreen(self
, row
):
302 return row
>= self
.sy
+ self
.sh
304 def LeftOfScreen(self
, col
):
307 def RightOfScreen(self
, col
):
308 return col
>= self
.sx
+ self
.sw
310 ##----------------- data structure helper functions
315 def SetText(self
, lines
):
320 self
.AdjustScrollbars()
321 self
.UpdateView(None)
323 def IsLine(self
, lineNum
):
324 return (0<=lineNum
) and (lineNum
<self
.LinesInFile())
326 def GetTextLine(self
, lineNum
):
327 if self
.IsLine(lineNum
):
328 return self
.lines
[lineNum
]
331 def SetTextLine(self
, lineNum
, text
):
332 if self
.IsLine(lineNum
):
333 self
.lines
[lineNum
] = text
335 def CurrentLineLength(self
):
336 return len(self
.lines
[self
.cy
])
338 def LinesInFile(self
):
339 return len(self
.lines
)
341 def UnTouchBuffer(self
):
342 self
.bufferTouched
= FALSE
344 def BufferWasTouched(self
):
345 return self
.bufferTouched
347 def TouchBuffer(self
):
348 self
.bufferTouched
= TRUE
351 ##-------------------------- Mouse scroll timing functions
353 def InitScrolling(self
):
354 # we don't rely on the windows system to scroll for us; we just
355 # redraw the screen manually every time
356 self
.EnableScrolling(FALSE
, FALSE
)
357 self
.nextScrollTime
= 0
358 self
.SCROLLDELAY
= 0.050 # seconds
359 self
.scrollTimer
= wxTimer(self
)
360 self
.scroller
= Scroller(self
)
363 if time
.time() > self
.nextScrollTime
:
364 self
.nextScrollTime
= time
.time() + self
.SCROLLDELAY
369 def SetScrollTimer(self
):
371 self
.scrollTimer
.Start(1000*self
.SCROLLDELAY
/2, oneShot
)
372 EVT_TIMER(self
, -1, self
.OnTimer
)
374 def OnTimer(self
, event
):
375 screenX
, screenY
= wxGetMousePosition()
376 x
, y
= self
.ScreenToClientXY(screenX
, screenY
)
381 ##-------------------------- Mouse off screen functions
383 def HandleAboveScreen(self
, row
):
384 self
.SetScrollTimer()
390 def HandleBelowScreen(self
, row
):
391 self
.SetScrollTimer()
393 row
= self
.sy
+ self
.sh
394 row
= min(row
, self
.LinesInFile() - 1)
397 def HandleLeftOfScreen(self
, col
):
398 self
.SetScrollTimer()
404 def HandleRightOfScreen(self
, col
):
405 self
.SetScrollTimer()
407 col
= self
.sx
+ self
.sw
408 col
= min(col
, self
.CurrentLineLength())
411 ##------------------------ mousing functions
413 def MouseToRow(self
, mouseY
):
414 row
= self
.sy
+ (mouseY
/ self
.fh
)
415 if self
.AboveScreen(row
):
416 self
.HandleAboveScreen(row
)
417 elif self
.BelowScreen(row
):
418 self
.HandleBelowScreen(row
)
420 self
.cy
= min(row
, self
.LinesInFile() - 1)
422 def MouseToCol(self
, mouseX
):
423 col
= self
.sx
+ (mouseX
/ self
.fw
)
424 if self
.LeftOfScreen(col
):
425 self
.HandleLeftOfScreen(col
)
426 elif self
.RightOfScreen(col
):
427 self
.HandleRightOfScreen(col
)
429 self
.cx
= min(col
, self
.CurrentLineLength())
431 def MouseToCursor(self
, event
):
432 self
.MouseToRow(event
.GetY())
433 self
.MouseToCol(event
.GetX())
435 def OnMotion(self
, event
):
436 if event
.LeftIsDown():
437 self
.Selecting
= true
438 self
.MouseToCursor(event
)
441 def OnLeftDown(self
, event
):
442 self
.MouseToCursor(event
)
443 self
.SelectBegin
= (self
.cy
, self
.cx
)
444 self
.SelectEnd
= None
448 def OnLeftUp(self
, event
):
449 if self
.SelectEnd
is None:
452 self
.Selecting
= false
453 self
.SelectNotify(false
, self
.SelectBegin
, self
.SelectEnd
)
456 self
.scrollTimer
.Stop()
459 #------------------------- Scrolling
461 def HorizScroll(self
, event
, eventType
):
462 maxLineLen
= self
.CalcMaxLineLen()
464 if eventType
== wxEVT_SCROLLWIN_LINEUP
:
466 elif eventType
== wxEVT_SCROLLWIN_LINEDOWN
:
468 elif eventType
== wxEVT_SCROLLWIN_PAGEUP
:
470 elif eventType
== wxEVT_SCROLLWIN_PAGEDOWN
:
472 elif eventType
== wxEVT_SCROLLWIN_TOP
:
473 self
.sx
= self
.cx
= 0
474 elif eventType
== wxEVT_SCROLLWIN_BOTTOM
:
475 self
.sx
= maxLineLen
- self
.sw
478 self
.sx
= event
.GetPosition()
480 self
.HorizBoundaries()
482 def VertScroll(self
, event
, eventType
):
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
.sy
= self
.cy
= 0
493 elif eventType
== wxEVT_SCROLLWIN_BOTTOM
:
494 self
.sy
= self
.LinesInFile() - self
.sh
495 self
.cy
= self
.LinesInFile()
497 self
.sy
= event
.GetPosition()
499 self
.VertBoundaries()
501 def OnScroll(self
, event
):
502 dir = event
.GetOrientation()
503 eventType
= event
.GetEventType()
504 if dir == wxHORIZONTAL
:
505 self
.HorizScroll(event
, eventType
)
507 self
.VertScroll(event
, eventType
)
511 def AdjustScrollbars(self
):
513 self
.SetCharDimensions()
514 self
.scroller
.SetScrollbars(
516 self
.CalcMaxLineLen()+3, max(self
.LinesInFile()+1, self
.sh
),
519 #------------ backspace, delete, return
521 def BreakLine(self
, event
):
522 if self
.IsLine(self
.cy
):
523 t
= self
.lines
[self
.cy
]
524 self
.lines
= self
.lines
[:self
.cy
] + [t
[:self
.cx
],t
[self
.cx
:]] + self
.lines
[self
.cy
+1:]
529 def InsertChar(self
,char
):
530 if self
.IsLine(self
.cy
):
531 t
= self
.lines
[self
.cy
]
532 t
= t
[:self
.cx
] + char
+ t
[self
.cx
:]
533 self
.SetTextLine(self
.cy
, t
)
538 t1
= self
.lines
[self
.cy
]
539 t2
= self
.lines
[self
.cy
+1]
541 self
.lines
= self
.lines
[:self
.cy
] + [t1
+ t2
] + self
.lines
[self
.cy
+2:]
545 def DeleteChar(self
,x
,y
,oldtext
):
546 newtext
= oldtext
[:x
] + oldtext
[x
+1:]
547 self
.SetTextLine(y
, newtext
)
551 def BackSpace(self
, event
):
552 t
= self
.GetTextLine(self
.cy
)
554 self
.DeleteChar(self
.cx
-1,self
.cy
,t
)
565 def Delete(self
, event
):
566 t
= self
.GetTextLine(self
.cy
)
568 self
.DeleteChar(self
.cx
,self
.cy
,t
)
571 if self
.cy
< len(self
.lines
) - 1:
575 def Escape(self
, event
):
578 def TabKey(self
, event
):
579 numSpaces
= self
.SpacesPerTab
- (self
.cx
% self
.SpacesPerTab
)
580 self
.SingleLineInsert(' ' * numSpaces
)
582 ##----------- selection routines
584 def SelectUpdate(self
):
585 self
.SelectEnd
= (self
.cy
, self
.cx
)
586 self
.SelectNotify(self
.Selecting
, self
.SelectBegin
, self
.SelectEnd
)
589 def NormalizedSelect(self
):
590 (begin
, end
) = (self
.SelectBegin
, self
.SelectEnd
)
603 def FindSelection(self
):
604 if self
.SelectEnd
is None or self
.SelectBegin
is None:
607 (begin
, end
) = self
.NormalizedSelect()
610 return (bRow
, bCol
, eRow
, eCol
)
613 self
.SelectBegin
= None
614 self
.SelectEnd
= None
615 self
.Selecting
= false
616 self
.SelectNotify(false
,None,None)
618 def CopySelection(self
, event
):
619 selection
= self
.FindSelection()
620 if selection
is None:
622 (bRow
, bCol
, eRow
, eCol
) = selection
625 self
.SingleLineCopy(bRow
, bCol
, eCol
)
627 self
.MultipleLineCopy(bRow
, bCol
, eRow
, eCol
)
629 def OnCopySelection(self
, event
):
630 self
.CopySelection(event
)
633 def CopyData(self
, data
):
634 self
.CopiedData
= data
636 def SingleLineCopy(self
, Row
, bCol
, eCol
):
637 Line
= self
.GetTextLine(Row
)
638 self
.CopyData([Line
[bCol
:eCol
]])
640 def MultipleLineCopy(self
, bRow
, bCol
, eRow
, eCol
):
641 bLine
= self
.GetTextLine(bRow
)[bCol
:]
642 eLine
= self
.GetTextLine(eRow
)[:eCol
]
643 self
.CopyData([bLine
] + [l
for l
in self
.lines
[bRow
+ 1:eRow
]] + [eLine
])
645 def OnDeleteSelection(self
, event
):
646 selection
= self
.FindSelection()
647 if selection
is None:
649 (bRow
, bCol
, eRow
, eCol
) = selection
652 self
.SingleLineDelete(bRow
, bCol
, eCol
)
654 self
.MultipleLineDelete(bRow
, bCol
, eRow
, eCol
)
664 def SingleLineDelete(self
, Row
, bCol
, eCol
):
665 ModLine
= self
.GetTextLine(Row
)
666 ModLine
= ModLine
[:bCol
] + ModLine
[eCol
:]
667 self
.SetTextLine(Row
,ModLine
)
669 def MultipleLineDelete(self
, bRow
, bCol
, eRow
, eCol
):
670 bLine
= self
.GetTextLine(bRow
)
671 eLine
= self
.GetTextLine(eRow
)
672 ModLine
= bLine
[:bCol
] + eLine
[eCol
:]
673 self
.lines
[bRow
:eRow
+ 1] = [ModLine
]
675 def OnPaste(self
, event
):
676 if self
.CopiedData
is None:
679 elif len(self
.CopiedData
) == 0:
682 elif len(self
.CopiedData
) == 1:
683 self
.SingleLineInsert(self
.CopiedData
[0])
685 self
.MultipleLinePaste()
687 def SingleLineInsert(self
, newText
):
688 ModLine
= self
.GetTextLine(self
.cy
)
689 ModLine
= ModLine
[:self
.cx
] + newText
+ ModLine
[self
.cx
:]
690 self
.SetTextLine(self
.cy
, ModLine
)
691 self
.cHoriz(len(newText
))
695 def MultipleLinePaste(self
):
696 FirstLine
= LastLine
= self
.GetTextLine(self
.cy
)
697 FirstLine
= FirstLine
[:self
.cx
] + self
.CopiedData
[0]
698 LastLine
= self
.CopiedData
[-1] + LastLine
[self
.cx
:]
700 NewSlice
= [FirstLine
]
701 NewSlice
+= [l
for l
in self
.CopiedData
[1:-1]]
702 NewSlice
+= [LastLine
]
703 self
.lines
[self
.cy
:self
.cy
+ 1] = NewSlice
705 self
.cy
= self
.cy
+ len(self
.CopiedData
)-1
706 self
.cx
= len(self
.CopiedData
[-1])
710 def OnCutSelection(self
,event
):
711 self
.CopySelection(event
)
712 self
.OnDeleteSelection(event
)
714 #-------------- Keyboard movement implementations
716 def MoveDown(self
, event
):
719 def MoveUp(self
, event
):
722 def MoveLeft(self
, event
):
728 self
.cx
= self
.CurrentLineLength()
732 def MoveRight(self
, event
):
733 linelen
= self
.CurrentLineLength()
734 if self
.cx
== linelen
:
735 if self
.cy
== len(self
.lines
) - 1:
744 def MovePageDown(self
, event
):
747 def MovePageUp(self
, event
):
750 def MoveHome(self
, event
):
753 def MoveEnd(self
, event
):
754 self
.cx
= self
.CurrentLineLength()
756 def MoveStartOfFile(self
, event
):
760 def MoveEndOfFile(self
, event
):
761 self
.cy
= len(self
.lines
) - 1
762 self
.cx
= self
.CurrentLineLength()
764 #-------------- Key handler mapping tables
766 def SetMoveSpecialFuncs(self
, action
):
767 action
[WXK_DOWN
] = self
.MoveDown
768 action
[WXK_UP
] = self
.MoveUp
769 action
[WXK_LEFT
] = self
.MoveLeft
770 action
[WXK_RIGHT
] = self
.MoveRight
771 action
[WXK_NEXT
] = self
.MovePageDown
772 action
[WXK_PRIOR
] = self
.MovePageUp
773 action
[WXK_HOME
] = self
.MoveHome
774 action
[WXK_END
] = self
.MoveEnd
776 def SetMoveSpecialControlFuncs(self
, action
):
777 action
[WXK_HOME
] = self
.MoveStartOfFile
778 action
[WXK_END
] = self
.MoveEndOfFile
780 def SetAltFuncs(self
, action
):
781 # subclass implements
784 def SetControlFuncs(self
, action
):
785 action
['c'] = self
.OnCopySelection
786 action
['d'] = self
.OnDeleteSelection
787 action
['v'] = self
.OnPaste
788 action
['x'] = self
.OnCutSelection
790 def SetSpecialControlFuncs(self
, action
):
791 action
[WXK_INSERT
] = self
.OnCopySelection
793 def SetShiftFuncs(self
, action
):
794 action
[WXK_DELETE
] = self
.OnCutSelection
795 action
[WXK_INSERT
] = self
.OnPaste
797 def SetSpecialFuncs(self
, action
):
798 action
[WXK_BACK
] = self
.BackSpace
799 action
[WXK_DELETE
] = self
.Delete
800 action
[WXK_RETURN
] = self
.BreakLine
801 action
[WXK_ESCAPE
] = self
.Escape
802 action
[WXK_TAB
] = self
.TabKey
804 ##-------------- Logic for key handlers
807 def Move(self
, keySettingFunction
, key
, event
):
809 keySettingFunction(action
)
811 if not action
.has_key(key
):
814 if event
.ShiftDown():
815 if not self
.Selecting
:
816 self
.Selecting
= true
817 self
.SelectBegin
= (self
.cy
, self
.cx
)
819 self
.SelectEnd
= (self
.cy
, self
.cx
)
823 self
.Selecting
= false
825 self
.SelectNotify(self
.Selecting
, self
.SelectBegin
, self
.SelectEnd
)
829 def MoveSpecialKey(self
, event
, key
):
830 return self
.Move(self
.SetMoveSpecialFuncs
, key
, event
)
832 def MoveSpecialControlKey(self
, event
, key
):
833 if not event
.ControlDown():
835 return self
.Move(self
.SetMoveSpecialControlFuncs
, key
, event
)
837 def Dispatch(self
, keySettingFunction
, key
, event
):
839 keySettingFunction(action
)
840 if action
.has_key(key
):
846 def ModifierKey(self
, key
, event
, modifierKeyDown
, MappingFunc
):
847 if not modifierKeyDown
:
850 key
= self
.UnixKeyHack(key
)
855 if not self
.Dispatch(MappingFunc
, key
, event
):
859 def ControlKey(self
, event
, key
):
860 return self
.ModifierKey(key
, event
, event
.ControlDown(), self
.SetControlFuncs
)
862 def AltKey(self
, event
, key
):
863 return self
.ModifierKey(key
, event
, event
.AltDown(), self
.SetAltFuncs
)
865 def SpecialControlKey(self
, event
, key
):
866 if not event
.ControlDown():
868 if not self
.Dispatch(self
.SetSpecialControlFuncs
, key
, event
):
872 def ShiftKey(self
, event
, key
):
873 if not event
.ShiftDown():
875 return self
.Dispatch(self
.SetShiftFuncs
, key
, event
)
877 def NormalChar(self
, event
, key
):
881 if not self
.Dispatch(self
.SetSpecialFuncs
, key
, event
):
882 if (key
>31) and (key
<256):
883 self
.InsertChar(chr(key
))
888 self
.AdjustScrollbars()
890 def OnChar(self
, event
):
891 key
= event
.KeyCode()
892 filters
= [self
.AltKey
,
893 self
.MoveSpecialControlKey
,
895 self
.SpecialControlKey
,
899 for filter in filters
:
900 if filter(event
,key
):
904 #----------------------- Eliminate memory leaks
906 def OnDestroy(self
, event
):
912 self
.selectColor
= None
913 self
.scrollTimer
= None
914 self
.eofMarker
= None
916 #-------------------- Abstract methods for subclasses
921 def SelectNotify(self
, Selecting
, SelectionBegin
, SelectionEnd
):