TextViewer.py
author laurent
Sun, 09 Oct 2011 19:51:14 +0200
changeset 566 6014ef82a98a
parent 549 b0d6819119c3
child 582 aa41547baa2a
permissions -rw-r--r--
Adding support for searching text or regular expression in whole project
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     1
#!/usr/bin/env python
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     3
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     5
#based on the plcopen standard. 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     6
#
58
39cd981ff242 Changing file headers
lbessard
parents: 56
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     8
#
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    10
#
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    15
#
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
58
39cd981ff242 Changing file headers
lbessard
parents: 56
diff changeset
    19
#General Public License for more details.
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    20
#
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    24
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    25
import wx
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
    26
import wx.stc
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    27
from types import *
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    28
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    29
import re
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    30
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
    31
from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
    32
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    33
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    34
#                         Textual programs Viewer class
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    35
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    36
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    37
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    38
NEWLINE = "\n"
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    39
NUMBERS = [str(i) for i in xrange(10)]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    40
LETTERS = ['_']
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    41
for i in xrange(26):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    42
    LETTERS.append(chr(ord('a') + i))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    43
    LETTERS.append(chr(ord('A') + i))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    44
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
    45
[STC_PLC_WORD, STC_PLC_COMMENT, STC_PLC_NUMBER, STC_PLC_STRING, 
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
    46
 STC_PLC_VARIABLE, STC_PLC_PARAMETER, STC_PLC_FUNCTION, STC_PLC_JUMP, 
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
    47
 STC_PLC_ERROR, STC_PLC_SEARCH_RESULT] = range(10)
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
    48
[SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT] = range(6)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    49
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
    50
[ID_TEXTVIEWER,
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    51
] = [wx.NewId() for _init_ctrls in range(1)]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    52
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    53
if wx.Platform == '__WXMSW__':
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    54
    faces = { 'times': 'Times New Roman',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    55
              'mono' : 'Courier New',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    56
              'helv' : 'Arial',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    57
              'other': 'Comic Sans MS',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    58
              'size' : 10,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    59
             }
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    60
else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    61
    faces = { 'times': 'Times',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    62
              'mono' : 'Courier',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    63
              'helv' : 'Helvetica',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    64
              'other': 'new century schoolbook',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    65
              'size' : 12,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    66
             }
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    67
re_texts = {}
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    68
re_texts["letter"] = "[A-Za-z]"
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    69
re_texts["digit"] = "[0-9]"
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    70
re_texts["identifier"] = "((?:%(letter)s|(?:_(?:%(letter)s|%(digit)s)))(?:_?(?:%(letter)s|%(digit)s))*)"%re_texts
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    71
IDENTIFIER_MODEL = re.compile(re_texts["identifier"])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    72
LABEL_MODEL = re.compile("[ \t\n]%(identifier)s:[ \t\n]"%re_texts)
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
    73
EXTENSIBLE_PARAMETER = re.compile("IN[1-9][0-9]*$")
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    74
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
    75
HIGHLIGHT_TYPES = {
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
    76
    ERROR_HIGHLIGHT: STC_PLC_ERROR,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
    77
    SEARCH_RESULT_HIGHLIGHT: STC_PLC_SEARCH_RESULT,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
    78
}
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
    79
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    80
def GetCursorPos(old, new):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    81
    old_length = len(old)
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    82
    new_length = len(new)
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    83
    common_length = min(old_length, new_length)
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    84
    i = 0
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    85
    for i in xrange(common_length):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    86
        if old[i] != new[i]:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    87
            break
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    88
    if old_length < new_length:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    89
        if common_length > 0 and old[i] != new[i]:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    90
            return i + new_length - old_length
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    91
        else:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    92
            return i + new_length - old_length + 1
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    93
    elif old_length > new_length or i < min(old_length, new_length) - 1:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    94
        if common_length > 0 and old[i] != new[i]:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    95
            return i
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    96
        else:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    97
            return i + 1
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    98
    else:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    99
        return None
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   100
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   101
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   102
class TextViewer(wx.stc.StyledTextCtrl):
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   103
    
