TextViewer.py
author Laurent Bessard
Wed, 05 Sep 2012 12:39:50 +0200
changeset 761 996515c4b394
parent 738 1ccd08cfae0c
permissions -rw-r--r--
Fix bug when drag'n dropping location with undefined direction on Windows
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
761
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
    32
from plcopen.structures import ST_BLOCK_START_KEYWORDS, ST_BLOCK_END_KEYWORDS, IEC_BLOCK_START_KEYWORDS, IEC_BLOCK_END_KEYWORDS, LOCATIONDATATYPES
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
    33
from controls import EditorPanel
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
    34
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    35
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    36
#                         Textual programs Viewer class
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    37
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    38
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    39
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    40
NEWLINE = "\n"
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    41
NUMBERS = [str(i) for i in xrange(10)]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    42
LETTERS = ['_']
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    43
for i in xrange(26):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    44
    LETTERS.append(chr(ord('a') + i))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    45
    LETTERS.append(chr(ord('A') + i))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    46
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
    47
[STC_PLC_WORD, STC_PLC_COMMENT, STC_PLC_NUMBER, STC_PLC_STRING, 
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
    48
 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
    49
 STC_PLC_ERROR, STC_PLC_SEARCH_RESULT] = range(10)
671
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
    50
[SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT, PRAGMA] = range(7)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    51
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
    52
[ID_TEXTVIEWER, ID_TEXTVIEWERTEXTCTRL,
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
    53
] = [wx.NewId() for _init_ctrls in range(2)]
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    54
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    55
if wx.Platform == '__WXMSW__':
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    56
    faces = { 'times': 'Times New Roman',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    57
              'mono' : 'Courier New',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    58
              'helv' : 'Arial',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    59
              'other': 'Comic Sans MS',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    60
              'size' : 10,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    61
             }
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    62
else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    63
    faces = { 'times': 'Times',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    64
              'mono' : 'Courier',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    65
              'helv' : 'Helvetica',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    66
              'other': 'new century schoolbook',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    67
              'size' : 12,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    68
             }
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    69
re_texts = {}
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    70
re_texts["letter"] = "[A-Za-z]"
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    71
re_texts["digit"] = "[0-9]"
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    72
re_texts["identifier"] = "((?:%(letter)s|(?:_(?:%(letter)s|%(digit)s)))(?:_?(?:%(letter)s|%(digit)s))*)"%re_texts
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    73
IDENTIFIER_MODEL = re.compile(re_texts["identifier"])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    74
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
    75
EXTENSIBLE_PARAMETER = re.compile("IN[1-9][0-9]*$")
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    76
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
    77
HIGHLIGHT_TYPES = {
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
    78
    ERROR_HIGHLIGHT: STC_PLC_ERROR,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
    79
    SEARCH_RESULT_HIGHLIGHT: STC_PLC_SEARCH_RESULT,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
    80
}
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
    81
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    82
def GetCursorPos(old, new):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    83
    old_length = len(old)
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    84
    new_length = len(new)
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    85
    common_length = min(old_length, new_length)
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    86
    i = 0
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    87
    for i in xrange(common_length):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    88
        if old[i] != new[i]:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    89
            break
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    90
    if old_length < new_length:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    91
        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
    92
            return i + new_length - old_length
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    93
        else:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    94
            return i + new_length - old_length + 1
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
    95
    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
    96
        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
    97
            return i
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 i + 1
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   100
    else:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   101
        return None
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   102
582
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   103
def LineStartswith(line, symbols):
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   104
    return reduce(lambda x, y: x or y, map(lambda x: line.startswith(x), symbols), False)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   105
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   106
class TextViewer(EditorPanel):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   107
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   108
    ID = ID_TEXTVIEWER
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   109
    
113
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 98
diff changeset
   110
    if wx.VERSION < (2, 6, 0):
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 98
diff changeset
   111
        def Bind(self, event, function, id = None):
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 98
diff changeset
   112
            if id is not None:
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 98
diff changeset
   113
                event(self, id, function)
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 98
diff changeset
   114
            else:
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 98
diff changeset
   115
                event(self, function)
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 98
diff changeset
   116
    
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   117
    def _init_Editor(self, prnt):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   118
        self.Editor = wx.stc.StyledTextCtrl(id=ID_TEXTVIEWERTEXTCTRL, 
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   119
                parent=prnt, name="TextViewer", size=wx.Size(0, 0), style=0)
