X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7722248d7510121367c9d4db7af1156197c26e82..8f8c4b40456b5a4ef56a704c69570c7a1c86e714:/wxPython/wx/lib/editor/editor.py?ds=sidebyside diff --git a/wxPython/wx/lib/editor/editor.py b/wxPython/wx/lib/editor/editor.py index 57f1d77870..ac2ec28545 100644 --- a/wxPython/wx/lib/editor/editor.py +++ b/wxPython/wx/lib/editor/editor.py @@ -1,5 +1,5 @@ #---------------------------------------------------------------------- -# Name: wxPython.lib.editor.wxEditor +# Name: wxPython.lib.editor.Editor # Purpose: An intelligent text editor with colorization capabilities. # # Original @@ -20,13 +20,22 @@ # 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 #---------------------------- @@ -70,14 +79,14 @@ class Scroller: #---------------------------------------------------------------------- -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 @@ -108,26 +117,36 @@ class wxEditor(wxScrolledWindow): 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 @@ -141,39 +160,39 @@ class wxEditor(wxScrolledWindow): 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_GetMetric(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_GetMetric(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): @@ -182,16 +201,16 @@ class wxEditor(wxScrolledWindow): ##-------------------- 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 @@ -220,13 +239,13 @@ class wxEditor(wxScrolledWindow): 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() @@ -251,7 +270,7 @@ class wxEditor(wxScrolledWindow): def DrawCursor(self, dc = None): if not dc: - dc = wxClientDC(self) + dc = wx.ClientDC(self) if (self.LinesInFile())31) and (key<256): self.InsertChar(chr(key)) else: - wxBell() + wx.Bell() return self.UpdateView() self.AdjustScrollbars()