113
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 98
diff changeset
   104
    if wx.VERSION < (2, 6, 0):
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 98
diff changeset
   105
        def Bind(self, event, function, id = None):
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 98
diff changeset
   106
            if id is not None:
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 98
diff changeset
   107
                event(self, id, function)
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 98
diff changeset
   108
            else:
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 98
diff changeset
   109
                event(self, function)
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 98
diff changeset
   110
    
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   111
    def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""):
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 79
diff changeset
   112
        wx.stc.StyledTextCtrl.__init__(self, parent, ID_TEXTVIEWER, size=wx.Size(0, 0), style=0)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   113
        
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   114
        self.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   115
        self.CmdKeyAssign(ord('-'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMOUT)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   116
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   117
        self.SetViewWhiteSpace(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   118
        
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   119
        self.SetLexer(wx.stc.STC_LEX_CONTAINER)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   120
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   121
        # Global default styles for all languages
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   122
        self.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   123
        self.StyleClearAll()  # Reset all to be like the default
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   124
        
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   125
        self.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER,  "back:#C0C0C0,size:%(size)d" % faces)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   126
        self.SetSelBackground(1, "#E0E0E0")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   127
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   128
        # Highlighting styles
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   129
        self.StyleSetSpec(STC_PLC_WORD, "fore:#00007F,bold,size:%(size)d" % faces)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   130
        self.StyleSetSpec(STC_PLC_VARIABLE, "fore:#7F0000,size:%(size)d" % faces)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   131
        self.StyleSetSpec(STC_PLC_PARAMETER, "fore:#7F007F,size:%(size)d" % faces)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   132
        self.StyleSetSpec(STC_PLC_FUNCTION, "fore:#7F7F00,size:%(size)d" % faces)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   133
        self.StyleSetSpec(STC_PLC_COMMENT, "fore:#7F7F7F,size:%(size)d" % faces)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   134
        self.StyleSetSpec(STC_PLC_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   135
        self.StyleSetSpec(STC_PLC_STRING, "fore:#007F00,size:%(size)d" % faces)
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   136
        self.StyleSetSpec(STC_PLC_JUMP, "fore:#FF7FFF,size:%(size)d" % faces)
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   137
        self.StyleSetSpec(STC_PLC_ERROR, "fore:#FF0000,back:#FFFF00,size:%(size)d" % faces)
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   138
        self.StyleSetSpec(STC_PLC_SEARCH_RESULT, "fore:#FFFFFF,back:#FFA500,size:%(size)d" % faces)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   139
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   140
        # Indicators styles
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   141
        self.IndicatorSetStyle(0, wx.stc.STC_INDIC_SQUIGGLE)
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   142
        if window and controler:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   143
            self.IndicatorSetForeground(0, wx.RED)
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   144
        else:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   145
            self.IndicatorSetForeground(0, wx.WHITE)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   146
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   147
        # Line numbers in the margin
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   148
        self.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   149
        self.SetMarginWidth(1, 50)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   150
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   151
        # Indentation size
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   152
        self.SetTabWidth(2)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   153
        self.SetUseTabs(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   154
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   155
        self.Keywords = []
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   156
        self.Variables = {}
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   157
        self.Functions = {}
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   158
        self.TypeNames = []
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   159
        self.Jumps = []
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
   160
        self.EnumeratedValues = []
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   161
        self.DisableEvents = True
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   162
        self.TextSyntax = "ST"
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   163
        self.CurrentAction = None
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   164
        self.TagName = tagname
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   165
        self.Highlights = []
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   166
        self.Debug = debug
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   167
        self.InstancePath = instancepath
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   168
        self.ContextStack = []
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   169
        self.CallStack = []
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   170
        
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   171
        self.ParentWindow = window
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   172
        self.Controler = controler
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   173
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   174
        self.RefreshHighlightsTimer = wx.Timer(self, -1)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   175
        self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   176
411
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   177
        self.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT|
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   178
                             wx.stc.STC_MOD_BEFOREDELETE|
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   179
                             wx.stc.STC_PERFORMED_USER)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   180
79
b22f661cbcfb Fixed ws indent problem
etisserant
parents: 73
diff changeset
   181
        self.Bind(wx.stc.EVT_STC_STYLENEEDED, self.OnStyleNeeded, id=ID_TEXTVIEWER)
116
58b9b84e385f Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents: 113
diff changeset
   182
        if controler:
73
f2529e34e4b7 Prevent problems showing ST code after failed build
etisserant
parents: 68
diff changeset
   183
            self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
f2529e34e4b7 Prevent problems showing ST code after failed build
etisserant
parents: 68
diff changeset
   184
            self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_TEXTVIEWER)
f2529e34e4b7 Prevent problems showing ST code after failed build
etisserant
parents: 68
diff changeset
   185
            self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
f2529e34e4b7 Prevent problems showing ST code after failed build
etisserant
parents: 68
diff changeset
   186
            self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_TEXTVIEWER)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   187
    
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   188
    def __del__(self):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   189
        self.RefreshHighlightsTimer.Stop()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   190
    
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   191
    def SetTagName(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   192
        self.TagName = tagname
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   193
        
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   194
    def GetTagName(self):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   195
        return self.TagName
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   196
    
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   197
    def GetInstancePath(self):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   198
        return self.InstancePath
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   199
    
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   200
    def IsViewing(self, tagname):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   201
        if self.Debug:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   202
            return self.InstancePath == tagname
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   203
        else:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   204
            return self.TagName == tagname
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   205
    
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 391
diff changeset
   206
    def IsDebugging(self):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 391
diff changeset
   207
        return self.Debug
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 391
diff changeset
   208
    
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   209
    def SetMode(self, mode):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   210
        pass
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   211
    
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   212
    def OnModification(self, event):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   213
        if not self.DisableEvents:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   214
            mod_type = event.GetModificationType()
411
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   215
            if mod_type&wx.stc.STC_MOD_BEFOREINSERT:
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   216
                if self.CurrentAction == None:
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   217
                    self.StartBuffering()
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   218
                elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1:
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   219
                    self.Controler.EndBuffering()
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   220
                    self.StartBuffering()
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   221
                self.CurrentAction = ("Add", event.GetPosition())
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   222
                wx.CallAfter(self.RefreshModel)
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   223
            elif mod_type&wx.stc.STC_MOD_BEFOREDELETE:
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   224
                if self.CurrentAction == None:
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   225
                    self.StartBuffering()
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   226
                elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1:
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   227
                    self.Controler.EndBuffering()
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   228
                    self.StartBuffering()
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   229
                self.CurrentAction = ("Delete", event.GetPosition())
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   230
                wx.CallAfter(self.RefreshModel)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   231
        event.Skip()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   232
    
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 27
diff changeset
   233
    def OnDoDrop(self, event):
50
4610aafc884e Bugs fixed
lbessard
parents: 47
diff changeset
   234
        try:
4610aafc884e Bugs fixed
lbessard
parents: 47
diff changeset
   235
            values = eval(event.GetDragText())
4610aafc884e Bugs fixed
lbessard
parents: 47
diff changeset
   236
        except:
4610aafc884e Bugs fixed
lbessard
parents: 47
diff changeset
   237
            values = event.GetDragText()
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 27
diff changeset
   238
        if isinstance(values, tuple):
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   239
            message = None
523
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   240
            if values[1] in ["program", "debug"]:
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 27
diff changeset
   241
                event.SetDragText("")
523
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   242
            elif values[1] in ["functionBlock", "function"]:
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   243
                blockname = values[2]
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   244
                if len(values) > 3:
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   245
                    blockinputs = values[3]
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   246
                else:
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   247
                    blockinputs = None
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   248
                if values[1] != "function": 
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   249
                    if  blockname == "":
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   250
                        dialog = wx.TextEntryDialog(self.ParentWindow, "Block name", "Please enter a block name", "", wx.OK|wx.CANCEL|wx.CENTRE)
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   251
                        if dialog.ShowModal() == wx.ID_OK:
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   252
                            blockname = dialog.GetValue()
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   253
                        else:
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   254
                            return
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   255
                        dialog.Destroy()
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   256
                    if blockname.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]:
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   257
                        message = _("\"%s\" pou already exists!")%blockname
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   258
                    elif blockname.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]:
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   259
                        message = _("\"%s\" element for this pou already exists!")%blockname
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   260
                    else:
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   261
                        self.Controler.AddEditedElementPouVar(self.TagName, values[0], blockname)
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   262
                        self.ParentWindow.RefreshVariablePanel(self.TagName)
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   263
                        self.RefreshVariableTree()
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   264
                blockinfo = self.Controler.GetBlockType(values[0], blockinputs, self.Debug)
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   265
                hint = ',\n    '.join(
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   266
                            [ " " + fctdecl[0]+" := (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["inputs"]] +
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   267
                            [ " " + fctdecl[0]+" => (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["outputs"]])
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   268
                event.SetDragText(blockname+"(\n    "+hint+")")
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   269
            elif values[1] == "location":
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   270
                pou_name, pou_type = self.Controler.GetEditedElementType(self.TagName, self.Debug)
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   271
                if len(values) > 2 and pou_type == "program":
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   272
                    var_name = values[3]
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   273
                    if var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]:
448
93a2f2034f98 Bug with location Drag'n Drop on TextViewer fixed
laurent
parents: 437
diff changeset
   274
                        message = _("\"%s\" pou already exists!")%var_name
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   275
                    elif var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]:
448
93a2f2034f98 Bug with location Drag'n Drop on TextViewer fixed
laurent
parents: 437
diff changeset
   276
                        message = _("\"%s\" element for this pou already exists!")%var_name
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   277
                    else:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   278
                        if values[2] is not None:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   279
                            var_type = values[2]
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   280
                        else:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   281
                            var_type = LOCATIONDATATYPES.get(values[0][2], ["BOOL"])[0]
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   282
                        self.Controler.AddEditedElementPouVar(self.TagName, var_type, var_name, values[0], values[4])
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   283
                        self.ParentWindow.RefreshVariablePanel(self.TagName)
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   284
                        self.RefreshVariableTree()
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   285
                        event.SetDragText(var_name)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   286
                else:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   287
                    event.SetDragText("")
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   288
            elif values[3] == self.TagName:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   289
                self.ResetBuffer()
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   290
                event.SetDragText(values[0])
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   291
                wx.CallAfter(self.RefreshModel)
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   292
            else:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   293
                message = _("Variable don't belong to this POU!")
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   294
            if message is not None:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   295
                dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   296
                dialog.ShowModal()
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   297
                dialog.Destroy()
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   298
                event.SetDragText("")
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 27
diff changeset
   299
        event.Skip()
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 27
diff changeset
   300
    
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   301
    def SetTextSyntax(self, syntax):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   302
        self.TextSyntax = syntax
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   303
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   304
    def SetKeywords(self, keywords):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   305
        self.Keywords = [keyword.upper() for keyword in keywords]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   306
        self.Colourise(0, -1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   307
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   308
    def RefreshJumpList(self):
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   309
        if self.TextSyntax != "IL":
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   310
            self.Jumps = [jump.upper() for jump in LABEL_MODEL.findall(self.GetText())]
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   311
            self.Colourise(0, -1)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   312
    
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   313
    # Buffer the last model state
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   314
    def RefreshBuffer(self):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   315
        self.Controler.BufferProject()
116
58b9b84e385f Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents: 113
diff changeset
   316
        if self.ParentWindow:
58b9b84e385f Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents: 113
diff changeset
   317
            self.ParentWindow.RefreshTitle()
485
d5ebb8eac934 Bug on TextViewer fixed : FileMenu not refreshed when text modified
laurent
parents: 448
diff changeset
   318
            self.ParentWindow.RefreshFileMenu()
116
58b9b84e385f Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents: 113
diff changeset
   319
            self.ParentWindow.RefreshEditMenu()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   320
    
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   321
    def StartBuffering(self):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   322
        self.Controler.StartBuffering()
116
58b9b84e385f Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents: 113
diff changeset
   323
        if self.ParentWindow:
58b9b84e385f Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents: 113
diff changeset
   324
            self.ParentWindow.RefreshTitle()
485
d5ebb8eac934 Bug on TextViewer fixed : FileMenu not refreshed when text modified
laurent
parents: 448
diff changeset
   325
            self.ParentWindow.RefreshFileMenu()
116
58b9b84e385f Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents: 113
diff changeset
   326
            self.ParentWindow.RefreshEditMenu()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   327
    
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   328
    def ResetBuffer(self):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   329
        if self.CurrentAction != None:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   330
            self.Controler.EndBuffering()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   331
            self.CurrentAction = None
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   332
    
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   333
    def RefreshView(self):
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   334
        self.ResetBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   335
        self.DisableEvents = True
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   336
        old_cursor_pos = self.GetCurrentPos()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   337
        old_text = self.GetText()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   338
        new_text = self.Controler.GetEditedElementText(self.TagName, self.Debug)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   339
        self.SetText(new_text)
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   340
        new_cursor_pos = GetCursorPos(old_text, new_text)
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   341
        if new_cursor_pos != None:
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 79
diff changeset
   342
            self.GotoPos(new_cursor_pos)
c798a68c5560 Lots of bugs fixed
lbessard
parents: 79
diff changeset
   343
        else:
c798a68c5560 Lots of bugs fixed
lbessard
parents: 79
diff changeset
   344
            self.GotoPos(old_cursor_pos)
c798a68c5560 Lots of bugs fixed
lbessard
parents: 79
diff changeset
   345
        self.ScrollToColumn(0)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   346
        self.RefreshJumpList()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   347
        self.EmptyUndoBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   348
        self.DisableEvents = False
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   349
        
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   350
        self.RefreshVariableTree()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   351
        
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   352
        self.TypeNames = [typename.upper() for typename in self.Controler.GetDataTypes(self.TagName, True, self.Debug)]
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   353
        self.EnumeratedValues = [value.upper() for value in self.Controler.GetEnumeratedDataValues()]
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   354
        
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   355
        self.Functions = {}
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   356
        for category in self.Controler.GetBlockTypes(self.TagName, self.Debug):
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   357
            for blocktype in category["list"]:
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   358
                blockname = blocktype["name"].upper()
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   359
                if blocktype["type"] == "function" and blockname not in self.Keywords and blockname not in self.Variables.keys():
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   360
                    interface = dict([(name, {}) for name, type, modifier in blocktype["inputs"] + blocktype["outputs"] if name != ''])
549
b0d6819119c3 Adding support for syntax highlighting for EN and ENO parameters in formal function and function blocs in textual editor
laurent
parents: 546
diff changeset
   361
                    for param in ["EN", "ENO"]:
b0d6819119c3 Adding support for syntax highlighting for EN and ENO parameters in formal function and function blocs in textual editor
laurent
parents: 546
diff changeset
   362
                        if not interface.has_key(param):
b0d6819119c3 Adding support for syntax highlighting for EN and ENO parameters in formal function and function blocs in textual editor
laurent
parents: 546
diff changeset
   363
                            interface[param] = {}
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   364
                    if self.Functions.has_key(blockname):
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   365
                        self.Functions[blockname]["interface"].update(interface)
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   366
                        self.Functions[blockname]["extensible"] |= blocktype["extensible"]
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   367
                    else:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   368
                        self.Functions[blockname] = {"interface": interface,
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   369
                                                     "extensible": blocktype["extensible"]}
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   370
        self.Colourise(0, -1)
297
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 295
diff changeset
   371
    
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   372
    def RefreshVariableTree(self):
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   373
        words = self.TagName.split("::")
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   374
        self.Variables = self.GenerateVariableTree([(variable["Name"], variable["Type"], variable["Tree"]) for variable in self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)])
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   375
        if self.Controler.GetEditedElementType(self.TagName, self.Debug)[1] == "function" or words[0] == "T" and self.TextSyntax == "IL":
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   376
            return_type = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug)
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   377
            if return_type is not None:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   378
                var_tree, var_dimension = self.Controler.GenerateVarTree(return_type, self.Debug)
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   379
                self.Variables[words[-1].upper()] = self.GenerateVariableTree(var_tree)
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   380
            else:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   381
                self.Variables[words[-1].upper()] = {}
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 411
diff changeset
   382
    
