py_ext/PythonEditor.py
author Laurent Bessard
Wed, 24 Apr 2013 00:20:13 +0200
changeset 1057 3837e165b3f9
parent 920 1499a4d225db
child 1058 bb8ac451c28a
permissions -rw-r--r--
Added support for search in PythonEditor and IECCodeViewer
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
     1
import re
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
     2
import keyword
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
     3
738
413946c04c87 refactoring
laurent
parents: 734
diff changeset
     4
import wx
413946c04c87 refactoring
laurent
parents: 734
diff changeset
     5
import wx.grid
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
     6
import wx.stc as stc
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
     7
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
     8
from plcopen.plcopen import TestTextElement
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
     9
from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 753
diff changeset
    10
from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
    11
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
    12
[STC_PYTHON_ERROR, STC_PYTHON_SEARCH_RESULT] = range(15, 17)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
    13
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
    14
HIGHLIGHT_TYPES = {
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
    15
    ERROR_HIGHLIGHT: STC_PYTHON_ERROR,
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
    16
    SEARCH_RESULT_HIGHLIGHT: STC_PYTHON_SEARCH_RESULT,
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
    17
}
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
    18
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    19
if wx.Platform == '__WXMSW__':
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    20
    faces = { 'times': 'Times New Roman',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    21
              'mono' : 'Courier New',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    22
              'helv' : 'Arial',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    23
              'other': 'Comic Sans MS',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    24
              'size' : 10,
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    25
              'size2': 8,
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    26
             }
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    27
elif wx.Platform == '__WXMAC__':
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    28
    faces = { 'times': 'Times New Roman',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    29
              'mono' : 'Monaco',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    30
              'helv' : 'Arial',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    31
              'other': 'Comic Sans MS',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    32
              'size' : 12,
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    33
              'size2': 10,
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    34
             }
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    35
else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    36
    faces = { 'times': 'Times',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    37
              'mono' : 'Courier',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    38
              'helv' : 'Helvetica',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    39
              'other': 'new century schoolbook',
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    40
              'size' : 12,
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    41
              'size2': 10,
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    42
             }
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    43
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    44
[ID_PYTHONEDITOR,
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    45
] = [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
    46
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    47
def GetCursorPos(old, new):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    48
    old_length = len(old)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    49
    new_length = len(new)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    50
    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
    51
    i = 0
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    52
    for i in xrange(common_length):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    53
        if old[i] != new[i]:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    54
            break
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    55
    if old_length < new_length:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    56
        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
    57
            return i + new_length - old_length
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 i + new_length - old_length + 1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    60
    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
    61
        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
    62
            return i
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    63
        else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    64
            return i + 1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    65
    else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    66
        return None
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    67
738
413946c04c87 refactoring
laurent
parents: 734
diff changeset
    68
class PythonEditor(ConfTreeNodeEditor):
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    69
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    70
    fold_symbols = 3
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    71
    CONFNODEEDITOR_TABS = [
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    72
        (_("Python code"), "_create_PythonCodeEditor")]
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    73
    
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    74
    def _create_PythonCodeEditor(self, prnt):
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    75
        self.PythonCodeEditor = stc.StyledTextCtrl(id=ID_PYTHONEDITOR, parent=prnt,
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
    76
                 name="TextViewer", pos=wx.DefaultPosition, 
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
    77
                 size=wx.DefaultSize, style=0)
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    78
        self.PythonCodeEditor.ParentWindow = self
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    79
        
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    80
        self.PythonCodeEditor.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    81
        self.PythonCodeEditor.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    82
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    83
        self.PythonCodeEditor.SetLexer(stc.STC_LEX_PYTHON)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    84
        self.PythonCodeEditor.SetKeyWords(0, " ".join(keyword.kwlist))
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    85
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    86
        self.PythonCodeEditor.SetProperty("fold", "1")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    87
        self.PythonCodeEditor.SetProperty("tab.timmy.whinge.level", "1")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    88
        self.PythonCodeEditor.SetMargins(0,0)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    89
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    90
        self.PythonCodeEditor.SetViewWhiteSpace(False)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    91
        
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    92
        self.PythonCodeEditor.SetEdgeMode(stc.STC_EDGE_BACKGROUND)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    93
        self.PythonCodeEditor.SetEdgeColumn(78)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    94
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    95
        # Set up the numbers in the margin for margin #1
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    96
        self.PythonCodeEditor.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    97
        # Reasonable value for, say, 4-5 digits using a mono font (40 pix)
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
    98
        self.PythonCodeEditor.SetMarginWidth(1, 40)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    99
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   100
        # Setup a margin to hold fold markers
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   101
        self.PythonCodeEditor.SetMarginType(2, stc.STC_MARGIN_SYMBOL)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   102
        self.PythonCodeEditor.SetMarginMask(2, stc.STC_MASK_FOLDERS)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   103
        self.PythonCodeEditor.SetMarginSensitive(2, True)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   104
        self.PythonCodeEditor.SetMarginWidth(2, 12)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   105
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   106
        if self.fold_symbols == 0:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   107
            # Arrow pointing right for contracted folders, arrow pointing down for expanded
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   108
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_ARROWDOWN, "black", "black")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   109
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_ARROW, "black", "black")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   110
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_EMPTY, "black", "black")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   111
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_EMPTY, "black", "black")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   112
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_EMPTY,     "white", "black")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   113
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY,     "white", "black")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   114
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY,     "white", "black")
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   115
            
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   116
        elif self.fold_symbols == 1:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   117
            # Plus for contracted folders, minus for expanded
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   118
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_MINUS, "white", "black")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   119
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_PLUS,  "white", "black")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   120
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_EMPTY, "white", "black")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   121
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_EMPTY, "white", "black")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   122
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_EMPTY, "white", "black")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   123
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   124
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black")
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   125
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   126
        elif self.fold_symbols == 2:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   127
            # Like a flattened tree control using circular headers and curved joins
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   128
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_CIRCLEMINUS,          "white", "#404040")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   129
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_CIRCLEPLUS,           "white", "#404040")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   130
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_VLINE,                "white", "#404040")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   131
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_LCORNERCURVE,         "white", "#404040")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   132
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_CIRCLEPLUSCONNECTED,  "white", "#404040")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   133
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_CIRCLEMINUSCONNECTED, "white", "#404040")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   134
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNERCURVE,         "white", "#404040")
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   135
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   136
        elif self.fold_symbols == 3:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   137
            # Like a flattened tree control using square headers
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   138
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_BOXMINUS,          "white", "#808080")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   139
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_BOXPLUS,           "white", "#808080")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   140
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_VLINE,             "white", "#808080")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   141
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_LCORNER,           "white", "#808080")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   142
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_BOXPLUSCONNECTED,  "white", "#808080")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   143
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   144
            self.PythonCodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER,           "white", "#808080")
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   145
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   146
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   147
        self.PythonCodeEditor.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   148
        self.PythonCodeEditor.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   149
        self.PythonCodeEditor.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   150
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   151
        # Global default style
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   152
        if wx.Platform == '__WXMSW__':
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   153
            self.PythonCodeEditor.StyleSetSpec(stc.STC_STYLE_DEFAULT, 'fore:#000000,back:#FFFFFF,face:Courier New')
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   154
        elif wx.Platform == '__WXMAC__':
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   155
            # 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
   156
            # and use this whenever OS != MSW.
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   157
            self.PythonCodeEditor.StyleSetSpec(stc.STC_STYLE_DEFAULT, 'fore:#000000,back:#FFFFFF,face:Monaco')
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   158
        else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   159
            defsize = wx.SystemSettings.GetFont(wx.SYS_ANSI_FIXED_FONT).GetPointSize()
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   160
            self.PythonCodeEditor.StyleSetSpec(stc.STC_STYLE_DEFAULT, 'fore:#000000,back:#FFFFFF,face:Courier,size:%d'%defsize)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   161
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   162
        # Clear styles and revert to default.
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   163
        self.PythonCodeEditor.StyleClearAll()
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   164
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   165
        # 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
   166
        # The rest remains unchanged.
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   167
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   168
        # Line numbers in margin
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   169
        self.PythonCodeEditor.StyleSetSpec(stc.STC_STYLE_LINENUMBER,'fore:#000000,back:#99A9C2')    
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   170
        # Highlighted brace
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   171
        self.PythonCodeEditor.StyleSetSpec(stc.STC_STYLE_BRACELIGHT,'fore:#00009D,back:#FFFF00')
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   172
        # Unmatched brace
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   173
        self.PythonCodeEditor.StyleSetSpec(stc.STC_STYLE_BRACEBAD,'fore:#00009D,back:#FF0000')
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   174
        # Indentation guide
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   175
        self.PythonCodeEditor.StyleSetSpec(stc.STC_STYLE_INDENTGUIDE, "fore:#CDCDCD")
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   176
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   177
        # Python styles
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   178
        self.PythonCodeEditor.StyleSetSpec(stc.STC_P_DEFAULT, 'fore:#000000')
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   179
        # Comments
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   180
        self.PythonCodeEditor.StyleSetSpec(stc.STC_P_COMMENTLINE,  'fore:#008000,back:#F0FFF0')
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   181
        self.PythonCodeEditor.StyleSetSpec(stc.STC_P_COMMENTBLOCK, 'fore:#008000,back:#F0FFF0')
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   182
        # Numbers
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   183
        self.PythonCodeEditor.StyleSetSpec(stc.STC_P_NUMBER, 'fore:#008080')
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   184
        # Strings and characters
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   185
        self.PythonCodeEditor.StyleSetSpec(stc.STC_P_STRING, 'fore:#800080')
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   186
        self.PythonCodeEditor.StyleSetSpec(stc.STC_P_CHARACTER, 'fore:#800080')
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   187
        # Keywords
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   188
        self.PythonCodeEditor.StyleSetSpec(stc.STC_P_WORD, 'fore:#000080,bold')
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   189
        # Triple quotes
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   190
        self.PythonCodeEditor.StyleSetSpec(stc.STC_P_TRIPLE, 'fore:#800080,back:#FFFFEA')
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   191
        self.PythonCodeEditor.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, 'fore:#800080,back:#FFFFEA')
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   192
        # Class names
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   193
        self.PythonCodeEditor.StyleSetSpec(stc.STC_P_CLASSNAME, 'fore:#0000FF,bold')
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   194
        # Function names
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   195
        self.PythonCodeEditor.StyleSetSpec(stc.STC_P_DEFNAME, 'fore:#008080,bold')
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   196
        # Operators
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   197
        self.PythonCodeEditor.StyleSetSpec(stc.STC_P_OPERATOR, 'fore:#800000,bold')
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   198
        # 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
   199
        # to be an identifier if it doesn't match the above criterae
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   200
        self.PythonCodeEditor.StyleSetSpec(stc.STC_P_IDENTIFIER, 'fore:#000000')
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   201
        
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   202
        # Highlighting styles
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   203
        self.PythonCodeEditor.StyleSetSpec(STC_PYTHON_ERROR, "fore:#FF0000,back:#FFFF00")
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   204
        self.PythonCodeEditor.StyleSetSpec(STC_PYTHON_SEARCH_RESULT, "fore:#FFFFFF,back:#FFA500")
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   205
        
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   206
        # Caret color
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   207
        self.PythonCodeEditor.SetCaretForeground("BLUE")
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   208
        # Selection background
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   209
        self.PythonCodeEditor.SetSelBackground(1, '#66CCFF')
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   210
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   211
        self.PythonCodeEditor.SetSelBackground(True, wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT))
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   212
        self.PythonCodeEditor.SetSelForeground(True, wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT))
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   213
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   214
        # 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
   215
        #self.RegisterImage(1, images.getSmilesBitmap())
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   216
        self.PythonCodeEditor.RegisterImage(1, 
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   217
            wx.ArtProvider.GetBitmap(wx.ART_DELETE, size=(16,16)))
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   218
        self.PythonCodeEditor.RegisterImage(2, 
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   219
            wx.ArtProvider.GetBitmap(wx.ART_NEW, size=(16,16)))
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   220
        self.PythonCodeEditor.RegisterImage(3, 
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   221
            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
   222
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   223
        # Indentation and tab stuff
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   224
        self.PythonCodeEditor.SetIndent(4)               # Proscribed indent size for wx
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   225
        self.PythonCodeEditor.SetIndentationGuides(True) # Show indent guides
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   226
        self.PythonCodeEditor.SetBackSpaceUnIndents(True)# Backspace unindents rather than delete 1 space
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   227
        self.PythonCodeEditor.SetTabIndents(True)        # Tab key indents
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   228
        self.PythonCodeEditor.SetTabWidth(4)             # Proscribed tab size for wx
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   229
        self.PythonCodeEditor.SetUseTabs(False)          # Use spaces rather than tabs, or
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   230
                                        # TabTimmy will complain!    
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   231
        # White space
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   232
        self.PythonCodeEditor.SetViewWhiteSpace(False)   # Don't view white space
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   233
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   234
        # 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
   235
        # 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
   236
        # edit them that way.            
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   237
        self.PythonCodeEditor.SetEOLMode(stc.STC_EOL_LF)
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   238
        self.PythonCodeEditor.SetViewEOL(False)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   239
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   240
        # No right-edge mode indicator
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   241
        self.PythonCodeEditor.SetEdgeMode(stc.STC_EDGE_NONE)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   242
        
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   243
        self.PythonCodeEditor.SetModEventMask(stc.STC_MOD_BEFOREINSERT|stc.STC_MOD_BEFOREDELETE)
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   244
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   245
        self.PythonCodeEditor.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_PYTHONEDITOR)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   246
        self.PythonCodeEditor.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   247
        self.PythonCodeEditor.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_PYTHONEDITOR)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   248
        
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   249
        return self.PythonCodeEditor
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   250
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   251
    def __init__(self, parent, controler, window):
