editors/CodeFileEditor.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Tue, 03 Dec 2024 21:22:45 +0100
changeset 4057 cf42c3dbdd5c
parent 3932 62d04933d569
permissions -rw-r--r--
IDE: Fix PLCOpenEditor (wxPython4 menus) and drop broken PDF doc support.
1511
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
     1
#!/usr/bin/env python
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
     2
# -*- coding: utf-8 -*-
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
     3
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
     6
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
     8
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
     9
# See COPYING file for copyrights details.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    10
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    11
# This program is free software; you can redistribute it and/or
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    12
# modify it under the terms of the GNU General Public License
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    13
# as published by the Free Software Foundation; either version 2
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    14
# of the License, or (at your option) any later version.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    15
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    16
# This program is distributed in the hope that it will be useful,
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    19
# GNU General Public License for more details.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    20
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    21
# You should have received a copy of the GNU General Public License
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    22
# along with this program; if not, write to the Free Software
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    24
1881
091005ec69c4 fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1878
diff changeset
    25
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    26
import re
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    27
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
    28
import wx
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
    29
import wx.grid
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
    30
import wx.stc as stc
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
    31
import wx.lib.buttons
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
    32
2434
07f48018b6f5 python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2432
diff changeset
    33
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    34
from plcopen.plcopen import TestTextElement
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
    35
from plcopen.structures import TestIdentifier, IEC_KEYWORDS, DefaultType
738
413946c04c87 refactoring
laurent
parents: 734
diff changeset
    36
from controls import CustomGrid, CustomTable
1834
cd42b426028b fix ungrouped imports from package X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    37
from controls.CustomStyledTextCtrl import CustomStyledTextCtrl, faces, GetCursorPos, NAVIGATION_KEYS
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    38
from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 801
diff changeset
    39
from util.BitmapLibrary import GetBitmap
1834
cd42b426028b fix ungrouped imports from package X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    40
from util.TranslationCatalogs import NoTranslate
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    41
from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD
1834
cd42b426028b fix ungrouped imports from package X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    42
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    43
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
    44
[STC_CODE_ERROR, STC_CODE_SEARCH_RESULT,
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3590
diff changeset
    45
 STC_CODE_SECTION] = list(range(15, 18))
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    46
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    47
HIGHLIGHT_TYPES = {
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    48
    ERROR_HIGHLIGHT: STC_CODE_ERROR,
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    49
    SEARCH_RESULT_HIGHLIGHT: STC_CODE_SEARCH_RESULT,
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    50
}
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    51
1161
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
    52
EDGE_COLUMN = 80
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
    53
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1704
diff changeset
    54
2528
6bfc8a9bf0e7 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2526
diff changeset
    55
def GetSectionsText(controler, sections_headers):
6bfc8a9bf0e7 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2526
diff changeset
    56
    parts = controler.GetTextParts()
6bfc8a9bf0e7 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2526
diff changeset
    57
    text = ""
6bfc8a9bf0e7 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2526
diff changeset
    58
    for section in controler.SECTIONS_NAMES:
6bfc8a9bf0e7 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2526
diff changeset
    59
        text += sections_headers(section)
6bfc8a9bf0e7 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2526
diff changeset
    60
        if parts[section] == "":
6bfc8a9bf0e7 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2526
diff changeset
    61
            text += "\n"
6bfc8a9bf0e7 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2526
diff changeset
    62
        else:
6bfc8a9bf0e7 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2526
diff changeset
    63
            if not parts[section].startswith("\n"):
6bfc8a9bf0e7 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2526
diff changeset
    64
                text += "\n"
6bfc8a9bf0e7 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2526
diff changeset
    65
            text += parts[section]
6bfc8a9bf0e7 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2526
diff changeset
    66
            if not parts[section].endswith("\n"):
6bfc8a9bf0e7 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2526
diff changeset
    67
                text += "\n"
6bfc8a9bf0e7 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2526
diff changeset
    68
    return text
6bfc8a9bf0e7 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2526
diff changeset
    69
2551
245644bfcd24 Make spaghetti-code-quality great again.
Edouard Tisserant
parents: 2528
diff changeset
    70
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    71
class CodeEditor(CustomStyledTextCtrl):
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
    72
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    73
    KEYWORDS = []
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    74
    COMMENT_HEADER = ""
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    75
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    76
    def __init__(self, parent, window, controler):
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
    77
        CustomStyledTextCtrl.__init__(self, parent, -1, wx.DefaultPosition,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
    78
                                      wx.Size(-1, 300), 0)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
    79
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    80
        self.SetMarginType(1, stc.STC_MARGIN_NUMBER)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    81
        self.SetMarginWidth(1, 25)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    82
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    83
        self.SetProperty("fold", "1")
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    84
        self.SetProperty("tab.timmy.whinge.level", "1")
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
    85
        self.SetMargins(0, 0)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    86
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    87
        self.SetViewWhiteSpace(False)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
    88
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    89
        self.SetEdgeMode(stc.STC_EDGE_BACKGROUND)
1161
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
    90
        self.SetEdgeColumn(EDGE_COLUMN)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    91
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    92
        # Setup a margin to hold fold markers
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    93
        self.SetMarginType(2, stc.STC_MARGIN_SYMBOL)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    94
        self.SetMarginMask(2, stc.STC_MASK_FOLDERS)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    95
        self.SetMarginSensitive(2, True)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    96
        self.SetMarginWidth(2, 12)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    97
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    98
        # Like a flattened tree control using square headers
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    99
        self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_BOXMINUS,          "white", "#808080")
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   100
        self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_BOXPLUS,           "white", "#808080")
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   101
        self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_VLINE,             "white", "#808080")
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   102
        self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_LCORNER,           "white", "#808080")
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   103
        self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_BOXPLUSCONNECTED,  "white", "#808080")
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   104
        self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080")
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   105
        self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER,           "white", "#808080")
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   106
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   107
        self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   108
        self.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   109
        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   110
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   111
        # Make some styles,  The lexer defines what each style is used for, we
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   112
        # just have to define what each style looks like.  This set is adapted from
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   113
        # Scintilla sample property files.
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   114
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   115
        # Global default styles for all languages
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   116
        self.StyleSetSpec(stc.STC_STYLE_DEFAULT,     "face:%(mono)s,size:%(size)d" % faces)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   117
        self.StyleClearAll()  # Reset all to be like the default
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   118
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   119
        # Global default styles for all languages
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   120
        self.StyleSetSpec(stc.STC_STYLE_DEFAULT,     "face:%(mono)s,size:%(size)d" % faces)
