plugins/python/PythonEditor.py
author ed
Fri, 04 Jun 2010 17:36:11 +0200
changeset 564 464d470bdbd7
parent 534 80f05b17de1e
child 654 9f6c091c316c
permissions -rw-r--r--
merge
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
     1
import  wx, wx.grid
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
     2
import  wx.stc  as  stc
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
     3
import keyword
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
     4
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
     5
if wx.Platform == '__WXMSW__':
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
     6
    faces = { 'times': 'Times New Roman',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
     7
              'mono' : 'Courier New',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
     8
              'helv' : 'Arial',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
     9
              'other': 'Comic Sans MS',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    10
              'size' : 10,
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    11
              'size2': 8,
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    12
             }
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    13
elif wx.Platform == '__WXMAC__':
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    14
    faces = { 'times': 'Times New Roman',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    15
              'mono' : 'Monaco',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    16
              'helv' : 'Arial',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    17
              'other': 'Comic Sans MS',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    18
              'size' : 12,
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    19
              'size2': 10,
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    20
             }
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    21
else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    22
    faces = { 'times': 'Times',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    23
              'mono' : 'Courier',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    24
              'helv' : 'Helvetica',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    25
              'other': 'new century schoolbook',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    26
              'size' : 12,
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    27
              'size2': 10,
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    28
             }
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    29
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    30
def AppendMenu(parent, help, id, kind, text):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    31
    if wx.VERSION >= (2, 6, 0):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    32
        parent.Append(help=help, id=id, kind=kind, text=text)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    33
    else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    34
        parent.Append(helpString=help, id=id, kind=kind, item=text)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    35
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    36
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    37
[ID_PYTHONEDITOR,
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    38
] = [wx.NewId() for _init_ctrls in range(1)]
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    39
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    40
def GetCursorPos(old, new):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    41
    old_length = len(old)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    42
    new_length = len(new)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    43
    common_length = min(old_length, new_length)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    44
    i = 0
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    45
    for i in xrange(common_length):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    46
        if old[i] != new[i]:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    47
            break
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    48
    if old_length < new_length:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    49
        if common_length > 0 and old[i] != new[i]:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    50
            return i + new_length - old_length
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    51
        else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    52
            return i + new_length - old_length + 1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    53
    elif old_length > new_length or i < min(old_length, new_length) - 1:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    54
        if common_length > 0 and old[i] != new[i]:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    55
            return i
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    56
        else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    57
            return i + 1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    58
    else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    59
        return None
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    60
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    61
class PythonEditor(stc.StyledTextCtrl):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    62
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    63
    fold_symbols = 3
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    64
    
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    65
    def __init__(self, parent, window, controler):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    66
        stc.StyledTextCtrl.__init__(self, parent, ID_PYTHONEDITOR, wx.DefaultPosition, 
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    67
                 wx.DefaultSize, 0)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    68
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    69
        self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    70
        self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    71
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    72
        self.SetLexer(stc.STC_LEX_PYTHON)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    73
        self.SetKeyWords(0, " ".join(keyword.kwlist))
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    74
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    75
        self.SetProperty("fold", "1")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    76
        self.SetProperty("tab.timmy.whinge.level", "1")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    77
        self.SetMargins(0,0)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    78
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    79
        self.SetViewWhiteSpace(False)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    80
        #self.SetBufferedDraw(False)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    81
        #self.SetViewEOL(True)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    82
        #self.SetEOLMode(stc.STC_EOL_CRLF)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    83
        #self.SetUseAntiAliasing(True)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    84
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    85
        self.SetEdgeMode(stc.STC_EDGE_BACKGROUND)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    86
        self.SetEdgeColumn(78)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    87
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    88
        # Set up the numbers in the margin for margin #1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    89
        self.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    90
        # Reasonable value for, say, 4-5 digits using a mono font (40 pix)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    91
        self.SetMarginWidth(1, 40)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    92
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    93
        # Setup a margin to hold fold markers
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    94
        self.SetMarginType(2, stc.STC_MARGIN_SYMBOL)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    95
        self.SetMarginMask(2, stc.STC_MASK_FOLDERS)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    96
        self.SetMarginSensitive(2, True)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    97
        self.SetMarginWidth(2, 12)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    98
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    99
        if self.fold_symbols == 0:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   100
            # Arrow pointing right for contracted folders, arrow pointing down for expanded
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   101
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_ARROWDOWN, "black", "black")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   102
            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_ARROW, "black", "black")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   103
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_EMPTY, "black", "black")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   104
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_EMPTY, "black", "black")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   105
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_EMPTY,     "white", "black")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   106
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY,     "white", "black")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   107
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY,     "white", "black")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   108
            
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   109
        elif self.fold_symbols == 1:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   110
            # Plus for contracted folders, minus for expanded
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   111
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_MINUS, "white", "black")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   112
            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_PLUS,  "white", "black")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   113
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_EMPTY, "white", "black")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   114
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_EMPTY, "white", "black")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   115
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_EMPTY, "white", "black")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   116
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   117
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   118
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   119
        elif self.fold_symbols == 2:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   120
            # Like a flattened tree control using circular headers and curved joins
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   121
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_CIRCLEMINUS,          "white", "#404040")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   122
            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_CIRCLEPLUS,           "white", "#404040")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   123
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_VLINE,                "white", "#404040")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   124
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_LCORNERCURVE,         "white", "#404040")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   125
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_CIRCLEPLUSCONNECTED,  "white", "#404040")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   126
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_CIRCLEMINUSCONNECTED, "white", "#404040")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   127
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNERCURVE,         "white", "#404040")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   128
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   129
        elif self.fold_symbols == 3:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   130
            # Like a flattened tree control using square headers
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   131
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_BOXMINUS,          "white", "#808080")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   132
            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_BOXPLUS,           "white", "#808080")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   133
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_VLINE,             "white", "#808080")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   134
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_LCORNER,           "white", "#808080")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   135
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_BOXPLUSCONNECTED,  "white", "#808080")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   136
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   137
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER,           "white", "#808080")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   138
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   139
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   140
        self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   141
        self.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   142
        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   143
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   144
        # Global default style
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   145
        if wx.Platform == '__WXMSW__':
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   146
            self.StyleSetSpec(stc.STC_STYLE_DEFAULT, 
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   147
                              'fore:#000000,back:#FFFFFF,face:Courier New')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   148
        elif wx.Platform == '__WXMAC__':
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   149
            # TODO: if this looks fine on Linux too, remove the Mac-specific case 
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   150
            # and use this whenever OS != MSW.
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   151
            self.StyleSetSpec(stc.STC_STYLE_DEFAULT, 
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   152
                              'fore:#000000,back:#FFFFFF,face:Monaco')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   153
        else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   154
            defsize = wx.SystemSettings.GetFont(wx.SYS_ANSI_FIXED_FONT).GetPointSize()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   155
            self.StyleSetSpec(stc.STC_STYLE_DEFAULT, 
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   156
                              'fore:#000000,back:#FFFFFF,face:Courier,size:%d'%defsize)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   157
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   158
        # Clear styles and revert to default.
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   159
        self.StyleClearAll()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   160
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   161
        # Following style specs only indicate differences from default.
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   162
        # The rest remains unchanged.
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   163
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   164
        # Line numbers in margin
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   165
        self.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER,'fore:#000000,back:#99A9C2')    
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   166
        # Highlighted brace
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   167
        self.StyleSetSpec(wx.stc.STC_STYLE_BRACELIGHT,'fore:#00009D,back:#FFFF00')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   168
        # Unmatched brace
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   169
        self.StyleSetSpec(wx.stc.STC_STYLE_BRACEBAD,'fore:#00009D,back:#FF0000')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   170
        # Indentation guide
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   171
        self.StyleSetSpec(wx.stc.STC_STYLE_INDENTGUIDE, "fore:#CDCDCD")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   172
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   173
        # Python styles
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   174
        self.StyleSetSpec(wx.stc.STC_P_DEFAULT, 'fore:#000000')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   175
        # Comments
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   176
        self.StyleSetSpec(wx.stc.STC_P_COMMENTLINE,  'fore:#008000,back:#F0FFF0')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   177
        self.StyleSetSpec(wx.stc.STC_P_COMMENTBLOCK, 'fore:#008000,back:#F0FFF0')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   178
        # Numbers
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   179
        self.StyleSetSpec(wx.stc.STC_P_NUMBER, 'fore:#008080')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   180
        # Strings and characters
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   181
        self.StyleSetSpec(wx.stc.STC_P_STRING, 'fore:#800080')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   182
        self.StyleSetSpec(wx.stc.STC_P_CHARACTER, 'fore:#800080')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   183
        # Keywords
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   184
        self.StyleSetSpec(wx.stc.STC_P_WORD, 'fore:#000080,bold')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   185
        # Triple quotes
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   186
        self.StyleSetSpec(wx.stc.STC_P_TRIPLE, 'fore:#800080,back:#FFFFEA')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   187
        self.StyleSetSpec(wx.stc.STC_P_TRIPLEDOUBLE, 'fore:#800080,back:#FFFFEA')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   188
        # Class names
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   189
        self.StyleSetSpec(wx.stc.STC_P_CLASSNAME, 'fore:#0000FF,bold')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   190
        # Function names
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   191
        self.StyleSetSpec(wx.stc.STC_P_DEFNAME, 'fore:#008080,bold')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   192
        # Operators
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   193
        self.StyleSetSpec(wx.stc.STC_P_OPERATOR, 'fore:#800000,bold')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   194
        # Identifiers. I leave this as not bold because everything seems
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   195
        # to be an identifier if it doesn't match the above criterae
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   196
        self.StyleSetSpec(wx.stc.STC_P_IDENTIFIER, 'fore:#000000')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   197
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   198
        # Caret color
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   199
        self.SetCaretForeground("BLUE")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   200
        # Selection background
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   201
        self.SetSelBackground(1, '#66CCFF')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   202
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   203
        self.SetSelBackground(True, wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT))
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   204
        self.SetSelForeground(True, wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT))
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   205
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   206
        # register some images for use in the AutoComplete box.
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   207
        #self.RegisterImage(1, images.getSmilesBitmap())
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   208
        self.RegisterImage(1, 
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   209
            wx.ArtProvider.GetBitmap(wx.ART_DELETE, size=(16,16)))
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   210
        self.RegisterImage(2, 
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   211
            wx.ArtProvider.GetBitmap(wx.ART_NEW, size=(16,16)))
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   212
        self.RegisterImage(3, 
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   213
            wx.ArtProvider.GetBitmap(wx.ART_COPY, size=(16,16)))
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   214
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   215
        # Indentation and tab stuff
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   216
        self.SetIndent(4)               # Proscribed indent size for wx
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   217
        self.SetIndentationGuides(True) # Show indent guides
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   218
        self.SetBackSpaceUnIndents(True)# Backspace unindents rather than delete 1 space
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   219
        self.SetTabIndents(True)        # Tab key indents
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   220
        self.SetTabWidth(4)             # Proscribed tab size for wx
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   221
        self.SetUseTabs(False)          # Use spaces rather than tabs, or
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   222
                                        # TabTimmy will complain!    
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   223
        # White space
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   224
        self.SetViewWhiteSpace(False)   # Don't view white space
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   225
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   226
        # EOL: Since we are loading/saving ourselves, and the
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   227
        # strings will always have \n's in them, set the STC to
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   228
        # edit them that way.            
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   229
        self.SetEOLMode(wx.stc.STC_EOL_LF)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   230
        self.SetViewEOL(False)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   231
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   232
        # No right-edge mode indicator
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   233
        self.SetEdgeMode(stc.STC_EDGE_NONE)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   234
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   235
        self.Controler = controler
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   236
        self.ParentWindow = window
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   237
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   238
        self.DisableEvents = True
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   239
        self.CurrentAction = None
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   240
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   241
        self.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT|wx.stc.STC_MOD_BEFOREDELETE)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   242
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   243
        self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_PYTHONEDITOR)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   244
        self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   245
        self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_PYTHONEDITOR)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   246
    
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   247
    def OnModification(self, event):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   248
        if not self.DisableEvents:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   249
            mod_type = event.GetModificationType()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   250
            if not (mod_type&wx.stc.STC_PERFORMED_UNDO or mod_type&wx.stc.STC_PERFORMED_REDO):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   251
                if mod_type&wx.stc.STC_MOD_BEFOREINSERT:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   252
                    if self.CurrentAction == None:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   253
                        self.StartBuffering()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   254
                    elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   255
                        self.Controler.EndBuffering()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   256
                        self.StartBuffering()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   257
                    self.CurrentAction = ("Add", event.GetPosition())
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   258
                elif mod_type&wx.stc.STC_MOD_BEFOREDELETE:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   259
                    if self.CurrentAction == None:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   260
                        self.StartBuffering()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   261
                    elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   262
                        self.Controler.EndBuffering()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   263
                        self.StartBuffering()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   264
                    self.CurrentAction = ("Delete", event.GetPosition())
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   265
        event.Skip()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   266
    
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   267
    def OnDoDrop(self, event):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   268
        self.ResetBuffer()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   269
        wx.CallAfter(self.RefreshModel)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   270
        event.Skip()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   271
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   272
    def IsViewing(self, name):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   273
        return self.Name == name
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   274
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   275
    # Buffer the last model state
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   276
    def RefreshBuffer(self):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   277
        self.Controler.BufferPython()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   278
        if self.ParentWindow:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   279
            self.ParentWindow.RefreshTitle()