297
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 295
diff changeset
   383
    def GenerateVariableTree(self, list):
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 295
diff changeset
   384
        tree = {}
299
15669fe26e56 Adding support for generating real array dimension in variable blocks
lbessard
parents: 297
diff changeset
   385
        for var_name, var_type, (var_tree, var_dimension) in list:
300
34d1402c0e24 Bug with variable tree generation fixed
lbessard
parents: 299
diff changeset
   386
            tree[var_name.upper()] = self.GenerateVariableTree(var_tree)
297
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 295
diff changeset
   387
        return tree
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 295
diff changeset
   388
    
145
4fb225afddf4 Adding scaling
lbessard
parents: 136
diff changeset
   389
    def RefreshScaling(self, refresh=True):
4fb225afddf4 Adding scaling
lbessard
parents: 136
diff changeset
   390
        pass
4fb225afddf4 Adding scaling
lbessard
parents: 136
diff changeset
   391
    
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   392
    def IsValidVariable(self, name, context):
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   393
        return context is not None and context.get(name, None) is not None
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   394
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   395
    def IsCallParameter(self, name, call):
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   396
        if call is not None:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   397
            return (call["interface"].get(name.upper(), None) is not None or 
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   398
                    call["extensible"] and EXTENSIBLE_PARAMETER.match(name.upper()) is not None)
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   399
        return False
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   400
        
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   401
    def OnStyleNeeded(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   402
        self.TextChanged = True
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   403
        line = self.LineFromPosition(self.GetEndStyled())
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   404
        if line == 0:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   405
            start_pos = last_styled_pos = 0
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   406
        else:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   407
            start_pos = last_styled_pos = self.GetLineEndPosition(line - 1) + 1
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   408
        end_pos = event.GetPosition()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   409
        self.StartStyling(start_pos, 0xff)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   410
        
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   411
        current_context = self.Variables
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   412
        current_call = None
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   413
        
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   414
        current_pos = last_styled_pos
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   415
        state = SPACE
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   416
        line = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   417
        word = ""
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   418
        while current_pos < end_pos:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   419
            char = chr(self.GetCharAt(current_pos)).upper()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   420
            line += char
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   421
            if char == NEWLINE:
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   422
                self.ContextStack = []
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   423
                current_context = self.Variables
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   424
                if state == COMMENT:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   425
                    self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_COMMENT)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   426
                elif state == NUMBER:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   427
                    self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   428
                elif state == WORD:
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   429
                    if word in self.Keywords or word in self.TypeNames:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   430
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   431
                    elif self.IsValidVariable(word, current_context):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   432
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   433
                    elif self.IsCallParameter(word, current_call):
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   434
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   435
                    elif word in self.Functions:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   436
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION)
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   437
                    elif self.TextSyntax == "IL" and word in self.Jumps:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   438
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
   439
                    elif word in self.EnumeratedValues:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   440
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   441
                    else:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   442
                        self.SetStyling(current_pos - last_styled_pos, 31)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   443
                        if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   444
                            self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   445
                            self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   446
                            self.StartStyling(current_pos, 0xff)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   447
                else:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   448
                    self.SetStyling(current_pos - last_styled_pos, 31)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   449
                last_styled_pos = current_pos
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   450
                state = SPACE
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   451
                line = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   452
            elif line.endswith("(*") and state != COMMENT:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   453
                self.SetStyling(current_pos - last_styled_pos - 1, 31)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   454
                last_styled_pos = current_pos
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   455
                if state == WORD:
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   456
                    current_context = self.Variables
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   457
                state = COMMENT
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   458
            elif state == COMMENT:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   459
                if line.endswith("*)"):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   460
                    self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   461
                    last_styled_pos = current_pos + 1
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   462
                    state = SPACE
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   463
            elif (line.endswith("'") or line.endswith('"')) and state not in [COMMENT, STRING, WSTRING]:
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   464
                self.SetStyling(current_pos - last_styled_pos, 31)
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   465
                last_styled_pos = current_pos
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   466
                if state == WORD:
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   467
                    current_context = self.Variables
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   468
                if line.endswith("'"):
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   469
                    state = STRING
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   470
                else:
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   471
                    state = WSTRING
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   472
            elif state == STRING:
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   473
                if line.endswith("'") and not line.endswith("$'"):
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   474
                    self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING)
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   475
                    last_styled_pos = current_pos + 1
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   476
                    state = SPACE
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   477
            elif state == WSTRING:
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   478
                if line.endswith('"') and not line.endswith('$"'):
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   479
                    self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING)
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   480
                    last_styled_pos = current_pos + 1
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   481
                    state = SPACE
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   482
            elif char in LETTERS:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   483
                if state == NUMBER:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   484
                    word = "#"
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   485
                    state = WORD
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   486
                elif state == SPACE:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   487
                    self.SetStyling(current_pos - last_styled_pos, 31)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   488
                    word = char
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   489
                    last_styled_pos = current_pos
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   490
                    state = WORD
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   491
                else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   492
                    word += char
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   493
            elif char in NUMBERS or char == '.' and state != WORD:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   494
                if state == SPACE:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   495
                    self.SetStyling(current_pos - last_styled_pos, 31)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   496
                    last_styled_pos = current_pos
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   497
                    state = NUMBER
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   498
                if state == WORD and char != '.':
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   499
                    word += char
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   500
            elif char == '(' and state == SPACE:
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   501
                self.CallStack.append(current_call)
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   502
                current_call = None
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   503
            else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   504
                if state == WORD:
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   505
                    if word in self.Keywords or word in self.TypeNames:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   506
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   507
                    elif self.IsValidVariable(word, current_context):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   508
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   509
                    elif self.IsCallParameter(word, current_call):
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   510
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   511
                    elif word in self.Functions:
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   512
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION)    
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   513
                    elif self.TextSyntax == "IL" and word in self.Jumps:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   514
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
   515
                    elif word in self.EnumeratedValues:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   516
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   517
                    else:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   518
                        self.SetStyling(current_pos - last_styled_pos, 31)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   519
                        if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   520
                            self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   521
                            self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   522
                            self.StartStyling(current_pos, 0xff)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   523
                    if char == '.':
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   524
                        if word != "]":
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   525
                            if current_context is not None:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   526
                                current_context = current_context.get(word, None)
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   527
                            else:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   528
                                current_context = None
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   529
                    elif char == '(':
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   530
                        self.CallStack.append(current_call)
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   531
                        current_call = self.Functions.get(word, None)
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   532
                        if current_call is None and self.IsValidVariable(word, current_context):
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   533
                            current_call = {"interface": current_context.get(word, {}),
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   534
                                            "extensible": False}
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   535
                        current_context = self.Variables
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   536
                    else:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   537
                        if char == '[':
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   538
                            self.ContextStack.append(current_context.get(word, None))
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   539
                        current_context = self.Variables
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   540
                    
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   541
                    word = ""
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   542
                    last_styled_pos = current_pos
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   543
                    state = SPACE
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   544
                elif state == NUMBER:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   545
                    self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   546
                    last_styled_pos = current_pos
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   547
                    state = SPACE
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   548
                if char == ']':
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   549
                    if len(self.ContextStack) > 0:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   550
                        current_context = self.ContextStack.pop()
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   551
                    else:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   552
                        current_context = self.Variables
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   553
                    word = char
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   554
                    state = WORD
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   555
                elif char == ')':
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   556
                    current_context = self.Variables
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   557
                    if len(self.CallStack) > 0:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   558
                        current_call = self.CallStack.pop()
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   559
                    else:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   560
                        current_call = None
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   561
                    word = char
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   562
                    state = WORD
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   563
            current_pos += 1
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   564
        if state == COMMENT:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   565
            self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   566
        elif state == NUMBER:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   567
            self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   568
        elif state == WORD:
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   569
            if word in self.Keywords or word in self.TypeNames:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   570
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   571
            elif self.IsValidVariable(word, current_context):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   572
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   573
            elif self.IsCallParameter(word, current_call):
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   574
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER)
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   575
            elif self.TextSyntax == "IL" and word in self.Functions:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   576
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   577
            elif word in self.Jumps:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   578
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
   579
            elif word in self.EnumeratedValues:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   580
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   581
            else:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   582
                self.SetStyling(current_pos - last_styled_pos, 31)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   583
        else:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   584
            self.SetStyling(current_pos - start_pos, 31)
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   585
        self.ShowHighlights(start_pos, end_pos)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   586
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   587
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   588
    def Cut(self):
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   589
        self.ResetBuffer()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   590
        self.CmdKeyExecute(wx.stc.STC_CMD_CUT)