1066
b6a5ae4a68d7 Fixed bug in CFileEditor
Laurent Bessard
parents: 1060
diff changeset
   121
        self.StyleSetSpec(stc.STC_STYLE_LINENUMBER,  "back:#C0C0C0,face:%(helv)s,size:%(size)d" % faces)
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   122
        self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(mono)s" % faces)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   123
        self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT,  "fore:#FFFFFF,back:#0000FF,bold")
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   124
        self.StyleSetSpec(stc.STC_STYLE_BRACEBAD,    "fore:#000000,back:#FF0000,bold")
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   125
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   126
        # Highlighting styles
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   127
        self.StyleSetSpec(STC_CODE_ERROR, 'fore:#FF0000,back:#FFFF00,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   128
        self.StyleSetSpec(STC_CODE_SEARCH_RESULT, 'fore:#FFFFFF,back:#FFA500,size:%(size)d' % faces)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   129
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   130
        # Section style
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   131
        self.StyleSetSpec(STC_CODE_SECTION, 'fore:#808080,size:%(size)d')
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   132
        self.StyleSetChangeable(STC_CODE_SECTION, False)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   133
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   134
        # Indentation size
1161
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
   135
        self.SetTabWidth(4)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   136
        self.SetUseTabs(0)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   137
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   138
        self.SetCodeLexer()
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   139
        self.SetKeyWords(0, " ".join(self.KEYWORDS))
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   140
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   141
        self.Controler = controler
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   142
        self.ParentWindow = window
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   143
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   144
        self.DisableEvents = True
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   145
        self.CurrentAction = None
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   146
1178
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   147
        self.ResetSearchResults()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   148
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   149
        self.RefreshHighlightsTimer = wx.Timer(self, -1)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   150
        self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   151
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   152
        self.SectionsComments = {}
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   153
        for section in self.Controler.SECTIONS_NAMES:
1110
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   154
            section_comment = " %s section " % (section)
1161
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
   155
            len_headers = EDGE_COLUMN - len(section_comment)
1767
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   156
            section_comment = \
2437
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
   157
                self.COMMENT_HEADER * (len_headers // 2) + \
1767
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   158
                section_comment + \
2437
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
   159
                self.COMMENT_HEADER * (len_headers - len_headers // 2)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   160
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   161
            self.SectionsComments[section] = {
1878
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1872
diff changeset
   162
                "comment": section_comment,
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   163
            }
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   164
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   165
        for i, section in enumerate(self.Controler.SECTIONS_NAMES):
1110
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   166
            section_infos = self.SectionsComments[section]
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   167
            if i + 1 < len(self.Controler.SECTIONS_NAMES):
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   168
                section_end = self.SectionsComments[
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   169
                    self.Controler.SECTIONS_NAMES[i + 1]]["comment"]
1110
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   170
            else:
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   171
                section_end = "$"
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   172
            section_infos["pattern"] = re.compile(
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   173
                section_infos["comment"] + "(.*)" +
1110
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   174
                section_end, re.DOTALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   175
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   176
        self.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT | wx.stc.STC_MOD_BEFOREDELETE)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   177
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   178
        self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   179
        self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   180
        self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   181
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   182
    def SetCodeLexer(self):
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   183
        pass
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   184
1178
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   185
    def ResetSearchResults(self):
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   186
        self.Highlights = []
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   187
        self.SearchParams = None
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   188
        self.SearchResults = None
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   189
        self.CurrentFindHighlight = None
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   190
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   191
    def OnModification(self, event):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   192
        if not self.DisableEvents:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   193
            mod_type = event.GetModificationType()
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   194
            if not (mod_type & wx.stc.STC_PERFORMED_UNDO or mod_type & wx.stc.STC_PERFORMED_REDO):
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   195
                if mod_type & wx.stc.STC_MOD_BEFOREINSERT:
1743
c3c3d1318130 clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
   196
                    if self.CurrentAction is None:
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   197
                        self.StartBuffering()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   198
                    elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   199
                        self.Controler.EndBuffering()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   200
                        self.StartBuffering()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   201
                    self.CurrentAction = ("Add", event.GetPosition())
658
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
   202
                    wx.CallAfter(self.RefreshModel)
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   203
                elif mod_type & wx.stc.STC_MOD_BEFOREDELETE:
1743
c3c3d1318130 clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
   204
                    if self.CurrentAction is None:
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   205
                        self.StartBuffering()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   206
                    elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   207
                        self.Controler.EndBuffering()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   208
                        self.StartBuffering()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   209
                    self.CurrentAction = ("Delete", event.GetPosition())
658
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
   210
                    wx.CallAfter(self.RefreshModel)
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   211
        wx.CallAfter(self.RefreshSectionStyling)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   212
        event.Skip()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   213
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   214
    def OnDoDrop(self, event):
1138
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   215
        try:
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   216
            values = eval(event.GetDragText())
1780
c52d1460cea8 clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1774
diff changeset
   217
        except Exception:
1138
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   218
            values = event.GetDragText()
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   219
        if isinstance(values, tuple):
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   220
            if values[3] == self.Controler.GetCurrentLocation():
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   221
                self.ResetBuffer()
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   222
                event.SetDragText(values[0])
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   223
                wx.CallAfter(self.RefreshModel)
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   224
            else:
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   225
                event.SetDragText("")
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   226
        else:
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   227
            self.ResetBuffer()
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   228
            wx.CallAfter(self.RefreshModel)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   229
        event.Skip()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   230
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   231
    # Buffer the last model state
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   232
    def RefreshBuffer(self):
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   233
        self.Controler.BufferCodeFile()
658
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
   234
        if self.ParentWindow is not None:
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   235
            self.ParentWindow.RefreshTitle()
587
c6354f7fe26e Restore RefreshFileMenu in CFileEditor
Edouard Tisserant
parents: 586
diff changeset
   236
            self.ParentWindow.RefreshFileMenu()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   237
            self.ParentWindow.RefreshEditMenu()
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   238
            self.ParentWindow.RefreshPageTitles()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   239
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   240
    def StartBuffering(self):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   241
        self.Controler.StartBuffering()
658
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
   242
        if self.ParentWindow is not None:
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   243
            self.ParentWindow.RefreshTitle()
587
c6354f7fe26e Restore RefreshFileMenu in CFileEditor
Edouard Tisserant
parents: 586
diff changeset
   244
            self.ParentWindow.RefreshFileMenu()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   245
            self.ParentWindow.RefreshEditMenu()
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   246
            self.ParentWindow.RefreshPageTitles()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   247
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   248
    def ResetBuffer(self):
1743
c3c3d1318130 clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
   249
        if self.CurrentAction is not None:
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   250
            self.Controler.EndBuffering()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   251
            self.CurrentAction = None
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   252
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   253
    def GetCodeText(self):
2528
6bfc8a9bf0e7 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2526
diff changeset
   254
        return GetSectionsText(
2551
245644bfcd24 Make spaghetti-code-quality great again.
Edouard Tisserant
parents: 2528
diff changeset
   255
            self.Controler,
245644bfcd24 Make spaghetti-code-quality great again.
Edouard Tisserant
parents: 2528
diff changeset
   256
            lambda section: self.SectionsComments[section]["comment"])
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   257
1101
5a0b439cf576 Fixed search in CodeFileEditor STC panel
Laurent Bessard
parents: 1097
diff changeset
   258
    def RefreshView(self, scroll_to_highlight=False):
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   259
        self.ResetBuffer()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   260
        self.DisableEvents = True
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   261
        old_cursor_pos = self.GetCurrentPos()
1060
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   262
        line = self.GetFirstVisibleLine()
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   263
        column = self.GetXOffset()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   264
        old_text = self.GetText()
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   265
        new_text = self.GetCodeText()
1060
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   266
        if old_text != new_text:
1101
5a0b439cf576 Fixed search in CodeFileEditor STC panel
Laurent Bessard
parents: 1097
diff changeset
   267
            self.SetText(new_text)
1060
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   268
            new_cursor_pos = GetCursorPos(old_text, new_text)
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   269
            self.LineScroll(column, line)
1743
c3c3d1318130 clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
   270
            if new_cursor_pos is not None:
1060
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   271
                self.GotoPos(new_cursor_pos)
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   272
            else:
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   273
                self.GotoPos(old_cursor_pos)
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   274
            self.EmptyUndoBuffer()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   275
        self.DisableEvents = False
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   276
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   277
        self.RefreshSectionStyling()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   278
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   279
        self.ShowHighlights()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   280
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   281
    def RefreshSectionStyling(self):
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   282
        self.Colourise(0, -1)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   283
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3590
diff changeset
   284
        for line in range(self.GetLineCount()):
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   285
            self.SetLineState(line, 0)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   286
2518
c48470e2b383 Fix section styling in code editor (python and c extensions) if non-latin symbols are used in the code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2437
diff changeset
   287
        doc_end_pos = self.GetLength()
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   288
        for section in self.Controler.SECTIONS_NAMES:
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   289
            section_comments = self.SectionsComments[section]
3795
223a91584172 IDE: more fixes for wxPython 4.0.7 and pyhon 3.10
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3752
diff changeset
   290
            txttofind = section_comments["comment"]
223a91584172 IDE: more fixes for wxPython 4.0.7 and pyhon 3.10
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3752
diff changeset
   291
            results = self.FindText(0, doc_end_pos, txttofind)
223a91584172 IDE: more fixes for wxPython 4.0.7 and pyhon 3.10
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3752
diff changeset
   292
            if wx.VERSION < (4, 1, 0):
223a91584172 IDE: more fixes for wxPython 4.0.7 and pyhon 3.10
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3752
diff changeset
   293
                start_pos = results
223a91584172 IDE: more fixes for wxPython 4.0.7 and pyhon 3.10
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3752
diff changeset
   294
                end_pos = start_pos+len(txttofind)
223a91584172 IDE: more fixes for wxPython 4.0.7 and pyhon 3.10
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3752
diff changeset
   295
            else:
223a91584172 IDE: more fixes for wxPython 4.0.7 and pyhon 3.10
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3752
diff changeset
   296
                start_pos, end_pos = results
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2739
diff changeset
   297
            self.StartStyling(start_pos)
1110
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   298
            self.SetStyling(end_pos - start_pos, STC_CODE_SECTION)
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   299
            self.SetLineState(self.LineFromPosition(start_pos), 1)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   300
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2739
diff changeset
   301
        self.StartStyling(end_pos)
2518
c48470e2b383 Fix section styling in code editor (python and c extensions) if non-latin symbols are used in the code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2437
diff changeset
   302
        self.SetStyling(doc_end_pos - end_pos, stc.STC_STYLE_DEFAULT)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   303
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   304
    def DoGetBestSize(self):
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2739
diff changeset
   305
        return self.ParentWindow.GetBestSize()
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   306
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   307
    def RefreshModel(self):
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   308
        text = self.GetText()
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   309
        parts = {}
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   310
        for section in self.Controler.SECTIONS_NAMES:
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   311
            section_comments = self.SectionsComments[section]
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   312
            result = section_comments["pattern"].search(text)
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   313
            if result is not None:
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   314
                parts[section] = result.group(1)
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   315
            else:
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   316
                parts[section] = ""
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   317
        self.Controler.SetTextParts(parts)
1178
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   318
        self.ResetSearchResults()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   319
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   320
    def OnKeyPressed(self, event):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   321
        if self.CallTipActive():
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   322
            self.CallTipCancel()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   323
        key = event.GetKeyCode()
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   324
        current_pos = self.GetCurrentPos()
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   325
        selected = self.GetSelection()
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   326
        text_selected = selected[0] != selected[1]
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   327
1139
f9cf74053b7d Fixed bug when deleting line between code and headers on Windows
Laurent Bessard
parents: 1138
diff changeset
   328
        # Test if caret is before Windows like new line
f9cf74053b7d Fixed bug when deleting line between code and headers on Windows
Laurent Bessard
parents: 1138
diff changeset
   329
        text = self.GetText()
1150
b1c84771e1cf Fixed bug when typing and caret is at last test position in CodeFileEditor
Laurent Bessard
parents: 1146
diff changeset
   330
        if current_pos < len(text) and ord(text[current_pos]) == 13:
1139
f9cf74053b7d Fixed bug when deleting line between code and headers on Windows
Laurent Bessard
parents: 1138
diff changeset
   331
            newline_size = 2
f9cf74053b7d Fixed bug when deleting line between code and headers on Windows
Laurent Bessard
parents: 1138
diff changeset
   332
        else:
f9cf74053b7d Fixed bug when deleting line between code and headers on Windows
Laurent Bessard
parents: 1138
diff changeset
   333
            newline_size = 1
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   334
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   335
        # Disable to type any character in section header lines
1878
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1872
diff changeset
   336
        if self.GetLineState(self.LineFromPosition(current_pos)) and \
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1872
diff changeset
   337
           not text_selected and \
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1872
diff changeset
   338
           key not in NAVIGATION_KEYS + [wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER]:
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   339
            return
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   340
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   341
        # Disable to delete line between code and header lines
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   342
        elif (self.GetCurLine()[0].strip() != "" and not text_selected and
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   343
              (key == wx.WXK_BACK and
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   344
               self.GetLineState(self.LineFromPosition(max(0, current_pos - 1))) or
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   345
               key in [wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE] and
1139
f9cf74053b7d Fixed bug when deleting line between code and headers on Windows
Laurent Bessard
parents: 1138
diff changeset
   346
               self.GetLineState(self.LineFromPosition(min(len(text), current_pos + newline_size))))):
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   347
            return
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   348
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   349
        elif key == 32 and event.ControlDown():
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   350
            # Tips
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   351
            if event.ShiftDown():
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   352
                pass
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   353
            # Code completion
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   354
            else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   355
                self.AutoCompSetIgnoreCase(False)  # so this needs to match
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   356
1136
5fac491d3a0e Added global variable names in CodeFileEditor auto-completion list
Laurent Bessard
parents: 1126
diff changeset
   357
                keywords = self.KEYWORDS + [var["Name"]
5fac491d3a0e Added global variable names in CodeFileEditor auto-completion list
Laurent Bessard
parents: 1126
diff changeset
   358
                                            for var in self.Controler.GetVariables()]
5fac491d3a0e Added global variable names in CodeFileEditor auto-completion list
Laurent Bessard
parents: 1126
diff changeset
   359
                keywords.sort()
5fac491d3a0e Added global variable names in CodeFileEditor auto-completion list
Laurent Bessard
parents: 1126
diff changeset
   360
                self.AutoCompShow(0, " ".join(keywords))
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   361
        else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   362
            event.Skip()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   363
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   364
    def OnKillFocus(self, event):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   365
        self.AutoCompCancel()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   366
        event.Skip()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   367
1126
26baa0ae9fd7 Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents: 1124
diff changeset
   368
    def OnUpdateUI(self, event):
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   369
        # check for matching braces
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   370
        braceAtCaret = -1
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   371
        braceOpposite = -1
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   372
        charBefore = None
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   373
        caretPos = self.GetCurrentPos()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   374
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   375
        if caretPos > 0:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   376
            charBefore = self.GetCharAt(caretPos - 1)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   377
            styleBefore = self.GetStyleAt(caretPos - 1)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   378
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   379
        # check before
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   380
        if charBefore and chr(charBefore) in "[]{}()" and styleBefore == stc.STC_P_OPERATOR:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   381
            braceAtCaret = caretPos - 1
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   382
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   383
        # check after
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   384
        if braceAtCaret < 0:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   385
            charAfter = self.GetCharAt(caretPos)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   386
            styleAfter = self.GetStyleAt(caretPos)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   387
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   388
            if charAfter and chr(charAfter) in "[]{}()" and styleAfter == stc.STC_P_OPERATOR:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   389
                braceAtCaret = caretPos
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   390
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   391
        if braceAtCaret >= 0:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   392
            braceOpposite = self.BraceMatch(braceAtCaret)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   393
1774
ac0fe8aabb5e clean-up: fix PEP8 E272 multiple spaces before keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1772
diff changeset
   394
        if braceAtCaret != -1 and braceOpposite == -1:
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   395
            self.BraceBadLight(braceAtCaret)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   396
        else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   397
            self.BraceHighlight(braceAtCaret, braceOpposite)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   398
1146
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   399
        selected_text = self.GetSelectedText()
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   400
        if selected_text:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   401
            self.ParentWindow.SetCopyBuffer(selected_text, True)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   402
1126
26baa0ae9fd7 Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents: 1124
diff changeset
   403
    def OnMarginClick(self, event):
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   404
        # fold and unfold as needed
1872
866fb3ab8778 fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1847
diff changeset
   405
        if event.GetMargin() == 2:
866fb3ab8778 fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1847
diff changeset
   406
            if event.GetShift() and event.GetControl():
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   407
                self.FoldAll()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   408
            else:
1872
866fb3ab8778 fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1847
diff changeset
   409
                lineClicked = self.LineFromPosition(event.GetPosition())
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   410
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   411
                if self.GetFoldLevel(lineClicked) & stc.STC_FOLDLEVELHEADERFLAG:
1872
866fb3ab8778 fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1847
diff changeset
   412
                    if event.GetShift():
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   413
                        self.SetFoldExpanded(lineClicked, True)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   414
                        self.Expand(lineClicked, True, True, 1)
1872
866fb3ab8778 fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1847
diff changeset
   415
                    elif event.GetControl():
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   416
                        if self.GetFoldExpanded(lineClicked):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   417
                            self.SetFoldExpanded(lineClicked, False)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   418
                            self.Expand(lineClicked, False, True, 0)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   419
                        else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   420
                            self.SetFoldExpanded(lineClicked, True)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   421
                            self.Expand(lineClicked, True, True, 100)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   422
                    else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   423
                        self.ToggleFold(lineClicked)
1126
26baa0ae9fd7 Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents: 1124
diff changeset
   424
        event.Skip()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   425
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   426
    def FoldAll(self):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   427
        lineCount = self.GetLineCount()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   428
        expanding = True
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   429
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   430
        # find out if we are folding or unfolding
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   431
        for lineNum in range(lineCount):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   432
            if self.GetFoldLevel(lineNum) & stc.STC_FOLDLEVELHEADERFLAG:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   433
                expanding = not self.GetFoldExpanded(lineNum)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   434
                break
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   435
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   436
        lineNum = 0
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   437
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   438
        while lineNum < lineCount:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   439
            level = self.GetFoldLevel(lineNum)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   440
            if level & stc.STC_FOLDLEVELHEADERFLAG and \
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   441
               (level & stc.STC_FOLDLEVELNUMBERMASK) == stc.STC_FOLDLEVELBASE:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   442
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   443
                if expanding:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   444
                    self.SetFoldExpanded(lineNum, True)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   445
                    lineNum = self.Expand(lineNum, True)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   446
                    lineNum = lineNum - 1
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   447
                else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   448
                    lastChild = self.GetLastChild(lineNum, -1)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   449
                    self.SetFoldExpanded(lineNum, False)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   450
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   451
                    if lastChild > lineNum:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   452
                        self.HideLines(lineNum+1, lastChild)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   453
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   454
            lineNum = lineNum + 1
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   455
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   456
    def Expand(self, line, doExpand, force=False, visLevels=0, level=-1):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   457
        lastChild = self.GetLastChild(line, level)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   458
        line = line + 1
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   459
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   460
        while line <= lastChild:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   461
            if force:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   462
                if visLevels > 0:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   463
                    self.ShowLines(line, line)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   464
                else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   465
                    self.HideLines(line, line)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   466
            else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   467
                if doExpand:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   468
                    self.ShowLines(line, line)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   469
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   470
            if level == -1:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   471
                level = self.GetFoldLevel(line)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   472
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   473
            if level & stc.STC_FOLDLEVELHEADERFLAG:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   474
                if force:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   475
                    if visLevels > 1:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   476
                        self.SetFoldExpanded(line, True)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   477
                    else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   478
                        self.SetFoldExpanded(line, False)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   479
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   480
                    line = self.Expand(line, doExpand, force, visLevels-1)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   481
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   482
                else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   483
                    if doExpand and self.GetFoldExpanded(line):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   484
                        line = self.Expand(line, True, force, visLevels-1)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   485
                    else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   486
                        line = self.Expand(line, False, force, visLevels-1)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   487
            else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   488
                line = line + 1
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   489
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   490
        return line
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   491
637
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   492
    def Cut(self):
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   493
        self.ResetBuffer()
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   494
        self.DisableEvents = True
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   495
        self.CmdKeyExecute(wx.stc.STC_CMD_CUT)
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   496
        self.DisableEvents = False
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   497
        self.RefreshModel()
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   498
        self.RefreshBuffer()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   499
637
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   500
    def Copy(self):
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   501
        self.CmdKeyExecute(wx.stc.STC_CMD_COPY)
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   502
        self.ParentWindow.RefreshEditMenu()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   503
637
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   504
    def Paste(self):
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   505
        self.ResetBuffer()
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   506
        self.DisableEvents = True
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   507
        self.CmdKeyExecute(wx.stc.STC_CMD_PASTE)
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   508
        self.DisableEvents = False
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   509
        self.RefreshModel()
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   510
        self.RefreshBuffer()
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   511
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   512
    def Find(self, direction, search_params):
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   513
        if self.SearchParams != search_params:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   514
            self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   515
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   516
            self.SearchParams = search_params
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   517
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   518
            self.SearchResults = [
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   519
                (start, end, SEARCH_RESULT_HIGHLIGHT)
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1846
diff changeset
   520
                for start, end, _text in
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1511
diff changeset
   521
                TestTextElement(self.GetText(), search_params)]
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   522
            self.CurrentFindHighlight = None
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   523
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   524
        if len(self.SearchResults) > 0:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   525
            if self.CurrentFindHighlight is not None:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   526
                old_idx = self.SearchResults.index(self.CurrentFindHighlight)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   527
                if self.SearchParams["wrap"]:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   528
                    idx = (old_idx + direction) % len(self.SearchResults)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   529
                else:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   530
                    idx = max(0, min(old_idx + direction, len(self.SearchResults) - 1))
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   531
                if idx != old_idx:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   532
                    self.RemoveHighlight(*self.CurrentFindHighlight)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   533
                    self.CurrentFindHighlight = self.SearchResults[idx]
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   534
                    self.AddHighlight(*self.CurrentFindHighlight)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   535
            else:
1178
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   536
                caret_pos = self.GetCurrentPos()
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   537
                if self.SearchParams["wrap"]:
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   538
                    self.CurrentFindHighlight = self.SearchResults[0]
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   539
                else:
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   540
                    self.CurrentFindHighlight = None
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   541
                for start, end, highlight_type in self.SearchResults:
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   542
                    if start[0] == 0:
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   543
                        highlight_start_pos = start[1]
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   544
                    else:
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   545
                        highlight_start_pos = self.GetLineEndPosition(start[0] - 1) + start[1] + 1
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   546
                    if highlight_start_pos >= caret_pos:
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   547
                        self.CurrentFindHighlight = (start, end, highlight_type)
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   548
                        break
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   549
                if self.CurrentFindHighlight is not None:
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   550
                    self.AddHighlight(*self.CurrentFindHighlight)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   551
1101
5a0b439cf576 Fixed search in CodeFileEditor STC panel
Laurent Bessard
parents: 1097
diff changeset
   552
            self.ScrollToLine(self.CurrentFindHighlight[0][0])
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   553
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   554
        else:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   555
            if self.CurrentFindHighlight is not None:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   556
                self.RemoveHighlight(*self.CurrentFindHighlight)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   557
            self.CurrentFindHighlight = None
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   558
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   559
    # -------------------------------------------------------------------------------
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   560
    #                        Highlights showing functions
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   561
    # -------------------------------------------------------------------------------
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   562
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   563
    def OnRefreshHighlightsTimer(self, event):
1101
5a0b439cf576 Fixed search in CodeFileEditor STC panel
Laurent Bessard
parents: 1097
diff changeset
   564
        self.RefreshView(True)
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   565
        event.Skip()
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   566
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   567
    def ClearHighlights(self, highlight_type=None):
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   568
        if highlight_type is None:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   569
            self.Highlights = []
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   570
        else:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   571
            highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   572
            if highlight_type is not None:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   573
                self.Highlights = [(start, end, highlight) for (start, end, highlight) in self.Highlights if highlight != highlight_type]
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   574
        self.RefreshView()
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   575
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   576
    def AddHighlight(self, start, end, highlight_type):
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   577
        highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   578
        if highlight_type is not None:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   579
            self.Highlights.append((start, end, highlight_type))
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   580
            self.GotoPos(self.PositionFromLine(start[0]) + start[1])
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   581
            self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   582
            self.RefreshView()
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   583
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   584
    def RemoveHighlight(self, start, end, highlight_type):
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   585
        highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None)
1766
c1e5b9f19483 clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   586
        if highlight_type is not None and \
c1e5b9f19483 clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   587
           (start, end, highlight_type) in self.Highlights:
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   588
            self.Highlights.remove((start, end, highlight_type))
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   589
            self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   590
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   591
    def ShowHighlights(self):
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   592
        for start, end, highlight_type in self.Highlights:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   593
            if start[0] == 0:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   594
                highlight_start_pos = start[1]
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   595
            else:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   596
                highlight_start_pos = self.GetLineEndPosition(start[0] - 1) + start[1] + 1
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   597
            if end[0] == 0:
1178
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   598
                highlight_end_pos = end[1] + 1
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   599
            else:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   600
                highlight_end_pos = self.GetLineEndPosition(end[0] - 1) + end[1] + 2
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2739
diff changeset
   601
            self.StartStyling(highlight_start_pos)
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   602
            self.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type)
3795
223a91584172 IDE: more fixes for wxPython 4.0.7 and pyhon 3.10
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3752
diff changeset
   603
            self.StartStyling(highlight_end_pos, 0x00)
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   604
            self.SetStyling(len(self.GetText()) - highlight_end_pos, stc.STC_STYLE_DEFAULT)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   605
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   606
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   607
# -------------------------------------------------------------------------------
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   608
#                         Helper for VariablesGrid values
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   609
# -------------------------------------------------------------------------------
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   610
2226
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   611
class AllGridCellEditor(wx.grid.GridCellTextEditor):
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   612
    def __init__(self, table, row, col):
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   613
        wx.grid.GridCellTextEditor.__init__(self)
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   614
2249
602fdd08dfab More pylint+pep8 conformance
Edouard Tisserant
parents: 2226
diff changeset
   615
2226
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   616
class ClassGridCellEditor(wx.grid.GridCellChoiceEditor):
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   617
    def __init__(self, table, row, col):
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2739
diff changeset
   618
        wx.grid.GridCellChoiceEditor.__init__(self,["input","memory","output"])
2226
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   619
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   620
651
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 637
diff changeset
   621
class VariablesTable(CustomTable):
2226
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   622
    __defaultColumnType = dict(
2249
602fdd08dfab More pylint+pep8 conformance
Edouard Tisserant
parents: 2226
diff changeset
   623
        [(name, AllGridCellEditor) for name in
602fdd08dfab More pylint+pep8 conformance
Edouard Tisserant
parents: 2226
diff changeset
   624
         ["Name", "Initial", "Description", "OnChange", "Options"]] +
602fdd08dfab More pylint+pep8 conformance
Edouard Tisserant
parents: 2226
diff changeset
   625
        [('Class', ClassGridCellEditor), ('Type', None)])
2226
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   626
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   627
    def __init__(self, *args, **kwargs):
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   628
        my_columns = kwargs.pop("additional_columns")
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   629
        super(VariablesTable, self).__init__(*args, **kwargs)
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   630
        self.columnTypes = dict(self.__defaultColumnType)
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   631
        if my_columns is not None:
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3590
diff changeset
   632
            for key in list(my_columns.keys()):
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3590
diff changeset
   633
                if key in list(self.columnTypes.keys()):
2226
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   634
                    self.columnTypes[key] = my_columns[key]
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   635
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   636
    def GetValue(self, row, col):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   637
        if row < self.GetNumberRows():
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   638
            if col == 0:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   639
                return row + 1
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   640
            else:
3752
9f6f46dbe3ae removed Python2 modules
GP Orcullo <kinsamanka@gmail.com>
parents: 3750
diff changeset
   641
                return str(self.data[row].get(self.GetColLabelValue(col, False), ""))
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   642
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   643
    def _updateColAttrs(self, grid):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   644
        """
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   645
        wxGrid -> update the column attributes to add the
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   646
        appropriate renderer given the column name.
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   647
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   648
        Otherwise default to the default renderer.
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   649
        """
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   650
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   651
        for row in range(self.GetNumberRows()):
2525
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   652
            row_highlights = self.Highlights.get(row, {})
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   653
            for col in range(self.GetNumberCols()):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   654
                editor = None
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   655
                renderer = None
665
aec7aca89f3e Fixing bug in c_ext plugin variable grid cells not editable
laurent
parents: 658
diff changeset
   656
                colname = self.GetColLabelValue(col, False)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   657
2226
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   658
                editortype = self.columnTypes.get(colname, None)
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   659
                if editortype is not None:
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   660
                    editor = editortype(self, row, col)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   661
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   662
                grid.SetCellEditor(row, col, editor)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   663
                grid.SetCellRenderer(row, col, renderer)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   664
2525
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   665
                highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   666
                grid.SetCellBackgroundColour(row, col, highlight_colours[0])
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   667
                grid.SetCellTextColour(row, col, highlight_colours[1])
651
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 637
diff changeset
   668
            self.ResizeRow(grid, row)
848
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   669
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   670
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   671
class VariablesEditor(wx.Panel):
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   672
2226
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   673
    def __init__(self, parent, window, controler, additional_columns=None):
848
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   674
        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   675
1161
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
   676
        main_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=4)
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
   677
        main_sizer.AddGrowableCol(1)
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
   678
        main_sizer.AddGrowableRow(0)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   679