534
80f05b17de1e Bug on FileMenu not refreshed when modifications fixed
laurent
parents: 427
diff changeset
   280
            self.ParentWindow.RefreshFileMenu()
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   281
            self.ParentWindow.RefreshEditMenu()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   282
    
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   283
    def StartBuffering(self):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   284
        self.Controler.StartBuffering()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   285
        if self.ParentWindow:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   286
            self.ParentWindow.RefreshTitle()
534
80f05b17de1e Bug on FileMenu not refreshed when modifications fixed
laurent
parents: 427
diff changeset
   287
            self.ParentWindow.RefreshFileMenu()
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   288
            self.ParentWindow.RefreshEditMenu()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   289
    
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   290
    def ResetBuffer(self):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   291
        if self.CurrentAction != None:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   292
            self.Controler.EndBuffering()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   293
            self.CurrentAction = None
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   294
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   295
    def RefreshView(self):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   296
        self.ResetBuffer()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   297
        self.DisableEvents = True
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   298
        old_cursor_pos = self.GetCurrentPos()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   299
        old_text = self.GetText()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   300
        new_text = self.Controler.GetPythonCode()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   301
        self.SetText(new_text)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   302
        new_cursor_pos = GetCursorPos(old_text, new_text)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   303
        if new_cursor_pos != None:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   304
            self.GotoPos(new_cursor_pos)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   305
        else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   306
            self.GotoPos(old_cursor_pos)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   307
        self.ScrollToColumn(0)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   308
        self.EmptyUndoBuffer()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   309
        self.DisableEvents = False
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   310
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   311
        self.Colourise(0, -1)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   312
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   313
    def RefreshModel(self):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   314
        self.Controler.SetPythonCode(self.GetText())
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   315
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   316
    def OnKeyPressed(self, event):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   317
        if self.CallTipActive():
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   318
            self.CallTipCancel()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   319
        key = event.GetKeyCode()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   320
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   321
        if key == 32 and event.ControlDown():
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   322
            pos = self.GetCurrentPos()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   323
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   324
            # Tips
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   325
            if event.ShiftDown():
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   326
                pass
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   327
##                self.CallTipSetBackground("yellow")
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   328
##                self.CallTipShow(pos, 'lots of of text: blah, blah, blah\n\n'
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   329
##                                 'show some suff, maybe parameters..\n\n'
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   330
##                                 'fubar(param1, param2)')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   331
            # Code completion
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   332
            else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   333
                self.AutoCompSetIgnoreCase(False)  # so this needs to match
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   334
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   335
                # Images are specified with a appended "?type"
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   336
                self.AutoCompShow(0, " ".join([word + "?1" for word in keyword.kwlist]))
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   337
        else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   338
            wx.CallAfter(self.RefreshModel)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   339
            event.Skip()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   340
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   341
    def OnKillFocus(self, event):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   342
        self.AutoCompCancel()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   343
        event.Skip()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   344
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   345
    def OnUpdateUI(self, evt):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   346
        # check for matching braces
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   347
        braceAtCaret = -1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   348
        braceOpposite = -1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   349
        charBefore = None
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   350
        caretPos = self.GetCurrentPos()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   351
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   352
        if caretPos > 0:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   353
            charBefore = self.GetCharAt(caretPos - 1)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   354
            styleBefore = self.GetStyleAt(caretPos - 1)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   355
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   356
        # check before
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   357
        if charBefore and chr(charBefore) in "[]{}()" and styleBefore == stc.STC_P_OPERATOR:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   358
            braceAtCaret = caretPos - 1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   359
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   360
        # check after
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   361
        if braceAtCaret < 0:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   362
            charAfter = self.GetCharAt(caretPos)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   363
            styleAfter = self.GetStyleAt(caretPos)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   364
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   365
            if charAfter and chr(charAfter) in "[]{}()" and styleAfter == stc.STC_P_OPERATOR:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   366
                braceAtCaret = caretPos
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   367
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   368
        if braceAtCaret >= 0:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   369
            braceOpposite = self.BraceMatch(braceAtCaret)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   370
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   371
        if braceAtCaret != -1  and braceOpposite == -1:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   372
            self.BraceBadLight(braceAtCaret)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   373
        else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   374
            self.BraceHighlight(braceAtCaret, braceOpposite)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   375
            #pt = self.PointFromPosition(braceOpposite)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   376
            #self.Refresh(True, wxRect(pt.x, pt.y, 5,5))
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   377
            #print pt
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   378
            #self.Refresh(False)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   379
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   380
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   381
    def OnMarginClick(self, evt):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   382
        # fold and unfold as needed
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   383
        if evt.GetMargin() == 2:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   384
            if evt.GetShift() and evt.GetControl():
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   385
                self.FoldAll()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   386
            else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   387
                lineClicked = self.LineFromPosition(evt.GetPosition())
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   388
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   389
                if self.GetFoldLevel(lineClicked) & stc.STC_FOLDLEVELHEADERFLAG:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   390
                    if evt.GetShift():
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   391
                        self.SetFoldExpanded(lineClicked, True)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   392
                        self.Expand(lineClicked, True, True, 1)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   393
                    elif evt.GetControl():
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   394
                        if self.GetFoldExpanded(lineClicked):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   395
                            self.SetFoldExpanded(lineClicked, False)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   396
                            self.Expand(lineClicked, False, True, 0)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   397
                        else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   398
                            self.SetFoldExpanded(lineClicked, True)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   399
                            self.Expand(lineClicked, True, True, 100)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   400
                    else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   401
                        self.ToggleFold(lineClicked)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   402
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   403
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   404
    def FoldAll(self):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   405
        lineCount = self.GetLineCount()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   406
        expanding = True
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   407
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   408
        # find out if we are folding or unfolding
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   409
        for lineNum in range(lineCount):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   410
            if self.GetFoldLevel(lineNum) & stc.STC_FOLDLEVELHEADERFLAG:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   411
                expanding = not self.GetFoldExpanded(lineNum)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   412
                break
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   413
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   414
        lineNum = 0
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   415
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   416
        while lineNum < lineCount:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   417
            level = self.GetFoldLevel(lineNum)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   418
            if level & stc.STC_FOLDLEVELHEADERFLAG and \
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   419
               (level & stc.STC_FOLDLEVELNUMBERMASK) == stc.STC_FOLDLEVELBASE:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   420
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   421
                if expanding:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   422
                    self.SetFoldExpanded(lineNum, True)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   423
                    lineNum = self.Expand(lineNum, True)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   424
                    lineNum = lineNum - 1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   425
                else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   426
                    lastChild = self.GetLastChild(lineNum, -1)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   427
                    self.SetFoldExpanded(lineNum, False)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   428
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   429
                    if lastChild > lineNum:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   430
                        self.HideLines(lineNum+1, lastChild)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   431
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   432
            lineNum = lineNum + 1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   433
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   434
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   435
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   436
    def Expand(self, line, doExpand, force=False, visLevels=0, level=-1):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   437
        lastChild = self.GetLastChild(line, level)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   438
        line = line + 1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   439
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   440
        while line <= lastChild:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   441
            if force:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   442
                if visLevels > 0:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   443
                    self.ShowLines(line, line)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   444
                else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   445
                    self.HideLines(line, line)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   446
            else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   447
                if doExpand:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   448
                    self.ShowLines(line, line)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   449
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   450
            if level == -1:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   451
                level = self.GetFoldLevel(line)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   452
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   453
            if level & stc.STC_FOLDLEVELHEADERFLAG:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   454
                if force:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   455
                    if visLevels > 1:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   456
                        self.SetFoldExpanded(line, True)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   457
                    else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   458
                        self.SetFoldExpanded(line, False)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   459
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   460
                    line = self.Expand(line, doExpand, force, visLevels-1)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   461
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   462
                else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   463
                    if doExpand and self.GetFoldExpanded(line):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   464
                        line = self.Expand(line, True, force, visLevels-1)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   465
                    else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   466
                        line = self.Expand(line, False, force, visLevels-1)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   467
            else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   468
                line = line + 1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   469
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   470
        return line
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   471
   
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   472
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   473
#-------------------------------------------------------------------------------
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   474
#                          PythonEditor Main Frame Class
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   475
#-------------------------------------------------------------------------------
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   476
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   477
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   478
[ID_PYTHONEDITORFRAME, 
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   479
] = [wx.NewId() for _init_ctrls in range(1)]
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   480
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   481
class PythonEditorFrame(wx.Frame):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   482
    
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   483
    if wx.VERSION < (2, 6, 0):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   484
        def Bind(self, event, function, id = None):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   485
            if id is not None:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   486
                event(self, id, function)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   487
            else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   488
                event(self, function)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   489
    
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   490
    def _init_coll_EditMenu_Items(self, parent):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   491
        AppendMenu(parent, help='', id=wx.ID_REFRESH,
415
339fa2542481 improved english spelling and grammar and internationalization updated
laurent
parents: 366
diff changeset
   492
              kind=wx.ITEM_NORMAL, text=_(u'Refresh\tCTRL+R'))
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   493
        AppendMenu(parent, help='', id=wx.ID_UNDO,
415
339fa2542481 improved english spelling and grammar and internationalization updated
laurent
parents: 366
diff changeset
   494
              kind=wx.ITEM_NORMAL, text=_(u'Undo\tCTRL+Z'))
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   495
        AppendMenu(parent, help='', id=wx.ID_REDO,
415
339fa2542481 improved english spelling and grammar and internationalization updated
laurent
parents: 366
diff changeset
   496
              kind=wx.ITEM_NORMAL, text=_(u'Redo\tCTRL+Y'))
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   497
        self.Bind(wx.EVT_MENU, self.OnRefreshMenu, id=wx.ID_REFRESH)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   498
        self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   499
        self.Bind(wx.EVT_MENU, self.OnRedoMenu, id=wx.ID_REDO)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   500
    
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   501
    def _init_coll_MenuBar_Menus(self, parent):
