Laurent@1091: #!/usr/bin/env python Laurent@1091: # -*- coding: utf-8 -*- Laurent@1091: Laurent@1091: import wx Laurent@1091: import wx.stc Laurent@1091: Laurent@1091: if wx.Platform == '__WXMSW__': Laurent@1091: faces = { 'times': 'Times New Roman', Laurent@1091: 'mono' : 'Courier New', Laurent@1091: 'helv' : 'Arial', Laurent@1091: 'other': 'Comic Sans MS', Laurent@1091: 'size' : 10, Laurent@1091: } Laurent@1091: else: Laurent@1091: faces = { 'times': 'Times', Laurent@1091: 'mono' : 'Courier', Laurent@1091: 'helv' : 'Helvetica', Laurent@1091: 'other': 'new century schoolbook', Laurent@1091: 'size' : 12, Laurent@1091: } Laurent@1091: Laurent@1091: def GetCursorPos(old, new): Laurent@1091: if old == "": Laurent@1091: return 0 Laurent@1091: old_length = len(old) Laurent@1091: new_length = len(new) Laurent@1091: common_length = min(old_length, new_length) Laurent@1091: i = 0 Laurent@1091: for i in xrange(common_length): Laurent@1091: if old[i] != new[i]: Laurent@1091: break Laurent@1091: if old_length < new_length: Laurent@1091: if common_length > 0 and old[i] != new[i]: Laurent@1091: return i + new_length - old_length Laurent@1091: else: Laurent@1091: return i + new_length - old_length + 1 Laurent@1091: elif old_length > new_length or i < min(old_length, new_length) - 1: Laurent@1091: if common_length > 0 and old[i] != new[i]: Laurent@1091: return i Laurent@1091: else: Laurent@1091: return i + 1 Laurent@1091: else: Laurent@1091: return None Laurent@1091: Laurent@1091: class CustomStyledTextCtrl(wx.stc.StyledTextCtrl): Laurent@1091: Laurent@1091: def __init__(self, *args, **kwargs): Laurent@1092: wx.stc.StyledTextCtrl.__init__(self, *args, **kwargs) Laurent@1091: Laurent@1091: self.Bind(wx.EVT_MOTION, self.OnMotion) Laurent@1091: Laurent@1091: def OnMotion(self, event): Laurent@1091: if wx.Platform == '__WXMSW__': Laurent@1091: if not event.Dragging(): Laurent@1091: x, y = event.GetPosition() Laurent@1091: margin_width = reduce( Laurent@1091: lambda x, y: x + y, Laurent@1092: [self.GetMarginWidth(i) Laurent@1091: for i in xrange(3)], Laurent@1091: 0) Laurent@1091: if x <= margin_width: Laurent@1092: self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) Laurent@1091: else: Laurent@1092: self.SetCursor(wx.StockCursor(wx.CURSOR_IBEAM)) Laurent@1092: else: Laurent@1092: event.Skip() Laurent@1091: else: Laurent@1091: event.Skip() Laurent@1091: Laurent@1091: def AppendText(self, text): Laurent@1092: self.GotoPos(self.GetLength()) Laurent@1091: self.AddText(text)