1161
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
   680
        controls_sizer = wx.BoxSizer(wx.VERTICAL)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2739
diff changeset
   681
        main_sizer.Add(controls_sizer, border=5, flag=wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   682
848
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   683
        for name, bitmap, help in [
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   684
                ("AddVariableButton", "add_element", _("Add variable")),
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   685
                ("DeleteVariableButton", "remove_element", _("Remove variable")),
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   686
                ("UpVariableButton", "up", _("Move variable up")),
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   687
                ("DownVariableButton", "down", _("Move variable down"))]:
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   688
            button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap),
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   689
                                                    size=wx.Size(28, 28), style=wx.NO_BORDER)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2739
diff changeset
   690
            button.SetToolTip(help)
848
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   691
            setattr(self, name, button)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2739
diff changeset
   692
            controls_sizer.Add(button, border=5, flag=wx.BOTTOM)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   693
1152
0a8fbd2a00f7 Fixed bug scrollbar not displayed in CodeFileEditor VariablePanel when grid is to small to show all variables
Laurent Bessard
parents: 1150
diff changeset
   694
        self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL)
3932
62d04933d569 IDE: Fix Variable grid ignoring edits. WxPython4 consequence.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3795
diff changeset
   695
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGED, self.OnVariablesGridCellChange)
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   696
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   697
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2739
diff changeset
   698
        main_sizer.Add(self.VariablesGrid, flag=wx.GROW)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   699
