controls/CustomStyledTextCtrl.py
changeset 1784 64beb9e9c749
parent 1747 6046ffa2280f
child 1847 6198190bc121
equal deleted inserted replaced
1729:31e63e25b4cc 1784:64beb9e9c749
    24 
    24 
    25 import wx
    25 import wx
    26 import wx.stc
    26 import wx.stc
    27 
    27 
    28 if wx.Platform == '__WXMSW__':
    28 if wx.Platform == '__WXMSW__':
    29     faces = { 'times': 'Times New Roman',
    29     faces = {
    30               'mono' : 'Courier New',
    30         'times': 'Times New Roman',
    31               'helv' : 'Arial',
    31         'mono':  'Courier New',
    32               'other': 'Comic Sans MS',
    32         'helv':  'Arial',
    33               'size' : 10,
    33         'other': 'Comic Sans MS',
    34              }
    34         'size':  10,
       
    35     }
    35 else:
    36 else:
    36     faces = { 'times': 'Times',
    37     faces = {
    37               'mono' : 'Courier',
    38         'times': 'Times',
    38               'helv' : 'Helvetica',
    39         'mono':  'Courier',
    39               'other': 'new century schoolbook',
    40         'helv':  'Helvetica',
    40               'size' : 12,
    41         'other': 'new century schoolbook',
    41              }
    42         'size':  12,
       
    43     }
    42 
    44 
    43 NAVIGATION_KEYS = [
    45 NAVIGATION_KEYS = [
    44     wx.WXK_END,
    46     wx.WXK_END,
    45     wx.WXK_HOME,
    47     wx.WXK_HOME,
    46     wx.WXK_LEFT,
    48     wx.WXK_LEFT,
    55     wx.WXK_NUMPAD_RIGHT,
    57     wx.WXK_NUMPAD_RIGHT,
    56     wx.WXK_NUMPAD_DOWN,
    58     wx.WXK_NUMPAD_DOWN,
    57     wx.WXK_NUMPAD_PAGEUP,
    59     wx.WXK_NUMPAD_PAGEUP,
    58     wx.WXK_NUMPAD_PAGEDOWN,
    60     wx.WXK_NUMPAD_PAGEDOWN,
    59     wx.WXK_NUMPAD_END]
    61     wx.WXK_NUMPAD_END]
       
    62 
    60 
    63 
    61 def GetCursorPos(old, new):
    64 def GetCursorPos(old, new):
    62     if old == "":
    65     if old == "":
    63         return 0
    66         return 0
    64     old_length = len(old)
    67     old_length = len(old)
    79         else:
    82         else:
    80             return i + 1
    83             return i + 1
    81     else:
    84     else:
    82         return None
    85         return None
    83 
    86 
       
    87 
    84 class CustomStyledTextCtrl(wx.stc.StyledTextCtrl):
    88 class CustomStyledTextCtrl(wx.stc.StyledTextCtrl):
    85     
    89 
    86     def __init__(self, *args, **kwargs):
    90     def __init__(self, *args, **kwargs):
    87         wx.stc.StyledTextCtrl.__init__(self, *args, **kwargs)
    91         wx.stc.StyledTextCtrl.__init__(self, *args, **kwargs)
    88         
    92 
    89         self.Bind(wx.EVT_MOTION, self.OnMotion)
    93         self.Bind(wx.EVT_MOTION, self.OnMotion)
    90         
    94 
    91     def OnMotion(self, event):
    95     def OnMotion(self, event):
    92         if wx.Platform == '__WXMSW__':
    96         if wx.Platform == '__WXMSW__':
    93             if not event.Dragging():
    97             if not event.Dragging():
    94                 x, y = event.GetPosition()
    98                 x, y = event.GetPosition()
    95                 margin_width = reduce(
    99                 margin_width = reduce(