699
649399ffdaf0 Fix bug with cut/copy/paste on PythonEditor
Laurent Bessard
parents: 696
diff changeset
   120
        self.Editor.ParentWindow = self
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   121
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   122
        self.Editor.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   123
        self.Editor.CmdKeyAssign(ord('-'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMOUT)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   124
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   125
        self.Editor.SetViewWhiteSpace(False)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   126
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   127
        self.Editor.SetLexer(wx.stc.STC_LEX_CONTAINER)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   128
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   129
        # Global default styles for all languages
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   130
        self.Editor.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   131
        self.Editor.StyleClearAll()  # Reset all to be like the default
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   132
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   133
        self.Editor.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER,  "back:#C0C0C0,size:%(size)d" % faces)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   134
        self.Editor.SetSelBackground(1, "#E0E0E0")
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   135
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   136
        # Highlighting styles
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   137
        self.Editor.StyleSetSpec(STC_PLC_WORD, "fore:#00007F,bold,size:%(size)d" % faces)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   138
        self.Editor.StyleSetSpec(STC_PLC_VARIABLE, "fore:#7F0000,size:%(size)d" % faces)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   139
        self.Editor.StyleSetSpec(STC_PLC_PARAMETER, "fore:#7F007F,size:%(size)d" % faces)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   140
        self.Editor.StyleSetSpec(STC_PLC_FUNCTION, "fore:#7F7F00,size:%(size)d" % faces)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   141
        self.Editor.StyleSetSpec(STC_PLC_COMMENT, "fore:#7F7F7F,size:%(size)d" % faces)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   142
        self.Editor.StyleSetSpec(STC_PLC_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   143
        self.Editor.StyleSetSpec(STC_PLC_STRING, "fore:#007F00,size:%(size)d" % faces)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   144
        self.Editor.StyleSetSpec(STC_PLC_JUMP, "fore:#FF7FFF,size:%(size)d" % faces)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   145
        self.Editor.StyleSetSpec(STC_PLC_ERROR, "fore:#FF0000,back:#FFFF00,size:%(size)d" % faces)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   146
        self.Editor.StyleSetSpec(STC_PLC_SEARCH_RESULT, "fore:#FFFFFF,back:#FFA500,size:%(size)d" % faces)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   147
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   148
        # Indicators styles
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   149
        self.Editor.IndicatorSetStyle(0, wx.stc.STC_INDIC_SQUIGGLE)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   150
        if self.ParentWindow is not None and self.Controler is not None:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   151
            self.Editor.IndicatorSetForeground(0, wx.RED)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   152
        else:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   153
            self.Editor.IndicatorSetForeground(0, wx.WHITE)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   154
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   155
        # Line numbers in the margin
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   156
        self.Editor.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   157
        self.Editor.SetMarginWidth(1, 50)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   158
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   159
        # Folding
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   160
        self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPEN,    wx.stc.STC_MARK_BOXMINUS,          "white", "#808080")
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   161
        self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDER,        wx.stc.STC_MARK_BOXPLUS,           "white", "#808080")
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   162
        self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERSUB,     wx.stc.STC_MARK_VLINE,             "white", "#808080")
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   163
        self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERTAIL,    wx.stc.STC_MARK_LCORNER,           "white", "#808080")
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   164
        self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEREND,     wx.stc.STC_MARK_BOXPLUSCONNECTED,  "white", "#808080")
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   165
        self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPENMID, wx.stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080")
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   166
        self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERMIDTAIL, wx.stc.STC_MARK_TCORNER,           "white", "#808080")
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   167
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   168
        # Indentation size
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   169
        self.Editor.SetTabWidth(2)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   170
        self.Editor.SetUseTabs(0)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   171
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   172
        self.Editor.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT|
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   173
                                    wx.stc.STC_MOD_BEFOREDELETE|
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   174
                                    wx.stc.STC_PERFORMED_USER)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   175
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   176
        self.Bind(wx.stc.EVT_STC_STYLENEEDED, self.OnStyleNeeded, id=ID_TEXTVIEWERTEXTCTRL)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   177
        self.Editor.Bind(wx.stc.EVT_STC_MARGINCLICK, self.OnMarginClick)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   178
        self.Editor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   179
        if self.Controler is not None:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   180
            self.Editor.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   181
            self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_TEXTVIEWERTEXTCTRL)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   182
            self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_TEXTVIEWERTEXTCTRL)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   183
        
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   184
    def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""):
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   185
        if tagname != "" and controler is not None:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   186
            self.VARIABLE_PANEL_TYPE = controler.GetPouType(tagname.split("::")[1])
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   187
        
600
7db729686416 Making variable panel not editable when showing variables of debugging block
laurent
parents: 589
diff changeset
   188
        EditorPanel.__init__(self, parent, tagname, window, controler, debug)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   189
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   190
        self.Keywords = []
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   191
        self.Variables = {}
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   192
        self.Functions = {}
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   193
        self.TypeNames = []
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   194
        self.Jumps = []
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
   195
        self.EnumeratedValues = []
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   196
        self.DisableEvents = True
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   197
        self.TextSyntax = None
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   198
        self.CurrentAction = None
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   199
        self.Highlights = []
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   200
        self.SearchParams = None
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   201
        self.SearchResults = None
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   202
        self.CurrentFindHighlight = None
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   203
        self.InstancePath = instancepath
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   204
        self.ContextStack = []
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   205
        self.CallStack = []
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   206
        
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   207
        self.RefreshHighlightsTimer = wx.Timer(self, -1)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   208
        self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