848
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   700
        self.SetSizer(main_sizer)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   701
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   702
        self.ParentWindow = window
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   703
        self.Controler = controler
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   704
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   705
        self.VariablesDefaultValue = {
1969
0607c382d73f remove duplicating code for variables name generate
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   706
            "Name":        "LocalVar0",
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   707
            "Type":        DefaultType,
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   708
            "Initial":     "",
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   709
            "Description": "",
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   710
            "OnChange":    "",
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   711
            "Options":     ""
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   712
        }
2226
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   713
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   714
        self.Table = VariablesTable(self, [], self.GetVariableTableColnames(), additional_columns=additional_columns)
1448
20ff66dcc31d Added more columns in variable list of extensions' code editors - updating python's PLCGlobals from PLC logic can trigger asynchronous 'OnChange' python call
Edouard Tisserant
parents: 1412
diff changeset
   715
        self.ColAlignements = [wx.ALIGN_RIGHT] +  \
20ff66dcc31d Added more columns in variable list of extensions' code editors - updating python's PLCGlobals from PLC logic can trigger asynchronous 'OnChange' python call
Edouard Tisserant
parents: 1412
diff changeset
   716
                              [wx.ALIGN_LEFT]*(len(self.VariablesDefaultValue))
1495
078047c3ab85 add i18n for some strings in DiscoveryDialog, DurationEditDialog, ProjectDialog and CodeFileEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1448
diff changeset
   717
        self.ColSizes = [20, 150] + [130]*(len(self.VariablesDefaultValue)-1)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   718
        self.VariablesGrid.SetTable(self.Table)
