#----------------------------------------------------------------------
-# Name: wxPython.lib.editor.wxEditor
+# Name: wxPython.lib.editor.Editor
# Purpose: An intelligent text editor with colorization capabilities.
#
# Original
# Copyright: (c) 1999 by Dirk Holtwick, 1999
# Licence: wxWindows license
#----------------------------------------------------------------------
+# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o 2.5 compatability update.
+#
+# 12/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o wxEditor -> Editor
+#
-import os, time
+import os
+import time
-from wxPython.wx import *
+import wx
-import selection
-import images
+import selection
+import images
#----------------------------
#----------------------------------------------------------------------
-class wxEditor(wxScrolledWindow):
+class Editor(wx.ScrolledWindow):
def __init__(self, parent, id,
- pos=wxDefaultPosition, size=wxDefaultSize, style=0):
+ pos=wx.DefaultPosition, size=wx.DefaultSize, style=0):
- wxScrolledWindow.__init__(self, parent, id,
+ wx.ScrolledWindow.__init__(self, parent, id,
pos, size,
- style|wxWANTS_CHARS)
+ style|wx.WANTS_CHARS)
self.isDrawing = False
self.sco_y = 0
def MapEvents(self):
- EVT_LEFT_DOWN(self, self.OnLeftDown)
- EVT_LEFT_UP(self, self.OnLeftUp)
- EVT_MOTION(self, self.OnMotion)
- EVT_SCROLLWIN(self, self.OnScroll)
- EVT_CHAR(self, self.OnChar)
- EVT_PAINT(self, self.OnPaint)
- EVT_SIZE(self, self.OnSize)
- EVT_WINDOW_DESTROY(self, self.OnDestroy)
- EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
+ self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
+ self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
+ self.Bind(wx.EVT_MOTION, self.OnMotion)
+ self.Bind(wx.EVT_SCROLLWIN, self.OnScroll)
+ self.Bind(wx.EVT_CHAR, self.OnChar)
+ self.Bind(wx.EVT_PAINT, self.OnPaint)
+ self.Bind(wx.EVT_SIZE, self.OnSize)
+ self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
+ self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
##------------------- Platform-specific stuff
def NiceFontForPlatform(self):
- if wxPlatform == "__WXMSW__":
- return wxFont(10, wxMODERN, wxNORMAL, wxNORMAL)
+ if wx.Platform == "__WXMSW__":
+ font = wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL)
else:
- return wxFont(12, wxMODERN, wxNORMAL, wxNORMAL, False)
+ font = wx.Font(12, wx.MODERN, wx.NORMAL, wx.NORMAL, False)
+ if wx.Platform == "__WXMAC__":
+ font.SetNoAntiAliasing()
+ return font
def UnixKeyHack(self, key):
+ #
# this will be obsolete when we get the new wxWindows patch
+ #
+ # 12/14/03 - jmg
+ #
+ # Which patch? I don't know if this is needed, but I don't know
+ # why it's here either. Play it safe; leave it in.
+ #
if key <= 26:
key += ord('a') - 1
return key
def SetCharDimensions(self):
# TODO: We need a code review on this. It appears that Linux
# improperly reports window dimensions when the scrollbar's there.
- self.bw, self.bh = self.GetClientSizeTuple()
+ self.bw, self.bh = self.GetClientSize()
- if wxPlatform == "__WXMSW__":
+ if wx.Platform == "__WXMSW__":
self.sh = self.bh / self.fh
self.sw = (self.bw / self.fw) - 1
else:
self.sh = self.bh / self.fh
if self.LinesInFile() >= self.sh:
- self.bw = self.bw - wxSystemSettings_GetSystemMetric(wxSYS_VSCROLL_X)
+ self.bw = self.bw - wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
self.sw = (self.bw / self.fw) - 1
self.sw = (self.bw / self.fw) - 1
if self.CalcMaxLineLen() >= self.sw:
- self.bh = self.bh - wxSystemSettings_GetSystemMetric(wxSYS_HSCROLL_Y)
+ self.bh = self.bh - wx.SystemSettings_GetMetric(wx.SYS_HSCROLL_Y)
self.sh = self.bh / self.fh
def UpdateView(self, dc = None):
if dc is None:
- dc = wxClientDC(self)
+ dc = wx.ClientDC(self)
if dc.Ok():
self.SetCharDimensions()
self.KeepCursorOnScreen()
- self.DrawSimpleCursor(0,0,dc, True)
+ self.DrawSimpleCursor(0,0, dc, True)
self.Draw(dc)
def OnPaint(self, event):
- dc = wxPaintDC(self)
+ dc = wx.PaintDC(self)
if self.isDrawing:
return
self.isDrawing = True
self.UpdateView(dc)
- wxCallAfter(self.AdjustScrollbars)
+ wx.CallAfter(self.AdjustScrollbars)
self.isDrawing = False
def OnEraseBackground(self, evt):
##-------------------- Drawing code
def InitFonts(self):
- dc = wxClientDC(self)
+ dc = wx.ClientDC(self)
self.font = self.NiceFontForPlatform()
dc.SetFont(self.font)
self.fw = dc.GetCharWidth()
self.fh = dc.GetCharHeight()
def SetColors(self):
- self.fgColor = wxNamedColour('black')
- self.bgColor = wxNamedColour('white')
- self.selectColor = wxColour(238, 220, 120) # r, g, b = emacsOrange
+ self.fgColor = wx.NamedColour('black')
+ self.bgColor = wx.NamedColour('white')
+ self.selectColor = wx.Colour(238, 220, 120) # r, g, b = emacsOrange
def InitDoubleBuffering(self):
pass
def Draw(self, odc=None):
if not odc:
- odc = wxClientDC(self)
+ odc = wx.ClientDC(self)
- bmp = wxEmptyBitmap(max(1,self.bw), max(1,self.bh))
- dc = wxBufferedDC(odc, bmp)
+ bmp = wx.EmptyBitmap(max(1,self.bw), max(1,self.bh))
+ dc = wx.BufferedDC(odc, bmp)
if dc.Ok():
dc.SetFont(self.font)
- dc.SetBackgroundMode(wxSOLID)
+ dc.SetBackgroundMode(wx.SOLID)
dc.SetTextBackground(self.bgColor)
dc.SetTextForeground(self.fgColor)
dc.Clear()
def DrawCursor(self, dc = None):
if not dc:
- dc = wxClientDC(self)
+ dc = wx.ClientDC(self)
if (self.LinesInFile())<self.cy: #-1 ?
self.cy = self.LinesInFile()-1
def DrawSimpleCursor(self, xp, yp, dc = None, old=False):
if not dc:
- dc = wxClientDC(self)
+ dc = wx.ClientDC(self)
if old:
xp = self.sco_x
szy = self.fh
x = xp * szx
y = yp * szy
- dc.Blit(x,y,szx,szy,dc,x,y,wxSRC_INVERT)
+ dc.Blit(x,y, szx,szy, dc, x,y, wx.SRC_INVERT)
self.sco_x = xp
self.sco_y = yp
self.EnableScrolling(False, False)
self.nextScrollTime = 0
self.SCROLLDELAY = 0.050 # seconds
- self.scrollTimer = wxTimer(self)
+ self.scrollTimer = wx.Timer(self)
self.scroller = Scroller(self)
def CanScroll(self):
def SetScrollTimer(self):
oneShot = True
self.scrollTimer.Start(1000*self.SCROLLDELAY/2, oneShot)
- EVT_TIMER(self, -1, self.OnTimer)
+ self.Bind(wx.EVT_TIMER, self.OnTimer)
def OnTimer(self, event):
- screenX, screenY = wxGetMousePosition()
+ screenX, screenY = wx.GetMousePosition()
x, y = self.ScreenToClientXY(screenX, screenY)
self.MouseToRow(y)
self.MouseToCol(x)
def HorizScroll(self, event, eventType):
maxLineLen = self.CalcMaxLineLen()
- if eventType == wxEVT_SCROLLWIN_LINEUP:
+ if eventType == wx.EVT_SCROLLWIN_LINEUP:
self.sx -= 1
- elif eventType == wxEVT_SCROLLWIN_LINEDOWN:
+ elif eventType == wx.EVT_SCROLLWIN_LINEDOWN:
self.sx += 1
- elif eventType == wxEVT_SCROLLWIN_PAGEUP:
+ elif eventType == wx.EVT_SCROLLWIN_PAGEUP:
self.sx -= self.sw
- elif eventType == wxEVT_SCROLLWIN_PAGEDOWN:
+ elif eventType == wx.EVT_SCROLLWIN_PAGEDOWN:
self.sx += self.sw
- elif eventType == wxEVT_SCROLLWIN_TOP:
+ elif eventType == wx.EVT_SCROLLWIN_TOP:
self.sx = self.cx = 0
- elif eventType == wxEVT_SCROLLWIN_BOTTOM:
+ elif eventType == wx.EVT_SCROLLWIN_BOTTOM:
self.sx = maxLineLen - self.sw
self.cx = maxLineLen
else:
self.HorizBoundaries()
def VertScroll(self, event, eventType):
- if eventType == wxEVT_SCROLLWIN_LINEUP:
+ if eventType == wx.EVT_SCROLLWIN_LINEUP:
self.sy -= 1
- elif eventType == wxEVT_SCROLLWIN_LINEDOWN:
+ elif eventType == wx.EVT_SCROLLWIN_LINEDOWN:
self.sy += 1
- elif eventType == wxEVT_SCROLLWIN_PAGEUP:
+ elif eventType == wx.EVT_SCROLLWIN_PAGEUP:
self.sy -= self.sh
- elif eventType == wxEVT_SCROLLWIN_PAGEDOWN:
+ elif eventType == wx.EVT_SCROLLWIN_PAGEDOWN:
self.sy += self.sh
- elif eventType == wxEVT_SCROLLWIN_TOP:
+ elif eventType == wx.EVT_SCROLLWIN_TOP:
self.sy = self.cy = 0
- elif eventType == wxEVT_SCROLLWIN_BOTTOM:
+ elif eventType == wx.EVT_SCROLLWIN_BOTTOM:
self.sy = self.LinesInFile() - self.sh
self.cy = self.LinesInFile()
else:
def OnScroll(self, event):
dir = event.GetOrientation()
eventType = event.GetEventType()
- if dir == wxHORIZONTAL:
+ if dir == wx.HORIZONTAL:
self.HorizScroll(event, eventType)
else:
self.VertScroll(event, eventType)
self.JoinLines()
self.TouchBuffer()
else:
- wxBell()
+ wx.Bell()
def Delete(self, event):
t = self.GetTextLine(self.cy)
def FindSelection(self):
if self.SelectEnd is None or self.SelectBegin is None:
- wxBell()
+ wx.Bell()
return None
(begin, end) = self.NormalizedSelect()
(bRow, bCol) = begin
self.SelectOff()
def CopyToClipboard(self, linesOfText):
- do = wxTextDataObject()
+ do = wx.TextDataObject()
do.SetText(os.linesep.join(linesOfText))
- wxTheClipboard.Open()
- wxTheClipboard.SetData(do)
- wxTheClipboard.Close()
+ wx.TheClipboard.Open()
+ wx.TheClipboard.SetData(do)
+ wx.TheClipboard.Close()
def SingleLineCopy(self, Row, bCol, eCol):
Line = self.GetTextLine(Row)
self.lines[bRow:eRow + 1] = [ModLine]
def OnPaste(self, event):
- do = wxTextDataObject()
- wxTheClipboard.Open()
- success = wxTheClipboard.GetData(do)
- wxTheClipboard.Close()
+ do = wx.TextDataObject()
+ wx.TheClipboard.Open()
+ success = wx.TheClipboard.GetData(do)
+ wx.TheClipboard.Close()
if success:
pastedLines = LineSplitter(do.GetText())
else:
- wxBell()
+ wx.Bell()
return
if len(pastedLines) == 0:
- wxBell()
+ wx.Bell()
return
elif len(pastedLines) == 1:
self.SingleLineInsert(pastedLines[0])
def MoveLeft(self, event):
if self.cx == 0:
if self.cy == 0:
- wxBell()
+ wx.Bell()
else:
self.cVert(-1)
self.cx = self.CurrentLineLength()
linelen = self.CurrentLineLength()
if self.cx == linelen:
if self.cy == len(self.lines) - 1:
- wxBell()
+ wx.Bell()
else:
self.cx = 0
self.cVert(1)
#-------------- Key handler mapping tables
def SetMoveSpecialFuncs(self, action):
- action[WXK_DOWN] = self.MoveDown
- action[WXK_UP] = self.MoveUp
- action[WXK_LEFT] = self.MoveLeft
- action[WXK_RIGHT] = self.MoveRight
- action[WXK_NEXT] = self.MovePageDown
- action[WXK_PRIOR] = self.MovePageUp
- action[WXK_HOME] = self.MoveHome
- action[WXK_END] = self.MoveEnd
+ action[wx.WXK_DOWN] = self.MoveDown
+ action[wx.WXK_UP] = self.MoveUp
+ action[wx.WXK_LEFT] = self.MoveLeft
+ action[wx.WXK_RIGHT] = self.MoveRight
+ action[wx.WXK_NEXT] = self.MovePageDown
+ action[wx.WXK_PRIOR] = self.MovePageUp
+ action[wx.WXK_HOME] = self.MoveHome
+ action[wx.WXK_END] = self.MoveEnd
def SetMoveSpecialControlFuncs(self, action):
- action[WXK_HOME] = self.MoveStartOfFile
- action[WXK_END] = self.MoveEndOfFile
+ action[wx.WXK_HOME] = self.MoveStartOfFile
+ action[wx.WXK_END] = self.MoveEndOfFile
def SetAltFuncs(self, action):
# subclass implements
action['x'] = self.OnCutSelection
def SetSpecialControlFuncs(self, action):
- action[WXK_INSERT] = self.OnCopySelection
+ action[wx.WXK_INSERT] = self.OnCopySelection
def SetShiftFuncs(self, action):
- action[WXK_DELETE] = self.OnCutSelection
- action[WXK_INSERT] = self.OnPaste
+ action[wx.WXK_DELETE] = self.OnCutSelection
+ action[wx.WXK_INSERT] = self.OnPaste
def SetSpecialFuncs(self, action):
- action[WXK_BACK] = self.BackSpace
- action[WXK_DELETE] = self.Delete
- action[WXK_RETURN] = self.BreakLine
- action[WXK_ESCAPE] = self.Escape
- action[WXK_TAB] = self.TabKey
+ action[wx.WXK_BACK] = self.BackSpace
+ action[wx.WXK_DELETE] = self.Delete
+ action[wx.WXK_RETURN] = self.BreakLine
+ action[wx.WXK_ESCAPE] = self.Escape
+ action[wx.WXK_TAB] = self.TabKey
##-------------- Logic for key handlers
except:
return False
if not self.Dispatch(MappingFunc, key, event):
- wxBell()
+ wx.Bell()
return True
def ControlKey(self, event, key):
if not event.ControlDown():
return False
if not self.Dispatch(self.SetSpecialControlFuncs, key, event):
- wxBell()
+ wx.Bell()
return True
def ShiftKey(self, event, key):
if (key>31) and (key<256):
self.InsertChar(chr(key))
else:
- wxBell()
+ wx.Bell()
return
self.UpdateView()
self.AdjustScrollbars()