743
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 738
diff changeset
   252
        ConfTreeNodeEditor.__init__(self, parent, controler, window)
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   253
        
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   254
        self.DisableEvents = False
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   255
        self.CurrentAction = None
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   256
    
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   257
        self.Highlights = []
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   258
        self.SearchParams = None
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   259
        self.SearchResults = None
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   260
        self.CurrentFindHighlight = None
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   261
        
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   262
        self.RefreshHighlightsTimer = wx.Timer(self, -1)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   263
        self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   264
    
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   265
    def GetBufferState(self):
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   266
        return self.Controler.GetBufferState()
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   267
        
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   268
    def Undo(self):
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   269
        self.Controler.LoadPrevious()
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   270
        self.RefreshView()
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   271
            
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   272
    def Redo(self):
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   273
        self.Controler.LoadNext()
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   274
        self.RefreshView()
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   275
    
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   276
    def OnModification(self, event):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   277
        if not self.DisableEvents:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   278
            mod_type = event.GetModificationType()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   279
            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
   280
                if mod_type&wx.stc.STC_MOD_BEFOREINSERT:
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   281
                    if self.CurrentAction is None:
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   282
                        self.StartBuffering()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   283
                    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
   284
                        self.Controler.EndBuffering()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   285
                        self.StartBuffering()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   286
                    self.CurrentAction = ("Add", event.GetPosition())
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   287
                    wx.CallAfter(self.RefreshModel)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   288
                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
   289
                    if self.CurrentAction == None:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   290
                        self.StartBuffering()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   291
                    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
   292
                        self.Controler.EndBuffering()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   293
                        self.StartBuffering()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   294
                    self.CurrentAction = ("Delete", event.GetPosition())
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   295
                    wx.CallAfter(self.RefreshModel)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   296
        event.Skip()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   297
    
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   298
    def OnDoDrop(self, event):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   299
        self.ResetBuffer()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   300
        wx.CallAfter(self.RefreshModel)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   301
        event.Skip()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   302
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   303
    # Buffer the last model state
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   304
    def RefreshBuffer(self):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   305
        self.Controler.BufferPython()
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   306
        if self.ParentWindow is not None:
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   307
            self.ParentWindow.RefreshTitle()