626
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   719
        self.VariablesGrid.SetButtons({"Add": self.AddVariableButton,
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   720
                                       "Delete": self.DeleteVariableButton,
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   721
                                       "Up": self.UpVariableButton,
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   722
                                       "Down": self.DownVariableButton})
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   723
626
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   724
        def _AddVariable(new_row):
1146
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   725
            if new_row > 0:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   726
                row_content = self.Table.data[new_row - 1].copy()
1969
0607c382d73f remove duplicating code for variables name generate
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   727
                old_name = row_content['Name']
0607c382d73f remove duplicating code for variables name generate
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   728
                row_content['Name'] =\
0607c382d73f remove duplicating code for variables name generate
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   729
                    self.Controler.GenerateNewName(old_name, old_name+'%d')
1146
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   730
            else:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   731
                row_content = self.VariablesDefaultValue.copy()
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   732
            self.Table.InsertRow(new_row, row_content)
626
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   733
            self.RefreshModel()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   734
            self.RefreshView()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   735
            return new_row
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   736
        setattr(self.VariablesGrid, "_AddRow", _AddVariable)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   737
626
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   738
        def _DeleteVariable(row):
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   739
            self.Table.RemoveRow(row)
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   740
            self.RefreshModel()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   741
            self.RefreshView()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   742
        setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   743