696
8865c406f616 Fix bug when starting debugging POU blocks
Laurent Bessard
parents: 687
diff changeset
   209
        
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   210
    def __del__(self):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   211
        self.RefreshHighlightsTimer.Stop()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   212
    
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   213
    def GetTitle(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   214
        if self.Debug or self.TagName == "":
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   215
            if len(self.InstancePath) > 15:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   216
                return "..." + self.InstancePath[-12:]
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   217
            return self.InstancePath
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   218
        return EditorPanel.GetTitle(self)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   219
    
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   220
    def GetInstancePath(self):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   221
        return self.InstancePath
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   222
    
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   223
    def IsViewing(self, tagname):
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   224
        if self.Debug or self.TagName == "":
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   225
            return self.InstancePath == tagname
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   226
        else:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   227
            return self.TagName == tagname
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   228
    
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   229
    def GetText(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   230
        return self.Editor.GetText()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   231
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   232
    def SetText(self, text):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   233
        self.Editor.SetText(text)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   234
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   235
    def SelectAll(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   236
        self.Editor.SelectAll()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   237
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   238
    def Colourise(self, start, end):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   239
        self.Editor.Colourise(start, end)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   240
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   241
    def StartStyling(self, pos, mask):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   242
        self.Editor.StartStyling(pos, mask)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   243
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   244
    def SetStyling(self, length, style):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   245
        self.Editor.SetStyling(length, style)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   246
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   247
    def GetCurrentPos(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   248
        return self.Editor.GetCurrentPos()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   249
    
675
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 671
diff changeset
   250
    def GetState(self):
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 671
diff changeset
   251
        return {"cursor_pos": self.Editor.GetCurrentPos()}
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 671
diff changeset
   252
    
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 671
diff changeset
   253
    def SetState(self, state):
704
aca0c83ed82e Replacing dialog asking for a name when drag'n drop function block to viewer by automatically generated name
Laurent Bessard
parents: 699
diff changeset
   254
        if self and state.has_key("cursor_pos"):
687
629680fb0582 refactoring
laurent
parents: 684
diff changeset
   255
            self.Editor.GotoPos(state.get("cursor_pos", 0))
675
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 671
diff changeset
   256
        
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   257
    def OnModification(self, event):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   258
        if not self.DisableEvents:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   259
            mod_type = event.GetModificationType()
411
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   260
            if mod_type&wx.stc.STC_MOD_BEFOREINSERT:
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   261
                if self.CurrentAction == None:
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   262
                    self.StartBuffering()
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   263
                elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1:
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   264
                    self.Controler.EndBuffering()
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   265
                    self.StartBuffering()
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   266
                self.CurrentAction = ("Add", event.GetPosition())
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   267
                wx.CallAfter(self.RefreshModel)
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   268
            elif mod_type&wx.stc.STC_MOD_BEFOREDELETE:
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   269
                if self.CurrentAction == None:
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   270
                    self.StartBuffering()
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   271
                elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1:
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   272
                    self.Controler.EndBuffering()
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   273
                    self.StartBuffering()
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   274
                self.CurrentAction = ("Delete", event.GetPosition())
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
   275
                wx.CallAfter(self.RefreshModel)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   276
        event.Skip()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   277
    
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 27
diff changeset
   278
    def OnDoDrop(self, event):
50
4610aafc884e Bugs fixed
lbessard
parents: 47
diff changeset
   279
        try:
4610aafc884e Bugs fixed
lbessard
parents: 47
diff changeset
   280
            values = eval(event.GetDragText())
4610aafc884e Bugs fixed
lbessard
parents: 47
diff changeset
   281
        except:
4610aafc884e Bugs fixed
lbessard
parents: 47
diff changeset
   282
            values = event.GetDragText()
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 27
diff changeset
   283
        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
   284
            message = None
523
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   285
            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
   286
                event.SetDragText("")
523
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   287
            elif values[1] in ["functionBlock", "function"]:
671
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   288
                blocktype = values[0]
523
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   289
                blockname = values[2]
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   290
                if len(values) > 3:
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   291
                    blockinputs = values[3]
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   292
                else:
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   293
                    blockinputs = None
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   294
                if values[1] != "function": 
671
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   295
                    if blockname == "":
523
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   296
                        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
   297
                        if dialog.ShowModal() == wx.ID_OK:
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   298
                            blockname = dialog.GetValue()
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   299
                        else:
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   300
                            return
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   301
                        dialog.Destroy()
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   302
                    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
   303
                        message = _("\"%s\" pou already exists!")%blockname
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   304
                    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
   305
                        message = _("\"%s\" element for this pou already exists!")%blockname
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   306
                    else:
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   307
                        self.Controler.AddEditedElementPouVar(self.TagName, values[0], blockname)
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   308
                        self.RefreshVariablePanel()
523
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   309
                        self.RefreshVariableTree()
671
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   310
                blockinfo = self.Controler.GetBlockType(blocktype, blockinputs, self.Debug)
523
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   311
                hint = ',\n    '.join(
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   312
                            [ " " + fctdecl[0]+" := (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["inputs"]] +
99ba2e3949ed Added drag'n'drop of functions and function blocks
edouard
parents: 485
diff changeset
   313
                            [ " " + fctdecl[0]+" => (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["outputs"]])
671
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   314
                if values[1] == "function":
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   315
                    event.SetDragText(blocktype+"(\n    "+hint+")")
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   316
                else:
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   317
                    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
   318
            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
   319
                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
   320
                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
   321
                    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
   322
                    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
   323
                        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
   324
                    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
   325
                        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
   326
                    else:
761
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   327
                        location = values[0]
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   328
                        if not location.startswith("%"):
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   329
                            dialog = wx.SingleChoiceDialog(self.ParentWindow, 
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   330
                                  _("Select a variable class:"), _("Variable class"), 
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   331
                                  ["Input", "Output", "Memory"], 
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   332
                                  wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL)
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   333
                            if dialog.ShowModal() == wx.ID_OK:
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   334
                                selected = dialog.GetSelection()
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   335
                            else:
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   336
                                selected = None
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   337
                            dialog.Destroy()
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   338
                            if selected is None:
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   339
                                event.SetDragText("")
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   340
                                return
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   341
                            if selected == 0:
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   342
                                location = "%I" + location
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   343
                            elif selected == 1:
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   344
                                location = "%Q" + location
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   345
                            else:
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   346
                                location = "%M" + location
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
   347
                        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
   348
                            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
   349
                        else:
761
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   350
                            var_type = LOCATIONDATATYPES.get(location[2], ["BOOL"])[0]
996515c4b394 Fix bug when drag'n dropping location with undefined direction on Windows
Laurent Bessard
parents: 738
diff changeset
   351
                        self.Controler.AddEditedElementPouVar(self.TagName, var_type, var_name, location, values[4])
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   352
                        self.RefreshVariablePanel()
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
   353
                        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
   354
                        event.SetDragText(var_name)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   355
                else:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   356
                    event.SetDragText("")
616
8a60ffcfd70b Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents: 613
diff changeset
   357
            elif values[1] == "Global":
8a60ffcfd70b Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents: 613
diff changeset
   358
                var_name = values[0]
8a60ffcfd70b Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents: 613
diff changeset
   359
                if var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]:
8a60ffcfd70b Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents: 613
diff changeset
   360
                    message = _("\"%s\" pou already exists!")%var_name
8a60ffcfd70b Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents: 613
diff changeset
   361
                else:
8a60ffcfd70b Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents: 613
diff changeset
   362
                    if not var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]:
8a60ffcfd70b Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents: 613
diff changeset
   363
                        self.Controler.AddEditedElementPouExternalVar(self.TagName, values[2], var_name)
8a60ffcfd70b Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents: 613
diff changeset
   364
                        self.RefreshVariablePanel()
8a60ffcfd70b Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents: 613
diff changeset
   365
                        self.RefreshVariableTree()
8a60ffcfd70b Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents: 613
diff changeset
   366
                    event.SetDragText(var_name)
716
2681a6da58d6 Adding support for drag'n dropping constant values
Laurent Bessard
parents: 704
diff changeset
   367
            elif values[1] == "Constant":
2681a6da58d6 Adding support for drag'n dropping constant values
Laurent Bessard
parents: 704
diff changeset
   368
                event.SetDragText(values[0])
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
   369
            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
   370
                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
   371
                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
   372
                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
   373
            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
   374
                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
   375
            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
   376
                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
   377
                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
   378
                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
   379
                event.SetDragText("")
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 27
diff changeset
   380
        event.Skip()
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 27
diff changeset
   381
    
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   382
    def SetTextSyntax(self, syntax):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   383
        self.TextSyntax = syntax
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   384
        if syntax in ["ST", "ALL"]:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   385
            self.Editor.SetMarginType(2, wx.stc.STC_MARGIN_SYMBOL)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   386
            self.Editor.SetMarginMask(2, wx.stc.STC_MASK_FOLDERS)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   387
            self.Editor.SetMarginSensitive(2, 1)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   388
            self.Editor.SetMarginWidth(2, 12)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   389
            if syntax == "ST":
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   390
                self.BlockStartKeywords = ST_BLOCK_START_KEYWORDS
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   391
                self.BlockEndKeywords = ST_BLOCK_START_KEYWORDS
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   392
            else:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   393
                self.BlockStartKeywords = IEC_BLOCK_START_KEYWORDS
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   394
                self.BlockEndKeywords = IEC_BLOCK_START_KEYWORDS
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   395
        else:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   396
            self.BlockStartKeywords = []
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   397
            self.BlockEndKeywords = []
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   398
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   399
    def SetKeywords(self, keywords):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   400
        self.Keywords = [keyword.upper() for keyword in keywords]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   401
        self.Colourise(0, -1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   402
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   403
    def RefreshJumpList(self):
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   404
        if self.TextSyntax != "IL":
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   405
            self.Jumps = [jump.upper() for jump in LABEL_MODEL.findall(self.GetText())]
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   406
            self.Colourise(0, -1)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   407
    
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   408
    # Buffer the last model state
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   409
    def RefreshBuffer(self):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   410
        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
   411
        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
   412
            self.ParentWindow.RefreshTitle()
485
d5ebb8eac934 Bug on TextViewer fixed : FileMenu not refreshed when text modified
laurent
parents: 448
diff changeset
   413
            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
   414
            self.ParentWindow.RefreshEditMenu()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   415
    
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   416
    def StartBuffering(self):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   417
        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
   418
        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
   419
            self.ParentWindow.RefreshTitle()
485
d5ebb8eac934 Bug on TextViewer fixed : FileMenu not refreshed when text modified
laurent
parents: 448
diff changeset
   420
            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
   421
            self.ParentWindow.RefreshEditMenu()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   422
    
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   423
    def ResetBuffer(self):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   424
        if self.CurrentAction != None:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   425
            self.Controler.EndBuffering()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   426
            self.CurrentAction = None
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   427
    
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   428
    def GetBufferState(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   429
        if not self.Debug and self.TextSyntax != "ALL":
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   430
            return self.Controler.GetBufferState()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   431
        return False, False
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   432
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   433
    def Undo(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   434
        if not self.Debug and self.TextSyntax != "ALL":
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   435
            self.Controler.LoadPrevious()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   436
            self.ParentWindow.CloseTabsWithoutModel()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   437
            
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   438
    def Redo(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   439
        if not self.Debug and self.TextSyntax != "ALL":
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   440
            self.Controler.LoadNext()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   441
            self.ParentWindow.CloseTabsWithoutModel()
654
f8445d00613d Fix bug when undo just after creating a new project element
laurent
parents: 619
diff changeset
   442
        
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   443
    def HasNoModel(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   444
        if not self.Debug and self.TextSyntax != "ALL":
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   445
            return self.Controler.GetEditedElement(self.TagName) is None
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   446
        return False
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   447
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   448
    def RefreshView(self, variablepanel=True):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   449
        EditorPanel.RefreshView(self, variablepanel)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   450
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   451
        if self.Controler is not None:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   452
            self.ResetBuffer()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   453
            self.DisableEvents = True
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   454
            old_cursor_pos = self.GetCurrentPos()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   455
            old_text = self.GetText()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   456
            new_text = self.Controler.GetEditedElementText(self.TagName, self.Debug)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   457
            self.SetText(new_text)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   458
            new_cursor_pos = GetCursorPos(old_text, new_text)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   459
            if new_cursor_pos != None:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   460
                self.Editor.GotoPos(new_cursor_pos)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   461
            else:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   462
                self.Editor.GotoPos(old_cursor_pos)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   463
            self.Editor.ScrollToColumn(0)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   464
            self.RefreshJumpList()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   465
            self.Editor.EmptyUndoBuffer()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   466
            self.DisableEvents = False
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   467
            
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   468
            self.RefreshVariableTree()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   469
            
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   470
            self.TypeNames = [typename.upper() for typename in self.Controler.GetDataTypes(self.TagName, True, self.Debug)]
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   471
            self.EnumeratedValues = [value.upper() for value in self.Controler.GetEnumeratedDataValues()]
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   472
            
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   473
            self.Functions = {}
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   474
            for category in self.Controler.GetBlockTypes(self.TagName, self.Debug):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   475
                for blocktype in category["list"]:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   476
                    blockname = blocktype["name"].upper()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   477
                    if blocktype["type"] == "function" and blockname not in self.Keywords and blockname not in self.Variables.keys():
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   478
                        interface = dict([(name, {}) for name, type, modifier in blocktype["inputs"] + blocktype["outputs"] if name != ''])
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   479
                        for param in ["EN", "ENO"]:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   480
                            if not interface.has_key(param):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   481
                                interface[param] = {}
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   482
                        if self.Functions.has_key(blockname):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   483
                            self.Functions[blockname]["interface"].update(interface)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   484
                            self.Functions[blockname]["extensible"] |= blocktype["extensible"]
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   485
                        else:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   486
                            self.Functions[blockname] = {"interface": interface,
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   487
                                                         "extensible": blocktype["extensible"]}
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   488
        
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 116
diff changeset
   489
        self.Colourise(0, -1)
582
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   490
            
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
   491
    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
   492
        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
   493
        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
   494
        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
   495
            return_type = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug)
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   496
            if return_type is not None:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   497
                var_tree, var_dimension = self.Controler.GenerateVarTree(return_type, self.Debug)
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   498
                self.Variables[words[-1].upper()] = self.GenerateVariableTree(var_tree)
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   499
            else:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   500
                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
   501
    
297
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 295
diff changeset
   502
    def GenerateVariableTree(self, list):
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 295
diff changeset
   503
        tree = {}
299
15669fe26e56 Adding support for generating real array dimension in variable blocks
lbessard
parents: 297
diff changeset
   504
        for var_name, var_type, (var_tree, var_dimension) in list:
300
34d1402c0e24 Bug with variable tree generation fixed
lbessard
parents: 299
diff changeset
   505
            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
   506
        return tree
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 295
diff changeset
   507
    
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   508
    def IsValidVariable(self, name, context):
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   509
        return context is not None and context.get(name, None) is not None
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   510
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   511
    def IsCallParameter(self, name, call):
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   512
        if call is not None:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   513
            return (call["interface"].get(name.upper(), None) is not None or 
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   514
                    call["extensible"] and EXTENSIBLE_PARAMETER.match(name.upper()) is not None)
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   515
        return False
582
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   516
    
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   517
    def RefreshLineFolding(self, line_number):
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   518
        if self.TextSyntax in ["ST", "ALL"]:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   519
            level = wx.stc.STC_FOLDLEVELBASE + self.Editor.GetLineIndentation(line_number)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   520
            line = self.Editor.GetLine(line_number).strip()
582
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   521
            if line == "":
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   522
                if line_number > 0:
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   523
                    if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   524
                        level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK
582
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   525
                    else:
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   526
                        level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK
582
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   527
                if level != wx.stc.STC_FOLDLEVELBASE:
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   528
                    level |=  wx.stc.STC_FOLDLEVELWHITEFLAG 
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   529
            elif LineStartswith(line, self.BlockStartKeywords):
582
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   530
                level |= wx.stc.STC_FOLDLEVELHEADERFLAG
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   531
            elif LineStartswith(line, self.BlockEndKeywords):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   532
                if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   533
                    level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK
582
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   534
                else:
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   535
                    level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   536
            self.Editor.SetFoldLevel(line_number, level)
582
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   537
    
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   538
    def OnStyleNeeded(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   539
        self.TextChanged = True
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   540
        line_number = self.Editor.LineFromPosition(self.Editor.GetEndStyled())
582
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   541
        if line_number == 0:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   542
            start_pos = last_styled_pos = 0
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   543
        else:
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   544
            start_pos = last_styled_pos = self.Editor.GetLineEndPosition(line_number - 1) + 1
582
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   545
        self.RefreshLineFolding(line_number)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   546
        end_pos = event.GetPosition()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   547
        self.StartStyling(start_pos, 0xff)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   548
        
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   549
        current_context = self.Variables
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   550
        current_call = None
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   551
        
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   552
        current_pos = last_styled_pos
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   553
        state = SPACE
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   554
        line = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   555
        word = ""
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   556
        while current_pos < end_pos:
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   557
            char = chr(self.Editor.GetCharAt(current_pos)).upper()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   558
            line += char
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   559
            if char == NEWLINE:
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   560
                self.ContextStack = []
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   561
                current_context = self.Variables
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   562
                if state == COMMENT:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   563
                    self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_COMMENT)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   564
                elif state == NUMBER:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   565
                    self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   566
                elif state == WORD:
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   567
                    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
   568
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   569
                    elif self.IsValidVariable(word, current_context):
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_VARIABLE)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   571
                    elif self.IsCallParameter(word, current_call):
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   572
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   573
                    elif word in self.Functions:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   574
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION)
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   575
                    elif self.TextSyntax == "IL" and word in self.Jumps:
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_JUMP)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
   577
                    elif word in self.EnumeratedValues:
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_NUMBER)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   579
                    else:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   580
                        self.SetStyling(current_pos - last_styled_pos, 31)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   581
                        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
   582
                            self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   583
                            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
   584
                            self.StartStyling(current_pos, 0xff)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   585
                else:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   586
                    self.SetStyling(current_pos - last_styled_pos, 31)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   587
                last_styled_pos = current_pos
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   588
                state = SPACE
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   589
                line = ""
582
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   590
                line_number += 1
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   591
                self.RefreshLineFolding(line_number)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   592
            elif line.endswith("(*") and state != COMMENT:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   593
                self.SetStyling(current_pos - last_styled_pos - 1, 31)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   594
                last_styled_pos = current_pos
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   595
                if state == WORD:
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   596
                    current_context = self.Variables
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   597
                state = COMMENT
671
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   598
            elif line.endswith("{") and state != PRAGMA:
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   599
                self.SetStyling(current_pos - last_styled_pos - 1, 31)
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   600
                last_styled_pos = current_pos
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   601
                if state == WORD:
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   602
                    current_context = self.Variables
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   603
                state = PRAGMA
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   604
            elif state == COMMENT:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   605
                if line.endswith("*)"):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   606
                    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
   607
                    last_styled_pos = current_pos + 1
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   608
                    state = SPACE
671
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   609
            elif state == PRAGMA:
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   610
                if line.endswith("}"):
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   611
                    self.SetStyling(current_pos - last_styled_pos + 2, 31)
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   612
                    last_styled_pos = current_pos + 1
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   613
                    state = SPACE
47b9ad1471cc Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
laurent
parents: 654
diff changeset
   614
            elif (line.endswith("'") or line.endswith('"')) and state not in [STRING, WSTRING]:
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   615
                self.SetStyling(current_pos - last_styled_pos, 31)
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   616
                last_styled_pos = current_pos
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   617
                if state == WORD:
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   618
                    current_context = self.Variables
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   619
                if line.endswith("'"):
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   620
                    state = STRING
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   621
                else:
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   622
                    state = WSTRING
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   623
            elif state == STRING:
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   624
                if line.endswith("'") and not line.endswith("$'"):
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   625
                    self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING)
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   626
                    last_styled_pos = current_pos + 1
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   627
                    state = SPACE
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   628
            elif state == WSTRING:
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   629
                if line.endswith('"') and not line.endswith('$"'):
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   630
                    self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING)
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   631
                    last_styled_pos = current_pos + 1
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   632
                    state = SPACE
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   633
            elif char in LETTERS:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   634
                if state == NUMBER:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   635
                    word = "#"
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   636
                    state = WORD
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   637
                elif state == SPACE:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   638
                    self.SetStyling(current_pos - last_styled_pos, 31)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   639
                    word = char
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   640
                    last_styled_pos = current_pos
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   641
                    state = WORD
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   642
                else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   643
                    word += char
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   644
            elif char in NUMBERS or char == '.' and state != WORD:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   645
                if state == SPACE:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   646
                    self.SetStyling(current_pos - last_styled_pos, 31)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   647
                    last_styled_pos = current_pos
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   648
                    state = NUMBER
654
f8445d00613d Fix bug when undo just after creating a new project element
laurent
parents: 619
diff changeset
   649
                elif state == WORD and char != '.':
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   650
                    word += char
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   651
            elif char == '(' and state == SPACE:
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   652
                self.CallStack.append(current_call)
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   653
                current_call = None
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   654
            else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   655
                if state == WORD:
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   656
                    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
   657
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   658
                    elif self.IsValidVariable(word, current_context):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   659
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   660
                    elif self.IsCallParameter(word, current_call):
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   661
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   662
                    elif word in self.Functions:
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   663
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION)    
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   664
                    elif self.TextSyntax == "IL" and word in self.Jumps:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   665
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
   666
                    elif word in self.EnumeratedValues:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   667
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   668
                    else:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   669
                        self.SetStyling(current_pos - last_styled_pos, 31)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   670
                        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
   671
                            self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   672
                            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
   673
                            self.StartStyling(current_pos, 0xff)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   674
                    if char == '.':
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   675
                        if word != "]":
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   676
                            if current_context is not None:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   677
                                current_context = current_context.get(word, None)
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   678
                            else:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   679
                                current_context = None
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   680
                    elif char == '(':
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   681
                        self.CallStack.append(current_call)
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   682
                        current_call = self.Functions.get(word, None)
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   683
                        if current_call is None and self.IsValidVariable(word, current_context):
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   684
                            current_call = {"interface": current_context.get(word, {}),
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   685
                                            "extensible": False}
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   686
                        current_context = self.Variables
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   687
                    else:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   688
                        if char == '[':
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   689
                            self.ContextStack.append(current_context.get(word, None))
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   690
                        current_context = self.Variables
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   691
                    
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   692
                    word = ""
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   693
                    last_styled_pos = current_pos
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   694
                    state = SPACE
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   695
                elif state == NUMBER:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   696
                    self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   697
                    last_styled_pos = current_pos
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   698
                    state = SPACE
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   699
                if char == ']':
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   700
                    if len(self.ContextStack) > 0:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   701
                        current_context = self.ContextStack.pop()
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   702
                    else:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   703
                        current_context = self.Variables
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   704
                    word = char
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 249
diff changeset
   705
                    state = WORD
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   706
                elif char == ')':
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   707
                    current_context = self.Variables
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   708
                    if len(self.CallStack) > 0:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   709
                        current_call = self.CallStack.pop()
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   710
                    else:
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   711
                        current_call = None
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   712
                    word = char
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   713
                    state = WORD
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   714
            current_pos += 1
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   715
        if state == COMMENT:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   716
            self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   717
        elif state == NUMBER:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   718
            self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   719
        elif state == WORD:
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   720
            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
   721
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   722
            elif self.IsValidVariable(word, current_context):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   723
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE)
546
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   724
            elif self.IsCallParameter(word, current_call):
f28df922efbe Improve syntax highlighting in TextViewer
laurent
parents: 543
diff changeset
   725
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER)
543
2f660878c2a7 Adding support for coloring following elements:
laurent
parents: 523
diff changeset
   726
            elif self.TextSyntax == "IL" and word in self.Functions:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   727
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   728
            elif word in self.Jumps:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   729
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
   730
            elif word in self.EnumeratedValues:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   731
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   732
            else:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   733
                self.SetStyling(current_pos - last_styled_pos, 31)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   734
        else:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   735
            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
   736
        self.ShowHighlights(start_pos, end_pos)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   737
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   738
    