534
80f05b17de1e Bug on FileMenu not refreshed when modifications fixed
laurent
parents: 427
diff changeset
   308
            self.ParentWindow.RefreshFileMenu()
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   309
            self.ParentWindow.RefreshEditMenu()
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   310
            self.ParentWindow.RefreshPageTitles()
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   311
    
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   312
    def StartBuffering(self):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   313
        self.Controler.StartBuffering()
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   314
        if self.ParentWindow is not None:
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   315
            self.ParentWindow.RefreshTitle()
534
80f05b17de1e Bug on FileMenu not refreshed when modifications fixed
laurent
parents: 427
diff changeset
   316
            self.ParentWindow.RefreshFileMenu()
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   317
            self.ParentWindow.RefreshEditMenu()
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   318
            self.ParentWindow.RefreshPageTitles()
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   319
    
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   320
    def ResetBuffer(self):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   321
        if self.CurrentAction != None:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   322
            self.Controler.EndBuffering()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   323
            self.CurrentAction = None
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   324
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   325
    def RefreshView(self):
751
a8dace95f965 Fixing bug on ConfNodeEditors refresh
laurent
parents: 743
diff changeset
   326
        ConfTreeNodeEditor.RefreshView(self)
a8dace95f965 Fixing bug on ConfNodeEditors refresh
laurent
parents: 743
diff changeset
   327
        
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   328
        self.ResetBuffer()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   329
        self.DisableEvents = True
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   330
        old_cursor_pos = self.PythonCodeEditor.GetCurrentPos()
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   331
        old_text = self.PythonCodeEditor.GetText()
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   332
        new_text = self.Controler.GetPythonCode()
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   333
        self.PythonCodeEditor.SetText(new_text)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   334
        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
   335
        if new_cursor_pos != None:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   336
            self.PythonCodeEditor.GotoPos(new_cursor_pos)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   337
        else:
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   338
            self.PythonCodeEditor.GotoPos(old_cursor_pos)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   339
        self.PythonCodeEditor.ScrollToColumn(0)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   340
        self.PythonCodeEditor.EmptyUndoBuffer()
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   341
        self.DisableEvents = False
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   342
        
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   343
        self.PythonCodeEditor.Colourise(0, -1)
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   344
        
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   345
        self.ShowHighlights()
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   346
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   347
    def RefreshModel(self):
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   348
        self.Controler.SetPythonCode(self.PythonCodeEditor.GetText())
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   349
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   350
    def OnKeyPressed(self, event):
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   351
        if self.PythonCodeEditor.CallTipActive():
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   352
            self.PythonCodeEditor.CallTipCancel()
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   353
        key = event.GetKeyCode()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   354
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   355
        if key == 32 and event.ControlDown():
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   356
            pos = self.PythonCodeEditor.GetCurrentPos()