626
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   744
        def _MoveVariable(row, move):
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   745
            new_row = self.Table.MoveRow(row, move)
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   746
            if new_row != row:
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   747
                self.RefreshModel()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   748
                self.RefreshView()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   749
            return new_row
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   750
        setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   751
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   752
        self.VariablesGrid.SetRowLabelSize(0)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   753
        for col in range(self.Table.GetNumberCols()):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   754
            attr = wx.grid.GridCellAttr()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   755
            attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   756
            self.VariablesGrid.SetColAttr(col, attr)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   757
            self.VariablesGrid.SetColSize(col, self.ColSizes[col])
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   758
        self.Table.ResetView(self.VariablesGrid)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   759
1704
794a47ef5323 add l18n support to variable table in CodeFileEditor (python/C extension)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1699
diff changeset
   760
    def GetVariableTableColnames(self):
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1748
diff changeset
   761
        _ = NoTranslate
1772
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
   762
        return ["#",
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
   763
                _("Name"),
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
   764
                _("Type"),
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
   765
                _("Initial"),
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
   766
                _("Description"),
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
   767
                _("OnChange"),
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
   768
                _("Options")]
1704
794a47ef5323 add l18n support to variable table in CodeFileEditor (python/C extension)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1699
diff changeset
   769
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   770
    def RefreshModel(self):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   771
        self.Controler.SetVariables(self.Table.GetData())
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   772
        self.RefreshBuffer()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   773
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   774
    # Buffer the last model state
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   775
    def RefreshBuffer(self):
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   776
        self.Controler.BufferCodeFile()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   777
        self.ParentWindow.RefreshTitle()