582
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   739
    def OnMarginClick(self, event):
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   740
        if event.GetMargin() == 2:
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   741
            line = self.Editor.LineFromPosition(event.GetPosition())
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   742
            if self.Editor.GetFoldLevel(line) & wx.stc.STC_FOLDLEVELHEADERFLAG:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   743
                self.Editor.ToggleFold(line)
582
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   744
        event.Skip()
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   745
        
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   746
    def Cut(self):
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   747
        self.ResetBuffer()
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   748
        self.DisableEvents = True
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   749
        self.Editor.CmdKeyExecute(wx.stc.STC_CMD_CUT)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   750
        self.DisableEvents = False
136
858ff1a52d20 Bugs on TextViewer fixed
lbessard
parents: 125
diff changeset
   751
        self.RefreshModel()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   752
        self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   753
    
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   754
    def Copy(self):
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   755
        self.Editor.CmdKeyExecute(wx.stc.STC_CMD_COPY)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   756
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   757
    def Paste(self):
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   758
        self.ResetBuffer()
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   759
        self.DisableEvents = True
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   760
        self.Editor.CmdKeyExecute(wx.stc.STC_CMD_PASTE)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   761
        self.DisableEvents = False
136
858ff1a52d20 Bugs on TextViewer fixed
lbessard
parents: 125
diff changeset
   762
        self.RefreshModel()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   763
        self.RefreshBuffer()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   764
    
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   765
    def Find(self, direction, search_params):
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   766
        if self.SearchParams != search_params:
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   767
            self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   768
            
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   769
            self.SearchParams = search_params
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   770
            criteria = {
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   771
                "raw_pattern": search_params["find_pattern"], 
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   772
                "pattern": re.compile(search_params["find_pattern"]),
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   773
                "case_sensitive": search_params["case_sensitive"],
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   774
                "regular_expression": search_params["regular_expression"],
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   775
                "filter": "all"}
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   776
            
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   777
            self.SearchResults = [
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   778
                (infos[1:], start, end, SEARCH_RESULT_HIGHLIGHT)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   779
                for infos, start, end, text in 
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   780
                self.Controler.SearchInPou(self.TagName, criteria, self.Debug)]
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   781
        
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   782
        if len(self.SearchResults) > 0:
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   783
            if self.CurrentFindHighlight is not None:
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   784
                old_idx = self.SearchResults.index(self.CurrentFindHighlight)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   785
                if self.SearchParams["wrap"]:
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   786
                    idx = (old_idx + direction) % len(self.SearchResults)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   787
                else:
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   788
                    idx = max(0, min(old_idx + direction, len(self.SearchResults) - 1))
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   789
                if idx != old_idx:
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   790
                    self.RemoveHighlight(*self.CurrentFindHighlight)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   791
                    self.CurrentFindHighlight = self.SearchResults[idx]
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   792
                    self.AddHighlight(*self.CurrentFindHighlight)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   793
            else:
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   794
                self.CurrentFindHighlight = self.SearchResults[0]
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   795
                self.AddHighlight(*self.CurrentFindHighlight)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   796
            
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   797
        else:
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   798
            if self.CurrentFindHighlight is not None:
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   799
                self.RemoveHighlight(*self.CurrentFindHighlight)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   800
            self.CurrentFindHighlight = None
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   801
    
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   802
    def RefreshModel(self):