415
339fa2542481 improved english spelling and grammar and internationalization updated
laurent
parents: 366
diff changeset
   502
        parent.Append(menu=self.EditMenu, title=_(u'&Edit'))
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   503
    
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   504
    def _init_utils(self):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   505
        self.MenuBar = wx.MenuBar()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   506
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   507
        self.EditMenu = wx.Menu(title='')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   508
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   509
        self._init_coll_MenuBar_Menus(self.MenuBar)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   510
        self._init_coll_EditMenu_Items(self.EditMenu)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   511
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   512
    def _init_ctrls(self, prnt):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   513
        wx.Frame.__init__(self, id=ID_PYTHONEDITORFRAME, name=u'PythonEditor',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   514
              parent=prnt, pos=wx.DefaultPosition, size=wx.Size(800, 650),
415
339fa2542481 improved english spelling and grammar and internationalization updated
laurent
parents: 366
diff changeset
   515
              style=wx.DEFAULT_FRAME_STYLE, title=_(u'PythonEditor'))
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   516
        self._init_utils()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   517
        self.SetClientSize(wx.Size(1000, 600))
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   518
        self.SetMenuBar(self.MenuBar)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   519
        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   520
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   521
        self.Bind(wx.EVT_MENU, self.OnSaveMenu, id=wx.ID_SAVE)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   522
        accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL, 83, wx.ID_SAVE)])
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   523
        self.SetAcceleratorTable(accel)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   524
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   525
        if wx.VERSION >= (2, 8, 0):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   526
            self.AUIManager = wx.aui.AuiManager(self)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   527
            self.AUIManager.SetDockSizeConstraint(0.5, 0.5)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   528
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   529
        self.PythonEdited = PythonEditor(self, self, self.Controler)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   530
        if wx.VERSION < (2, 8, 0):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   531
            self.MainSizer = wx.BoxSizer(wx.VERTICAL)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   532
            self.MainSizer.AddWindow(self.PythonEdited, 0, border=0, flag=wx.GROW)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   533
            self.SetSizer(self.MainSizer)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   534
        else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   535
            self.AUIManager.AddPane(self.PythonEdited, wx.aui.AuiPaneInfo().CentrePane())
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   536
            
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   537
        self.StatusBar = wx.StatusBar( name='HelpBar',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   538
              parent=self, style=wx.ST_SIZEGRIP)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   539
        self.SetStatusBar(self.StatusBar)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   540
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   541
        if wx.VERSION >= (2, 8, 0):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   542
            self.AUIManager.Update()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   543
    
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   544
    def __init__(self, parent, controler):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   545
        self.Controler = controler
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   546
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   547
        self._init_ctrls(parent)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   548
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   549
        self.PythonEdited.RefreshView()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   550
        self.RefreshTitle()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   551
        self.RefreshEditMenu()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   552
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   553
    def OnCloseFrame(self, event):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   554
        if wx.VERSION >= (2, 8, 0):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   555
            self.AUIManager.UnInit()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   556
        if getattr(self, "_onclose", None) is not None:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   557
            self._onclose()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   558
        event.Skip()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   559
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   560
    def OnSaveMenu(self, event):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   561
        if getattr(self, "_onsave", None) != None:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   562
            self._onsave()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   563
        self.RefreshTitle()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   564
        self.RefreshEditMenu()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   565
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   566
    def RefreshTitle(self):