587
c6354f7fe26e Restore RefreshFileMenu in CFileEditor
Edouard Tisserant
parents: 586
diff changeset
   778
        self.ParentWindow.RefreshFileMenu()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   779
        self.ParentWindow.RefreshEditMenu()
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   780
        self.ParentWindow.RefreshPageTitles()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   781
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   782
    def RefreshView(self):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   783
        self.Table.SetData(self.Controler.GetVariables())
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   784
        self.Table.ResetView(self.VariablesGrid)
626
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   785
        self.VariablesGrid.RefreshButtons()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   786
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   787
    def DoGetBestSize(self):
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2739
diff changeset
   788
        return self.ParentWindow.GetBestSize()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   789
1658
ba6a6d6e989c fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1556
diff changeset
   790
    def ShowErrorMessage(self, message):
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   791
        dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR)
1658
ba6a6d6e989c fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1556
diff changeset
   792
        dialog.ShowModal()
ba6a6d6e989c fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1556
diff changeset
   793
        dialog.Destroy()
ba6a6d6e989c fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1556
diff changeset
   794
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   795
    def OnVariablesGridCellChange(self, event):
1146
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   796
        row, col = event.GetRow(), event.GetCol()
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   797
        colname = self.Table.GetColLabelValue(col, False)
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   798
        value = self.Table.GetValue(row, col)
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   799
        message = None
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   800
1146
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   801
        if colname == "Name" and value != "":
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   802
            if not TestIdentifier(value):
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   803
                message = _("\"%s\" is not a valid identifier!") % value
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   804
            elif value.upper() in IEC_KEYWORDS:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   805
                message = _("\"%s\" is a keyword. It can't be used!") % value
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   806
            elif value.upper() in [var["Name"].upper()
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   807
                                   for var_row, var in enumerate(self.Table.data)
1146
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   808
                                   if var_row != row]:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   809
                message = _("A variable with \"%s\" as name already exists!") % value
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   810
            else:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   811
                self.RefreshModel()
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   812
                wx.CallAfter(self.RefreshView)
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   813
        else:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   814
            self.RefreshModel()
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   815
            wx.CallAfter(self.RefreshView)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   816
1146
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   817
        if message is not None:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   818
            event.Veto()
1658
ba6a6d6e989c fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1556
diff changeset
   819
            wx.CallAfter(self.ShowErrorMessage, message)
1146
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   820
        else:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   821
            event.Skip()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   822
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   823
    def OnVariablesGridEditorShown(self, event):
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   824
        row, col = event.GetRow(), event.GetCol()
801
435e49e80832 Update list of messages to be translated for internationalization and french translations
laurent
parents: 782
diff changeset
   825
        if self.Table.GetColLabelValue(col, False) == "Type":
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   826
            type_menu = wx.Menu(title='')
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   827
            base_menu = wx.Menu(title='')
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   828
            for base_type in self.Controler.GetBaseTypes():
3590
09dad7f00c36 IDE: fix wxPython 3->4 API change leading to exception in type selection menu in CodeFileEditor
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3303
diff changeset
   829
                new_entry = base_menu.Append(wx.ID_ANY, base_type)
2737
38afed869ff6 Finished fixing Wx IDs abuse. There was still some wasted IDs because of wx.NewId calls in many places where it wasn't needed, and those IDs were not re-used. As a consequence Beremiz was making exception crashing after a few hours of intensive use.
Edouard Tisserant
parents: 2551
diff changeset
   830
                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), new_entry)
38afed869ff6 Finished fixing Wx IDs abuse. There was still some wasted IDs because of wx.NewId calls in many places where it wasn't needed, and those IDs were not re-used. As a consequence Beremiz was making exception crashing after a few hours of intensive use.
Edouard Tisserant
parents: 2551
diff changeset
   831
            type_menu.AppendMenu(wx.ID_ANY, "Base Types", base_menu)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   832
            datatype_menu = wx.Menu(title='')
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   833
            for datatype in self.Controler.GetDataTypes():
3590
09dad7f00c36 IDE: fix wxPython 3->4 API change leading to exception in type selection menu in CodeFileEditor
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3303
diff changeset
   834
                new_entry = datatype_menu.Append(wx.ID_ANY, item=datatype)
2737
38afed869ff6 Finished fixing Wx IDs abuse. There was still some wasted IDs because of wx.NewId calls in many places where it wasn't needed, and those IDs were not re-used. As a consequence Beremiz was making exception crashing after a few hours of intensive use.
Edouard Tisserant
parents: 2551
diff changeset
   835
                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), new_entry)
38afed869ff6 Finished fixing Wx IDs abuse. There was still some wasted IDs because of wx.NewId calls in many places where it wasn't needed, and those IDs were not re-used. As a consequence Beremiz was making exception crashing after a few hours of intensive use.
Edouard Tisserant
parents: 2551
diff changeset
   836
            type_menu.AppendMenu(wx.ID_ANY, "User Data Types", datatype_menu)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   837
            rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   838
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2739
diff changeset
   839
            self.VariablesGrid.PopupMenu(type_menu, rect.x + rect.width, rect.y + self.VariablesGrid.GetColLabelSize())