136
858ff1a52d20 Bugs on TextViewer fixed
lbessard
parents: 125
diff changeset
   803
        self.RefreshJumpList()
858ff1a52d20 Bugs on TextViewer fixed
lbessard
parents: 125
diff changeset
   804
        self.Controler.SetEditedElementText(self.TagName, self.GetText())
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   805
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   806
    def OnKeyDown(self, event):
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   807
        if self.Controler is not None:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   808
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   809
            if self.Editor.CallTipActive():
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   810
                self.Editor.CallTipCancel()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   811
            key = event.GetKeyCode()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   812
            key_handled = False
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   813
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   814
            line = self.Editor.GetCurrentLine()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   815
            if line == 0:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   816
                start_pos = 0
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   817
            else:
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   818
                start_pos = self.Editor.GetLineEndPosition(line - 1) + 1
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   819
            end_pos = self.GetCurrentPos()
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   820
            lineText = self.Editor.GetTextRange(start_pos, end_pos).replace("\t", " ")
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   821
            
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   822
            # Code completion
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   823
            if key == wx.WXK_SPACE and event.ControlDown():
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   824
                
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   825
                words = lineText.split(" ")
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   826
                words = [word for i, word in enumerate(words) if word != '' or i == len(words) - 1]
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   827
                            
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   828
                kw = []
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   829
                
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   830
                if self.TextSyntax == "IL":
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   831
                    if len(words) == 1:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   832
                        kw = self.Keywords
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   833
                    elif len(words) == 2:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   834
                        if words[0].upper() in ["CAL", "CALC", "CALNC"]:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   835
                            kw = self.Functions
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   836
                        elif words[0].upper() in ["JMP", "JMPC", "JMPNC"]:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   837
                            kw = self.Jumps
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   838
                        else:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   839
                            kw = self.Variables.keys()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   840
                else:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   841
                    kw = self.Keywords + self.Variables.keys() + self.Functions
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   842
                if len(kw) > 0:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   843
                    if len(words[-1]) > 0:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   844
                        kw = [keyword for keyword in kw if keyword.startswith(words[-1])]
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   845
                    kw.sort()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   846
                    self.Editor.AutoCompSetIgnoreCase(True)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   847
                    self.Editor.AutoCompShow(len(words[-1]), " ".join(kw))