415
339fa2542481 improved english spelling and grammar and internationalization updated
laurent
parents: 366
diff changeset
   567
        title = _("PythonEditor")
339fa2542481 improved english spelling and grammar and internationalization updated
laurent
parents: 366
diff changeset
   568
        self.SetTitle("%s - %s"%(title, self.Controler.GetFilename()))
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   569
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   570
#-------------------------------------------------------------------------------
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   571
#                          Edit Project Menu Functions
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   572
#-------------------------------------------------------------------------------
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   573
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   574
    def RefreshEditMenu(self):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   575
        undo, redo = self.Controler.GetBufferState()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   576
        self.EditMenu.Enable(wx.ID_UNDO, undo)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   577
        self.EditMenu.Enable(wx.ID_REDO, redo)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   578
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   579
    def OnRefreshMenu(self, event):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   580
        self.PythonEdited.RefreshView()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   581
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   582
    def OnUndoMenu(self, event):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   583
        self.Controler.LoadPrevious()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   584
        self.PythonEdited.RefreshView()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   585
        self.RefreshTitle()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   586
        self.RefreshEditMenu()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   587
    
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   588
    def OnRedoMenu(self, event):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   589
        self.Controler.LoadNext()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   590
        self.PythonEdited.RefreshView()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   591
        self.RefreshTitle()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   592
        self.RefreshEditMenu()
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 415
diff changeset
   593
        
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 415
diff changeset
   594