708
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 675
diff changeset
   840
            type_menu.Destroy()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   841
            event.Veto()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   842
        else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   843
            event.Skip()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   844
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   845
    def GetVariableTypeFunction(self, base_type):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   846
        def VariableTypeFunction(event):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   847
            row = self.VariablesGrid.GetGridCursorRow()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   848
            self.Table.SetValueByName(row, "Type", base_type)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   849
            self.Table.ResetView(self.VariablesGrid)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   850
            self.RefreshModel()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   851
            self.RefreshView()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   852
            event.Skip()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   853
        return VariableTypeFunction
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   854
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   855
    def OnVariablesGridCellLeftClick(self, event):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   856
        if event.GetCol() == 0:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   857
            row = event.GetRow()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   858
            data_type = self.Table.GetValueByName(row, "Type")
401
8106a853a7c7 Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents: 213
diff changeset
   859
            var_name = self.Table.GetValueByName(row, "Name")
2739
7278186a2083 Copy description when DnD variables from CodeFile CTN to POUs
Edouard Tisserant
parents: 2737
diff changeset
   860
            desc = self.Table.GetValueByName(row, "Description")
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   861
            data = wx.TextDataObject(str((var_name, "Global", data_type,
2739
7278186a2083 Copy description when DnD variables from CodeFile CTN to POUs
Edouard Tisserant
parents: 2737
diff changeset
   862
                                          self.Controler.GetCurrentLocation(), desc)))
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   863
            dragSource = wx.DropSource(self.VariablesGrid)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   864
            dragSource.SetData(data)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   865
            dragSource.DoDragDrop()
874
8b24e9312f18 Fix bug when Drag'n Dropping located variables on Windows
Laurent Bessard
parents: 848
diff changeset
   866
            return
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   867
        event.Skip()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   868
2525
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   869
    def AddVariableHighlight(self, infos, highlight_type):
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   870
        self.Table.AddHighlight(infos, highlight_type)
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   871
        cell_visible = infos[0]
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   872
        colnames = [colname.lower() for colname in self.Table.colnames]
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   873
        self.VariablesGrid.MakeCellVisible(cell_visible, colnames.index(infos[1]))
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   874
        self.Table.ResetView(self.VariablesGrid)
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   875
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   876
    def RemoveVariableHighlight(self, infos, highlight_type):
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   877
        self.Table.RemoveHighlight(infos, highlight_type)
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   878
        self.Table.ResetView(self.VariablesGrid)
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   879
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   880
    def ClearHighlights(self, highlight_type=None):
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   881
        self.Table.ClearHighlights(highlight_type)
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   882
        self.Table.ResetView(self.VariablesGrid)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   883
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   884
# -------------------------------------------------------------------------------
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   885
#                          CodeFileEditor Main Frame Class
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   886
# -------------------------------------------------------------------------------
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   887
2551
245644bfcd24 Make spaghetti-code-quality great again.
Edouard Tisserant
parents: 2528
diff changeset
   888
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   889
class CodeFileEditor(ConfTreeNodeEditor):
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   890
1138
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   891
    CONFNODEEDITOR_TABS = []
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   892
    CODE_EDITOR = None
2226
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   893
    COLUMNS_TYPE = None
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   894
1138
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   895
    def _create_CodePanel(self, prnt):
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   896
        self.CodeEditorPanel = wx.SplitterWindow(prnt)
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   897
        self.CodeEditorPanel.SetMinimumPaneSize(1)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   898
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   899
        self.VariablesPanel = VariablesEditor(self.CodeEditorPanel,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   900
                                              self.ParentWindow,
2226
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   901
                                              self.Controler,
addb6eff8d94 Customizable columns in VariableTables (i.e. can be monkey patched properly)
Edouard Tisserant
parents: 1969
diff changeset
   902
                                              self.COLUMNS_TYPE)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   903
1138
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   904
        if self.CODE_EDITOR is not None:
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   905
            self.CodeEditor = self.CODE_EDITOR(self.CodeEditorPanel,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   906
                                               self.ParentWindow, self.Controler)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   907
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   908
            self.CodeEditorPanel.SplitHorizontally(self.VariablesPanel,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   909
                                                   self.CodeEditor, 150)
1138
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   910
        else:
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   911
            self.CodeEditorPanel.Initialize(self.VariablesPanel)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   912
1138
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   913
        return self.CodeEditorPanel
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   914
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   915
    def __init__(self, parent, controler, window):
743
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 738
diff changeset
   916
        ConfTreeNodeEditor.__init__(self, parent, controler, window)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   917
1138
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   918
        wx.CallAfter(self.CodeEditorPanel.SetSashPosition, 150)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   919
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   920
    def GetBufferState(self):
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   921
        return self.Controler.GetBufferState()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   922
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   923
    def Undo(self):
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   924
        self.Controler.LoadPrevious()
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   925
        self.RefreshView()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   926
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   927
    def Redo(self):
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   928
        self.Controler.LoadNext()
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   929
        self.RefreshView()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   930
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   931
    def RefreshView(self):
751
a8dace95f965 Fixing bug on ConfNodeEditors refresh
laurent
parents: 744
diff changeset
   932
        ConfTreeNodeEditor.RefreshView(self)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   933
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   934
        self.VariablesPanel.RefreshView()
1138
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   935
        self.CodeEditor.RefreshView()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 1178
diff changeset
   936
1138
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   937
    def Find(self, direction, search_params):
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   938
        self.CodeEditor.Find(direction, search_params)
2525
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   939
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   940
    def AddHighlight(self, infos, start, end, highlight_type):
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   941
        if self.VariablesPanel is not None and infos[0] == "var_inout":
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   942
            self.VariablesPanel.AddVariableHighlight(infos[1:], highlight_type)
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   943
        else:
2526
450c6239ee75 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2525
diff changeset
   944
            self.CodeEditor.AddHighlight(start, end, highlight_type)
2525
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   945
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   946
    def RemoveHighlight(self, infos, start, end, highlight_type):
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   947
        if self.VariablesPanel is not None and infos[0] == "var_inout":
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   948
            self.VariablesPanel.RemoveVariableHighlight(infos[1:], highlight_type)
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   949
        else:
2526
450c6239ee75 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2525
diff changeset
   950
            self.CodeEditor.RemoveHighlight(start, end, highlight_type)
2525
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   951
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   952
    def ClearHighlights(self, highlight_type=None):
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   953
        if self.VariablesPanel is not None:
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   954
            self.VariablesPanel.ClearHighlights(highlight_type)
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   955
        else:
9812b332f350 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2518
diff changeset
   956
            self.CodeEditor.ClearHighlights(highlight_type)