582
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   848
                key_handled = True
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   849
            elif key == wx.WXK_RETURN or key == wx.WXK_NUMPAD_ENTER:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   850
                if self.TextSyntax in ["ST", "ALL"]:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   851
                    indent = self.Editor.GetLineIndentation(line)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   852
                    if LineStartswith(lineText.strip(), self.BlockStartKeywords):
619
fc03645162b5 Fixing bug in autoindent when number of spaces at the beginning of line is odd
laurent
parents: 617
diff changeset
   853
                        indent = (indent / 2 + 1) * 2
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   854
                    self.Editor.AddText("\n" + " " * indent)
582
aa41547baa2a Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents: 566
diff changeset
   855
                    key_handled = True
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   856
            elif key == wx.WXK_BACK:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   857
                if self.TextSyntax in ["ST", "ALL"]:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   858
                    indent = self.Editor.GetLineIndentation(line)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   859
                    if lineText.strip() == "" and indent > 0:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   860
                        self.Editor.DelLineLeft()
619
fc03645162b5 Fixing bug in autoindent when number of spaces at the beginning of line is odd
laurent
parents: 617
diff changeset
   861
                        self.Editor.AddText(" " * ((max(0, indent - 1) / 2) * 2))
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   862
                        key_handled = True
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   863
            if not key_handled:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   864
                event.Skip()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   865
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   866
    def OnKillFocus(self, event):
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 582
diff changeset
   867
        self.Editor.AutoCompCancel()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   868
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   869
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   870
#-------------------------------------------------------------------------------
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   871
#                        Highlights showing functions
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   872
#-------------------------------------------------------------------------------
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   873
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   874
    def OnRefreshHighlightsTimer(self, event):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   875
        self.RefreshView()
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   876
        event.Skip()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   877
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   878
    def ClearHighlights(self, highlight_type=None):