136
858ff1a52d20 Bugs on TextViewer fixed
lbessard
parents: 125
diff changeset
   591
        self.RefreshModel()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   592
        self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   593
    
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   594
    def Copy(self):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   595
        self.CmdKeyExecute(wx.stc.STC_CMD_COPY)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   596
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   597
    def Paste(self):
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   598
        self.ResetBuffer()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   599
        self.CmdKeyExecute(wx.stc.STC_CMD_PASTE)
136
858ff1a52d20 Bugs on TextViewer fixed
lbessard
parents: 125
diff changeset
   600
        self.RefreshModel()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   601
        self.RefreshBuffer()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   602
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   603
    def RefreshModel(self):
136
858ff1a52d20 Bugs on TextViewer fixed
lbessard
parents: 125
diff changeset
   604
        self.RefreshJumpList()
858ff1a52d20 Bugs on TextViewer fixed
lbessard
parents: 125
diff changeset
   605
        self.Controler.SetEditedElementText(self.TagName, self.GetText())
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   606
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   607
    def OnKeyDown(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   608
        if self.CallTipActive():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   609
            self.CallTipCancel()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   610
        key = event.GetKeyCode()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   611
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   612
        # Code completion
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   613
        if key == wx.WXK_SPACE and event.ControlDown():
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   614
            
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   615
            line = self.GetCurrentLine()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   616
            if line == 0:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   617
                start_pos = 0
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   618
            else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   619
                start_pos = self.GetLineEndPosition(line - 1) + 1
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   620
            end_pos = self.GetCurrentPos()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   621
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   622
            lineText = self.GetTextRange(start_pos, end_pos).replace("\t", " ")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   623
            words = lineText.split(" ")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   624
            words = [word for i, word in enumerate(words) if word != '' or i == len(words) - 1]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   625
                        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   626
            kw = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   627
            
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   628
            if self.TextSyntax == "IL":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   629
                if len(words) == 1:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   630
                    kw = self.Keywords
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   631
                elif len(words) == 2:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   632
                    if words[0].upper() in ["CAL", "CALC", "CALNC"]:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   633
                        kw = self.Functions
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   634
                    elif words[0].upper() in ["JMP", "JMPC", "JMPNC"]:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   635
                        kw = self.Jumps
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   636
                    else:
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   637
                        kw = self.Variables.keys()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   638
            else:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   639
                kw = self.Keywords + self.Variables.keys() + self.Functions
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   640
            if len(kw) > 0:
312
eab54dae434d Adding filted in Auto-completion of TextViewer
lbessard
parents: 308
diff changeset
   641
                if len(words[-1]) > 0:
eab54dae434d Adding filted in Auto-completion of TextViewer
lbessard
parents: 308
diff changeset
   642
                    kw = [keyword for keyword in kw if keyword.startswith(words[-1])]
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   643
                kw.sort()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   644
                self.AutoCompSetIgnoreCase(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   645
                self.AutoCompShow(len(words[-1]), " ".join(kw))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   646
        else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   647
            event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   648
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   649
    def OnKillFocus(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   650
        self.AutoCompCancel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   651
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   652
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   653
#-------------------------------------------------------------------------------
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   654
#                        Highlights showing functions
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   655
#-------------------------------------------------------------------------------
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   656
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   657
    def OnRefreshHighlightsTimer(self, event):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   658
        self.RefreshView()
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   659
        event.Skip()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   660
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   661
    def ClearHighlights(self, highlight_type=None):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   662
        if highlight_type is None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   663
            self.Highlights = []
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   664
        else:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   665
            highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   666
            if highlight_type is not None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   667
                self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != highlight_type]
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   668
        self.RefreshView()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   669
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   670
    def AddHighlight(self, infos, start, end, highlight_type):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   671
        highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   672
        if infos[0] == "body" and highlight_type is not None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   673
            self.Highlights.append((infos[1], start, end, highlight_type))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   674
            self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   675
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   676
    def ShowHighlights(self, start_pos, end_pos):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   677
        for indent, start, end, highlight_type in self.Highlights:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   678
            if start[0] == 0:
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   679
                highlight_start_pos = start[1] - indent
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   680
            else:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   681
                highlight_start_pos = self.GetLineEndPosition(start[0] - 1) + start[1] - indent + 1
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   682
            if end[0] == 0:
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   683
                highlight_end_pos = end[1] - indent + 1
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   684
            else:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   685
                highlight_end_pos = self.GetLineEndPosition(end[0] - 1) + end[1] - indent + 2
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   686
            if highlight_start_pos < end_pos and highlight_end_pos > start_pos:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   687
                self.StartStyling(highlight_start_pos, 0xff)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   688
                self.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   689