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()
82 ##------------------ Init stuff
97 EVT_LEFT_DOWN(self
, self
.OnLeftDown
)
98 EVT_LEFT_UP(self
, self
.OnLeftUp
)
99 EVT_MOTION(self
, self
.OnMotion
)
100 EVT_SCROLLWIN(self
, self
.OnScroll
)
101 EVT_CHAR(self
, self
.OnChar
)
102 EVT_PAINT(self
, self
.OnPaint
)
103 EVT_SIZE(self
, self
.OnSize
)
104 EVT_WINDOW_DESTROY(self
, self
.OnDestroy
)
105 EVT_ERASE_BACKGROUND(self
, self
.OnEraseBackground
)
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 def OnEraseBackground(self
, evt
):
163 ##-------------------- Drawing code
166 dc
= wxClientDC(self
)
167 self
.font
= self
.NiceFontForPlatform()
168 dc
.SetFont(self
.font
)
169 self
.fw
= dc
.GetCharWidth()
170 self
.fh
= dc
.GetCharHeight()
173 self
.fgColor
= wxNamedColour('black')
174 self
.bgColor
= wxNamedColour('white')
175 self
.selectColor
= wxColour(238, 220, 120) # r, g, b = emacsOrange
177 def InitDoubleBuffering(self
):
178 bw
,bh
= self
.GetClientSizeTuple()
179 self
.mdc
= wxMemoryDC()
180 self
.mdc
.SelectObject(wxEmptyBitmap(bw
,bh
))
182 def DrawEditText(self
, t
, x
, y
, dc
):
183 dc
.DrawText(t
, x
* self
.fw
, y
* self
.fh
)
185 def DrawLine(self
, line
, dc
):
186 if self
.IsLine(line
):
189 dc
.SetTextForeground(self
.fgColor
)
190 fragments
= selection
.Selection(
191 self
.SelectBegin
, self
.SelectEnd
,
192 self
.sx
, self
.sw
, line
, t
)
194 for (data
, selected
) in fragments
:
196 dc
.SetTextBackground(self
.selectColor
)
197 if x
== 0 and len(data
) == 0 and len(fragments
) == 1:
200 dc
.SetTextBackground(self
.bgColor
)
201 self
.DrawEditText(data
, x
, line
- self
.sy
, dc
)
204 def Draw(self
, odc
=None):
206 odc
= wxClientDC(self
)
209 dc
.SetFont(self
.font
)
210 dc
.SelectObject(wxEmptyBitmap(self
.bw
,self
.bh
))
211 dc
.SetBackgroundMode(wxSOLID
)
212 dc
.SetTextBackground(self
.bgColor
)
213 dc
.SetTextForeground(self
.fgColor
)
215 for line
in range(self
.sy
, self
.sy
+ self
.sh
):
216 self
.DrawLine(line
, dc
)
217 if len(self
.lines
) < self
.sh
+ self
.sy
:
218 self
.DrawEofMarker(dc
)
219 odc
.Blit(0,0,self
.bw
,self
.bh
,dc
,0,0,wxCOPY
)
222 ##------------------ eofMarker stuff
224 def LoadImages(self
):
225 self
.eofMarker
= images
.GetBitmap(images
.EofImageData
)
227 def DrawEofMarker(self
,dc
):
229 y
= (len(self
.lines
) - self
.sy
) * self
.fh
231 dc
.DrawBitmap(self
.eofMarker
, x
, y
, hasTransparency
)
233 ##------------------ cursor-related functions
235 def DrawCursor(self
, dc
= None):
237 dc
= wxClientDC(self
)
239 if (self
.LinesInFile())<self
.cy
: #-1 ?
240 self
.cy
= self
.LinesInFile()-1
241 s
= self
.lines
[self
.cy
]
243 x
= self
.cx
- self
.sx
244 y
= self
.cy
- self
.sy
245 self
.DrawSimpleCursor(x
, y
, dc
)
248 def DrawSimpleCursor(self
, xp
, yp
, dc
= None, old
=false
):
250 dc
= wxClientDC(self
)
260 dc
.Blit(x
,y
,szx
,szy
,dc
,x
,y
,wxSRC_INVERT
)
264 ##-------- Enforcing screen boundaries, cursor movement
266 def CalcMaxLineLen(self
):
267 """get length of longest line on screen"""
269 for line
in self
.lines
[self
.sy
:self
.sy
+self
.sh
]:
270 if len(line
) >maxlen
:
274 def KeepCursorOnScreen(self
):
275 self
.sy
= ForceBetween(max(0, self
.cy
-self
.sh
), self
.sy
, self
.cy
)
276 self
.sx
= ForceBetween(max(0, self
.cx
-self
.sw
), self
.sx
, self
.cx
)
277 self
.AdjustScrollbars()
279 def HorizBoundaries(self
):
280 self
.SetCharDimensions()
281 maxLineLen
= self
.CalcMaxLineLen()
282 self
.sx
= ForceBetween(0, self
.sx
, max(self
.sw
, maxLineLen
- self
.sw
+ 1))
283 self
.cx
= ForceBetween(self
.sx
, self
.cx
, self
.sx
+ self
.sw
- 1)
285 def VertBoundaries(self
):
286 self
.SetCharDimensions()
287 self
.sy
= ForceBetween(0, self
.sy
, max(self
.sh
, self
.LinesInFile() - self
.sh
+ 1))
288 self
.cy
= ForceBetween(self
.sy
, self
.cy
, self
.sy
+ self
.sh
- 1)
290 def cVert(self
, num
):
291 self
.cy
= self
.cy
+ num
292 self
.cy
= ForceBetween(0, self
.cy
, self
.LinesInFile() - 1)
293 self
.sy
= ForceBetween(self
.cy
- self
.sh
+ 1, self
.sy
, self
.cy
)
294 self
.cx
= min(self
.cx
, self
.CurrentLineLength())
296 def cHoriz(self
, num
):
297 self
.cx
= self
.cx
+ num
298 self
.cx
= ForceBetween(0, self
.cx
, self
.CurrentLineLength())
299 self
.sx
= ForceBetween(self
.cx
- self
.sw
+ 1, self
.sx
, self
.cx
)
301 def AboveScreen(self
, row
):
304 def BelowScreen(self
, row
):
305 return row
>= self
.sy
+ self
.sh
307 def LeftOfScreen(self
, col
):
310 def RightOfScreen(self
, col
):
311 return col
>= self
.sx
+ self
.sw
313 ##----------------- data structure helper functions
318 def SetText(self
, lines
):
323 self
.AdjustScrollbars()
324 self
.UpdateView(None)
326 def IsLine(self
, lineNum
):
327 return (0<=lineNum
) and (lineNum
<self
.LinesInFile())
329 def GetTextLine(self
, lineNum
):
330 if self
.IsLine(lineNum
):
331 return self
.lines
[lineNum
]
334 def SetTextLine(self
, lineNum
, text
):
335 if self
.IsLine(lineNum
):
336 self
.lines
[lineNum
] = text
338 def CurrentLineLength(self
):
339 return len(self
.lines
[self
.cy
])
341 def LinesInFile(self
):
342 return len(self
.lines
)
344 def UnTouchBuffer(self
):
345 self
.bufferTouched
= FALSE
347 def BufferWasTouched(self
):
348 return self
.bufferTouched
350 def TouchBuffer(self
):
351 self
.bufferTouched
= TRUE
354 ##-------------------------- Mouse scroll timing functions
356 def InitScrolling(self
):
357 # we don't rely on the windows system to scroll for us; we just
358 # redraw the screen manually every time
359 self
.EnableScrolling(FALSE
, FALSE
)
360 self
.nextScrollTime
= 0
361 self
.SCROLLDELAY
= 0.050 # seconds
362 self
.scrollTimer
= wxTimer(self
)
363 self
.scroller
= Scroller(self
)
366 if time
.time() > self
.nextScrollTime
:
367 self
.nextScrollTime
= time
.time() + self
.SCROLLDELAY
372 def SetScrollTimer(self
):
374 self
.scrollTimer
.Start(1000*self
.SCROLLDELAY
/2, oneShot
)
375 EVT_TIMER(self
, -1, self
.OnTimer
)
377 def OnTimer(self
, event
):
378 screenX
, screenY
= wxGetMousePosition()
379 x
, y
= self
.ScreenToClientXY(screenX
, screenY
)
384 ##-------------------------- Mouse off screen functions
386 def HandleAboveScreen(self
, row
):
387 self
.SetScrollTimer()
393 def HandleBelowScreen(self
, row
):
394 self
.SetScrollTimer()
396 row
= self
.sy
+ self
.sh
397 row
= min(row
, self
.LinesInFile() - 1)
400 def HandleLeftOfScreen(self
, col
):
401 self
.SetScrollTimer()
407 def HandleRightOfScreen(self
, col
):
408 self
.SetScrollTimer()
410 col
= self
.sx
+ self
.sw
411 col
= min(col
, self
.CurrentLineLength())
414 ##------------------------ mousing functions
416 def MouseToRow(self
, mouseY
):
417 row
= self
.sy
+ (mouseY
/ self
.fh
)
418 if self
.AboveScreen(row
):
419 self
.HandleAboveScreen(row
)
420 elif self
.BelowScreen(row
):
421 self
.HandleBelowScreen(row
)
423 self
.cy
= min(row
, self
.LinesInFile() - 1)
425 def MouseToCol(self
, mouseX
):
426 col
= self
.sx
+ (mouseX
/ self
.fw
)
427 if self
.LeftOfScreen(col
):
428 self
.HandleLeftOfScreen(col
)
429 elif self
.RightOfScreen(col
):
430 self
.HandleRightOfScreen(col
)
432 self
.cx
= min(col
, self
.CurrentLineLength())
434 def MouseToCursor(self
, event
):
435 self
.MouseToRow(event
.GetY())
436 self
.MouseToCol(event
.GetX())
438 def OnMotion(self
, event
):
439 if event
.LeftIsDown():
440 self
.Selecting
= true
441 self
.MouseToCursor(event
)
444 def OnLeftDown(self
, event
):
445 self
.MouseToCursor(event
)
446 self
.SelectBegin
= (self
.cy
, self
.cx
)
447 self
.SelectEnd
= None
451 def OnLeftUp(self
, event
):
452 if self
.SelectEnd
is None:
455 self
.Selecting
= false
456 self
.SelectNotify(false
, self
.SelectBegin
, self
.SelectEnd
)
459 self
.scrollTimer
.Stop()
462 #------------------------- Scrolling
464 def HorizScroll(self
, event
, eventType
):
465 maxLineLen
= self
.CalcMaxLineLen()
467 if eventType
== wxEVT_SCROLLWIN_LINEUP
:
469 elif eventType
== wxEVT_SCROLLWIN_LINEDOWN
:
471 elif eventType
== wxEVT_SCROLLWIN_PAGEUP
:
473 elif eventType
== wxEVT_SCROLLWIN_PAGEDOWN
:
475 elif eventType
== wxEVT_SCROLLWIN_TOP
:
476 self
.sx
= self
.cx
= 0
477 elif eventType
== wxEVT_SCROLLWIN_BOTTOM
:
478 self
.sx
= maxLineLen
- self
.sw
481 self
.sx
= event
.GetPosition()
483 self
.HorizBoundaries()
485 def VertScroll(self
, event
, eventType
):
486 if eventType
== wxEVT_SCROLLWIN_LINEUP
:
488 elif eventType
== wxEVT_SCROLLWIN_LINEDOWN
:
490 elif eventType
== wxEVT_SCROLLWIN_PAGEUP
:
492 elif eventType
== wxEVT_SCROLLWIN_PAGEDOWN
:
494 elif eventType
== wxEVT_SCROLLWIN_TOP
:
495 self
.sy
= self
.cy
= 0
496 elif eventType
== wxEVT_SCROLLWIN_BOTTOM
:
497 self
.sy
= self
.LinesInFile() - self
.sh
498 self
.cy
= self
.LinesInFile()
500 self
.sy
= event
.GetPosition()
502 self
.VertBoundaries()
504 def OnScroll(self
, event
):
505 dir = event
.GetOrientation()
506 eventType
= event
.GetEventType()
507 if dir == wxHORIZONTAL
:
508 self
.HorizScroll(event
, eventType
)
510 self
.VertScroll(event
, eventType
)
514 def AdjustScrollbars(self
):
516 self
.SetCharDimensions()
517 self
.scroller
.SetScrollbars(
519 self
.CalcMaxLineLen()+3, max(self
.LinesInFile()+1, self
.sh
),
522 #------------ backspace, delete, return
524 def BreakLine(self
, event
):
525 if self
.IsLine(self
.cy
):
526 t
= self
.lines
[self
.cy
]
527 self
.lines
= self
.lines
[:self
.cy
] + [t
[:self
.cx
],t
[self
.cx
:]] + self
.lines
[self
.cy
+1:]
532 def InsertChar(self
,char
):
533 if self
.IsLine(self
.cy
):
534 t
= self
.lines
[self
.cy
]
535 t
= t
[:self
.cx
] + char
+ t
[self
.cx
:]
536 self
.SetTextLine(self
.cy
, t
)
541 t1
= self
.lines
[self
.cy
]
542 t2
= self
.lines
[self
.cy
+1]
544 self
.lines
= self
.lines
[:self
.cy
] + [t1
+ t2
] + self
.lines
[self
.cy
+2:]
548 def DeleteChar(self
,x
,y
,oldtext
):
549 newtext
= oldtext
[:x
] + oldtext
[x
+1:]
550 self
.SetTextLine(y
, newtext
)
554 def BackSpace(self
, event
):
555 t
= self
.GetTextLine(self
.cy
)
557 self
.DeleteChar(self
.cx
-1,self
.cy
,t
)
568 def Delete(self
, event
):
569 t
= self
.GetTextLine(self
.cy
)
571 self
.DeleteChar(self
.cx
,self
.cy
,t
)
574 if self
.cy
< len(self
.lines
) - 1:
578 def Escape(self
, event
):
581 def TabKey(self
, event
):
582 numSpaces
= self
.SpacesPerTab
- (self
.cx
% self
.SpacesPerTab
)
583 self
.SingleLineInsert(' ' * numSpaces
)
585 ##----------- selection routines
587 def SelectUpdate(self
):
588 self
.SelectEnd
= (self
.cy
, self
.cx
)
589 self
.SelectNotify(self
.Selecting
, self
.SelectBegin
, self
.SelectEnd
)
592 def NormalizedSelect(self
):
593 (begin
, end
) = (self
.SelectBegin
, self
.SelectEnd
)
606 def FindSelection(self
):
607 if self
.SelectEnd
is None or self
.SelectBegin
is None:
610 (begin
, end
) = self
.NormalizedSelect()
613 return (bRow
, bCol
, eRow
, eCol
)
616 self
.SelectBegin
= None
617 self
.SelectEnd
= None
618 self
.Selecting
= false
619 self
.SelectNotify(false
,None,None)
621 def CopySelection(self
, event
):
622 selection
= self
.FindSelection()
623 if selection
is None:
625 (bRow
, bCol
, eRow
, eCol
) = selection
628 self
.SingleLineCopy(bRow
, bCol
, eCol
)
630 self
.MultipleLineCopy(bRow
, bCol
, eRow
, eCol
)
632 def OnCopySelection(self
, event
):
633 self
.CopySelection(event
)
636 def CopyToClipboard(self
, linesOfText
):
637 do
= wxTextDataObject()
638 do
.SetText(string
.join(linesOfText
, os
.linesep
))
639 wxTheClipboard
.Open()
640 wxTheClipboard
.SetData(do
)
641 wxTheClipboard
.Close()
643 def SingleLineCopy(self
, Row
, bCol
, eCol
):
644 Line
= self
.GetTextLine(Row
)
645 self
.CopyToClipboard([Line
[bCol
:eCol
]])
647 def MultipleLineCopy(self
, bRow
, bCol
, eRow
, eCol
):
648 bLine
= self
.GetTextLine(bRow
)[bCol
:]
649 eLine
= self
.GetTextLine(eRow
)[:eCol
]
650 self
.CopyToClipboard([bLine
] + [l
for l
in self
.lines
[bRow
+ 1:eRow
]] + [eLine
])
652 def OnDeleteSelection(self
, event
):
653 selection
= self
.FindSelection()
654 if selection
is None:
656 (bRow
, bCol
, eRow
, eCol
) = selection
659 self
.SingleLineDelete(bRow
, bCol
, eCol
)
661 self
.MultipleLineDelete(bRow
, bCol
, eRow
, eCol
)
671 def SingleLineDelete(self
, Row
, bCol
, eCol
):
672 ModLine
= self
.GetTextLine(Row
)
673 ModLine
= ModLine
[:bCol
] + ModLine
[eCol
:]
674 self
.SetTextLine(Row
,ModLine
)
676 def MultipleLineDelete(self
, bRow
, bCol
, eRow
, eCol
):
677 bLine
= self
.GetTextLine(bRow
)
678 eLine
= self
.GetTextLine(eRow
)
679 ModLine
= bLine
[:bCol
] + eLine
[eCol
:]
680 self
.lines
[bRow
:eRow
+ 1] = [ModLine
]
682 def OnPaste(self
, event
):
683 do
= wxTextDataObject()
684 wxTheClipboard
.Open()
685 success
= wxTheClipboard
.GetData(do
)
686 wxTheClipboard
.Close()
688 pastedLines
= string
.split(do
.GetText(), '\n')
692 if len(pastedLines
) == 0:
695 elif len(pastedLines
) == 1:
696 self
.SingleLineInsert(pastedLines
[0])
698 self
.MultipleLinePaste(pastedLines
)
700 def SingleLineInsert(self
, newText
):
701 ModLine
= self
.GetTextLine(self
.cy
)
702 ModLine
= ModLine
[:self
.cx
] + newText
+ ModLine
[self
.cx
:]
703 self
.SetTextLine(self
.cy
, ModLine
)
704 self
.cHoriz(len(newText
))
708 def MultipleLinePaste(self
, pastedLines
):
709 FirstLine
= LastLine
= self
.GetTextLine(self
.cy
)
710 FirstLine
= FirstLine
[:self
.cx
] + pastedLines
[0]
711 LastLine
= pastedLines
[-1] + LastLine
[self
.cx
:]
713 NewSlice
= [FirstLine
]
714 NewSlice
+= [l
for l
in pastedLines
[1:-1]]
715 NewSlice
+= [LastLine
]
716 self
.lines
[self
.cy
:self
.cy
+ 1] = NewSlice
718 self
.cy
= self
.cy
+ len(pastedLines
)-1
719 self
.cx
= len(pastedLines
[-1])
723 def OnCutSelection(self
,event
):
724 self
.CopySelection(event
)
725 self
.OnDeleteSelection(event
)
727 #-------------- Keyboard movement implementations
729 def MoveDown(self
, event
):
732 def MoveUp(self
, event
):
735 def MoveLeft(self
, event
):
741 self
.cx
= self
.CurrentLineLength()
745 def MoveRight(self
, event
):
746 linelen
= self
.CurrentLineLength()
747 if self
.cx
== linelen
:
748 if self
.cy
== len(self
.lines
) - 1:
757 def MovePageDown(self
, event
):
760 def MovePageUp(self
, event
):
763 def MoveHome(self
, event
):
766 def MoveEnd(self
, event
):
767 self
.cx
= self
.CurrentLineLength()
769 def MoveStartOfFile(self
, event
):
773 def MoveEndOfFile(self
, event
):
774 self
.cy
= len(self
.lines
) - 1
775 self
.cx
= self
.CurrentLineLength()
777 #-------------- Key handler mapping tables
779 def SetMoveSpecialFuncs(self
, action
):
780 action
[WXK_DOWN
] = self
.MoveDown
781 action
[WXK_UP
] = self
.MoveUp
782 action
[WXK_LEFT
] = self
.MoveLeft
783 action
[WXK_RIGHT
] = self
.MoveRight
784 action
[WXK_NEXT
] = self
.MovePageDown
785 action
[WXK_PRIOR
] = self
.MovePageUp
786 action
[WXK_HOME
] = self
.MoveHome
787 action
[WXK_END
] = self
.MoveEnd
789 def SetMoveSpecialControlFuncs(self
, action
):
790 action
[WXK_HOME
] = self
.MoveStartOfFile
791 action
[WXK_END
] = self
.MoveEndOfFile
793 def SetAltFuncs(self
, action
):
794 # subclass implements
797 def SetControlFuncs(self
, action
):
798 action
['c'] = self
.OnCopySelection
799 action
['d'] = self
.OnDeleteSelection
800 action
['v'] = self
.OnPaste
801 action
['x'] = self
.OnCutSelection
803 def SetSpecialControlFuncs(self
, action
):
804 action
[WXK_INSERT
] = self
.OnCopySelection
806 def SetShiftFuncs(self
, action
):
807 action
[WXK_DELETE
] = self
.OnCutSelection
808 action
[WXK_INSERT
] = self
.OnPaste
810 def SetSpecialFuncs(self
, action
):
811 action
[WXK_BACK
] = self
.BackSpace
812 action
[WXK_DELETE
] = self
.Delete
813 action
[WXK_RETURN
] = self
.BreakLine
814 action
[WXK_ESCAPE
] = self
.Escape
815 action
[WXK_TAB
] = self
.TabKey
817 ##-------------- Logic for key handlers
820 def Move(self
, keySettingFunction
, key
, event
):
822 keySettingFunction(action
)
824 if not action
.has_key(key
):
827 if event
.ShiftDown():
828 if not self
.Selecting
:
829 self
.Selecting
= true
830 self
.SelectBegin
= (self
.cy
, self
.cx
)
832 self
.SelectEnd
= (self
.cy
, self
.cx
)
836 self
.Selecting
= false
838 self
.SelectNotify(self
.Selecting
, self
.SelectBegin
, self
.SelectEnd
)
842 def MoveSpecialKey(self
, event
, key
):
843 return self
.Move(self
.SetMoveSpecialFuncs
, key
, event
)
845 def MoveSpecialControlKey(self
, event
, key
):
846 if not event
.ControlDown():
848 return self
.Move(self
.SetMoveSpecialControlFuncs
, key
, event
)
850 def Dispatch(self
, keySettingFunction
, key
, event
):
852 keySettingFunction(action
)
853 if action
.has_key(key
):
859 def ModifierKey(self
, key
, event
, modifierKeyDown
, MappingFunc
):
860 if not modifierKeyDown
:
863 key
= self
.UnixKeyHack(key
)
868 if not self
.Dispatch(MappingFunc
, key
, event
):
872 def ControlKey(self
, event
, key
):
873 return self
.ModifierKey(key
, event
, event
.ControlDown(), self
.SetControlFuncs
)
875 def AltKey(self
, event
, key
):
876 return self
.ModifierKey(key
, event
, event
.AltDown(), self
.SetAltFuncs
)
878 def SpecialControlKey(self
, event
, key
):
879 if not event
.ControlDown():
881 if not self
.Dispatch(self
.SetSpecialControlFuncs
, key
, event
):
885 def ShiftKey(self
, event
, key
):
886 if not event
.ShiftDown():
888 return self
.Dispatch(self
.SetShiftFuncs
, key
, event
)
890 def NormalChar(self
, event
, key
):
894 if not self
.Dispatch(self
.SetSpecialFuncs
, key
, event
):
895 if (key
>31) and (key
<256):
896 self
.InsertChar(chr(key
))
901 self
.AdjustScrollbars()
903 def OnChar(self
, event
):
904 key
= event
.KeyCode()
905 filters
= [self
.AltKey
,
906 self
.MoveSpecialControlKey
,
908 self
.SpecialControlKey
,
912 for filter in filters
:
913 if filter(event
,key
):
917 #----------------------- Eliminate memory leaks
919 def OnDestroy(self
, event
):
925 self
.selectColor
= None
926 self
.scrollTimer
= None
927 self
.eofMarker
= None
929 #-------------------- Abstract methods for subclasses
934 def SelectNotify(self
, Selecting
, SelectionBegin
, SelectionEnd
):