617
1a80e0598045 Fixing bug in highlighting in variable panel
laurent
parents: 616
diff changeset
   879
        EditorPanel.ClearHighlights(self, highlight_type)
1a80e0598045 Fixing bug in highlighting in variable panel
laurent
parents: 616
diff changeset
   880
        
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   881
        if highlight_type is None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   882
            self.Highlights = []
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   883
        else:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   884
            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
   885
            if highlight_type is not None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   886
                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
   887
        self.RefreshView()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   888
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   889
    def AddHighlight(self, infos, start, end, highlight_type):
617
1a80e0598045 Fixing bug in highlighting in variable panel
laurent
parents: 616
diff changeset
   890
        EditorPanel.AddHighlight(self, infos, start, end, highlight_type)
1a80e0598045 Fixing bug in highlighting in variable panel
laurent
parents: 616
diff changeset
   891
        
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   892
        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
   893
        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
   894
            self.Highlights.append((infos[1], start, end, highlight_type))
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   895
            self.Editor.GotoPos(self.Editor.PositionFromLine(start[0]) + start[1])
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   896
            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
   897
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   898
    def RemoveHighlight(self, infos, start, end, highlight_type):
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   899
        EditorPanel.RemoveHighlight(self, infos, start, end, highlight_type)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   900
        
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   901
        highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   902
        if (infos[0] == "body" and highlight_type is not None and 
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   903
            (infos[1], start, end, highlight_type) in self.Highlights):
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   904
            self.Highlights.remove((infos[1], start, end, highlight_type))
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   905
            self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents: 716