738
413946c04c87 refactoring
laurent
parents: 734
diff changeset
   357
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   358
            # Code completion
738
413946c04c87 refactoring
laurent
parents: 734
diff changeset
   359
            if not event.ShiftDown():
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   360
                self.PythonCodeEditor.AutoCompSetIgnoreCase(False)  # so this needs to match
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   361
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   362
                # Images are specified with a appended "?type"
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   363
                self.PythonCodeEditor.AutoCompShow(0, " ".join([word + "?1" for word in keyword.kwlist]))
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   364
        else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   365
            event.Skip()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   367
    def OnKillFocus(self, event):
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   368
        self.PythonCodeEditor.AutoCompCancel()
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   369
        event.Skip()
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
    def OnUpdateUI(self, evt):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   372
        # check for matching braces
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   373
        braceAtCaret = -1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   374
        braceOpposite = -1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   375
        charBefore = None
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   376
        caretPos = self.PythonCodeEditor.GetCurrentPos()
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   377
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   378
        if caretPos > 0:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   379
            charBefore = self.PythonCodeEditor.GetCharAt(caretPos - 1)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   380
            styleBefore = self.PythonCodeEditor.GetStyleAt(caretPos - 1)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   381
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   382
        # check before
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   383
        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
   384
            braceAtCaret = caretPos - 1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   385
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   386
        # check after
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   387
        if braceAtCaret < 0:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   388
            charAfter = self.PythonCodeEditor.GetCharAt(caretPos)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   389
            styleAfter = self.PythonCodeEditor.GetStyleAt(caretPos)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   390
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   391
            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
   392
                braceAtCaret = caretPos
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   393
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   394
        if braceAtCaret >= 0:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   395
            braceOpposite = self.PythonCodeEditor.BraceMatch(braceAtCaret)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   396
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   397
        if braceAtCaret != -1  and braceOpposite == -1:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   398
            self.PythonCodeEditor.BraceBadLight(braceAtCaret)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   399
        else:
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   400
            self.PythonCodeEditor.BraceHighlight(braceAtCaret, braceOpposite)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   401
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   402
    def OnMarginClick(self, evt):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   403
        # fold and unfold as needed
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   404
        if evt.GetMargin() == 2:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   405
            if evt.GetShift() and evt.GetControl():
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   406
                self.FoldAll()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   407
            else:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   408
                lineClicked = self.PythonCodeEditor.LineFromPosition(evt.GetPosition())
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   409
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   410
                if self.PythonCodeEditor.GetFoldLevel(lineClicked) & stc.STC_FOLDLEVELHEADERFLAG:
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   411
                    if evt.GetShift():
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   412
                        self.PythonCodeEditor.SetFoldExpanded(lineClicked, True)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   413
                        self.Expand(lineClicked, True, True, 1)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   414
                    elif evt.GetControl():
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   415
                        if self.PythonCodeEditor.GetFoldExpanded(lineClicked):
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   416
                            self.PythonCodeEditor.SetFoldExpanded(lineClicked, False)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   417
                            self.Expand(lineClicked, False, True, 0)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   418
                        else:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   419
                            self.PythonCodeEditor.SetFoldExpanded(lineClicked, True)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   420
                            self.Expand(lineClicked, True, True, 100)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   421
                    else:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   422
                        self.PythonCodeEditor.ToggleFold(lineClicked)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   423
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   424
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   425
    def FoldAll(self):
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   426
        lineCount = self.PythonCodeEditor.GetLineCount()
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   427
        expanding = True
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
        # 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
   430
        for lineNum in range(lineCount):
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   431
            if self.PythonCodeEditor.GetFoldLevel(lineNum) & stc.STC_FOLDLEVELHEADERFLAG:
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   432
                expanding = not self.PythonCodeEditor.GetFoldExpanded(lineNum)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   433
                break
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
        lineNum = 0
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   436
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   437
        while lineNum < lineCount:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   438
            level = self.PythonCodeEditor.GetFoldLevel(lineNum)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   439
            if level & stc.STC_FOLDLEVELHEADERFLAG and \
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   440
               (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
   441
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   442
                if expanding:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   443
                    self.PythonCodeEditor.SetFoldExpanded(lineNum, True)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   444
                    lineNum = self.Expand(lineNum, True)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   445
                    lineNum = lineNum - 1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   446
                else:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   447
                    lastChild = self.PythonCodeEditor.GetLastChild(lineNum, -1)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   448
                    self.PythonCodeEditor.SetFoldExpanded(lineNum, False)
366
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 lastChild > lineNum:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   451
                        self.PythonCodeEditor.HideLines(lineNum+1, lastChild)
366
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
            lineNum = lineNum + 1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   454
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   455
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   456
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   457
    def Expand(self, line, doExpand, force=False, visLevels=0, level=-1):
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   458
        lastChild = self.PythonCodeEditor.GetLastChild(line, level)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   459
        line = line + 1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   460
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   461
        while line <= lastChild:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   462
            if force:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   463
                if visLevels > 0:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   464
                    self.PythonCodeEditor.ShowLines(line, line)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   465
                else:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   466
                    self.PythonCodeEditor.HideLines(line, line)
366
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
                if doExpand:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   469
                    self.PythonCodeEditor.ShowLines(line, line)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   470
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   471
            if level == -1:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   472
                level = self.PythonCodeEditor.GetFoldLevel(line)
366
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
            if level & stc.STC_FOLDLEVELHEADERFLAG:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   475
                if force:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   476
                    if visLevels > 1:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   477
                        self.PythonCodeEditor.SetFoldExpanded(line, True)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   478
                    else:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   479
                        self.PythonCodeEditor.SetFoldExpanded(line, False)
366
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
                    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
   482
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   483
                else:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   484
                    if doExpand and self.PythonCodeEditor.GetFoldExpanded(line):
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   485
                        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
   486
                    else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   487
                        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
   488
            else:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   489
                line = line + 1
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   490
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   491
        return line
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   492
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   493
    def Cut(self):
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   494
        self.ResetBuffer()
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   495
        self.DisableEvents = True
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   496
        self.PythonCodeEditor.CmdKeyExecute(wx.stc.STC_CMD_CUT)
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   497
        self.DisableEvents = False
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   498
        self.RefreshModel()
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   499
        self.RefreshBuffer()
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   500
    
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   501
    def Copy(self):
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   502
        self.PythonCodeEditor.CmdKeyExecute(wx.stc.STC_CMD_COPY)
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   503
    
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   504
    def Paste(self):
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   505
        self.ResetBuffer()
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   506
        self.DisableEvents = True
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 814
diff changeset
   507
        self.PythonCodeEditor.CmdKeyExecute(wx.stc.STC_CMD_PASTE)
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   508
        self.DisableEvents = False
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   509
        self.RefreshModel()
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
   510
        self.RefreshBuffer()
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   511
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   512
    def Find(self, direction, search_params):
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   513
        if self.SearchParams != search_params:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   514
            self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   515
            
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   516
            self.SearchParams = search_params
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   517
            criteria = {
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   518
                "raw_pattern": search_params["find_pattern"], 
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   519
                "pattern": re.compile(search_params["find_pattern"]),
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   520
                "case_sensitive": search_params["case_sensitive"],
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   521
                "regular_expression": search_params["regular_expression"],
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   522
                "filter": "all"}
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   523
            
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   524
            self.SearchResults = [
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   525
                (start, end, SEARCH_RESULT_HIGHLIGHT)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   526
                for start, end, text in 
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   527
                TestTextElement(self.PythonCodeEditor.GetText(), criteria)]
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   528
            self.CurrentFindHighlight = None
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   529
        
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   530
        if len(self.SearchResults) > 0:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   531
            if self.CurrentFindHighlight is not None:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   532
                old_idx = self.SearchResults.index(self.CurrentFindHighlight)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   533
                if self.SearchParams["wrap"]:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   534
                    idx = (old_idx + direction) % len(self.SearchResults)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   535
                else:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   536
                    idx = max(0, min(old_idx + direction, len(self.SearchResults) - 1))
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   537
                if idx != old_idx:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   538
                    self.RemoveHighlight(*self.CurrentFindHighlight)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   539
                    self.CurrentFindHighlight = self.SearchResults[idx]
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   540
                    self.AddHighlight(*self.CurrentFindHighlight)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   541
            else:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   542
                self.CurrentFindHighlight = self.SearchResults[0]
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   543
                self.AddHighlight(*self.CurrentFindHighlight)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   544
            
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   545
        else:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   546
            if self.CurrentFindHighlight is not None:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   547
                self.RemoveHighlight(*self.CurrentFindHighlight)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   548
            self.CurrentFindHighlight = None
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   549
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   550
#-------------------------------------------------------------------------------
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   551
#                        Highlights showing functions
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   552
#-------------------------------------------------------------------------------
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   553
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   554
    def OnRefreshHighlightsTimer(self, event):
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   555
        self.RefreshView()
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   556
        event.Skip()
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   557
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   558
    def ClearHighlights(self, highlight_type=None):
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   559
        if highlight_type is None:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   560
            self.Highlights = []
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   561
        else:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   562
            highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   563
            if highlight_type is not None:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   564
                self.Highlights = [(start, end, highlight) for (start, end, highlight) in self.Highlights if highlight != highlight_type]
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   565
        self.RefreshView()
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   566
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   567
    def AddHighlight(self, start, end, highlight_type):
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   568
        highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   569
        if highlight_type is not None:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   570
            self.Highlights.append((start, end, highlight_type))
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   571
            self.PythonCodeEditor.GotoPos(self.PythonCodeEditor.PositionFromLine(start[0]) + start[1])
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   572
            self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   573
            self.RefreshView()
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   574
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   575
    def RemoveHighlight(self, start, end, highlight_type):
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   576
        highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   577
        if (highlight_type is not None and 
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   578
            (start, end, highlight_type) in self.Highlights):
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   579
            self.Highlights.remove((start, end, highlight_type))
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   580
            self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   581
    
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   582
    def ShowHighlights(self):
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   583
        for start, end, highlight_type in self.Highlights:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   584
            if start[0] == 0:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   585
                highlight_start_pos = start[1]
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   586
            else:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   587
                highlight_start_pos = self.PythonCodeEditor.GetLineEndPosition(start[0] - 1) + start[1] + 1
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   588
            if end[0] == 0:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   589
                highlight_end_pos = end[1] - indent + 1
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   590
            else:
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   591
                highlight_end_pos = self.PythonCodeEditor.GetLineEndPosition(end[0] - 1) + end[1] + 2
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   592
            self.PythonCodeEditor.StartStyling(highlight_start_pos, 0xff)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   593
            self.PythonCodeEditor.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   594
            self.PythonCodeEditor.StartStyling(highlight_start_pos, 0x00)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   595
            self.PythonCodeEditor.SetStyling(len(self.PythonCodeEditor.GetText()) - highlight_end_pos, stc.STC_STYLE_DEFAULT)
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
   596