diff changeset
   906
    
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   907
    def ShowHighlights(self, start_pos, end_pos):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   908
        for indent, start, end, highlight_type in self.Highlights:
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   909
            if start[0] == 0:
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   910
                highlight_start_pos = start[1] - indent
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   911
            else:
589
e3a1d9a59c97 Fixing bug that calls text styling in a loop while some highlighting is defined
laurent
parents: 586
diff changeset
   912
                highlight_start_pos = self.Editor.GetLineEndPosition(start[0] - 1) + start[1] - indent + 1
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   913
            if end[0] == 0:
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   914
                highlight_end_pos = end[1] - indent + 1
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   915
            else:
589
e3a1d9a59c97 Fixing bug that calls text styling in a loop while some highlighting is defined
laurent
parents: 586
diff changeset
   916
                highlight_end_pos = self.Editor.GetLineEndPosition(end[0] - 1) + end[1] - indent + 2
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   917
            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
   918
                self.StartStyling(highlight_start_pos, 0xff)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 549
diff changeset
   919
                self.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type)
589
e3a1d9a59c97 Fixing bug that calls text styling in a loop while some highlighting is defined
laurent
parents: 586
diff changeset
   920
                self.StartStyling(highlight_start_pos, 0x00)
e3a1d9a59c97 Fixing bug that calls text styling in a loop while some highlighting is defined
laurent
parents: 586
diff changeset
   921
                self.SetStyling(len(self.Editor.GetText()) - highlight_end_pos, wx.stc.STC_STYLE_DEFAULT)
e3a1d9a59c97 Fixing bug that calls text styling in a loop while some highlighting is defined
laurent
parents: 586
diff changeset
   922