py_ext/PythonEditor.py
author Laurent Bessard
Mon, 10 Jun 2013 11:54:18 +0200
changeset 1240 ceaf9b4c0f86
parent 1138 cf2a6a7c87e8
child 1511 91538d0c242c
permissions -rw-r--r--
Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
     1
import keyword
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
     2
import wx.stc as stc
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
     3
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
     4
from controls.CustomStyledTextCtrl import faces
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
     5
from editors.CodeFileEditor import CodeFileEditor, CodeEditor
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
     6
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
     7
class PythonCodeEditor(CodeEditor):
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
     8
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
     9
    KEYWORDS = keyword.kwlist
1110
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1097
diff changeset
    10
    COMMENT_HEADER = "#"
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    11
    
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    12
    def SetCodeLexer(self):
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    13
        self.SetLexer(stc.STC_LEX_PYTHON)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    14
        
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    15
        # Line numbers in margin
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    16
        self.StyleSetSpec(stc.STC_STYLE_LINENUMBER,'fore:#000000,back:#99A9C2,size:%(size)d' % faces)    
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    17
        # Highlighted brace
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    18
        self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT,'fore:#00009D,back:#FFFF00,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    19
        # Unmatched brace
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    20
        self.StyleSetSpec(stc.STC_STYLE_BRACEBAD,'fore:#00009D,back:#FF0000,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    21
        # Indentation guide
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    22
        self.StyleSetSpec(stc.STC_STYLE_INDENTGUIDE, 'fore:#CDCDCD,size:%(size)d' % faces)
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 920
diff changeset
    23
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    24
        # Python styles
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    25
        self.StyleSetSpec(stc.STC_P_DEFAULT, 'fore:#000000,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    26
        # Comments
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    27
        self.StyleSetSpec(stc.STC_P_COMMENTLINE,  'fore:#008000,back:#F0FFF0,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    28
        self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, 'fore:#008000,back:#F0FFF0,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    29
        # Numbers
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    30
        self.StyleSetSpec(stc.STC_P_NUMBER, 'fore:#008080,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    31
        # Strings and characters
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    32
        self.StyleSetSpec(stc.STC_P_STRING, 'fore:#800080,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    33
        self.StyleSetSpec(stc.STC_P_CHARACTER, 'fore:#800080,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    34
        # Keywords
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    35
        self.StyleSetSpec(stc.STC_P_WORD, 'fore:#000080,bold,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    36
        # Triple quotes
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    37
        self.StyleSetSpec(stc.STC_P_TRIPLE, 'fore:#800080,back:#FFFFEA,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    38
        self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, 'fore:#800080,back:#FFFFEA,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    39
        # Class names
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    40
        self.StyleSetSpec(stc.STC_P_CLASSNAME, 'fore:#0000FF,bold,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    41
        # Function names
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    42
        self.StyleSetSpec(stc.STC_P_DEFNAME, 'fore:#008080,bold,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    43
        # Operators
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    44
        self.StyleSetSpec(stc.STC_P_OPERATOR, 'fore:#800000,bold,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    45
        # Identifiers. I leave this as not bold because everything seems
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    46
        # to be an identifier if it doesn't match the above criterae
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    47
        self.StyleSetSpec(stc.STC_P_IDENTIFIER, 'fore:#000000,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    48
        
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    49
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    50
#-------------------------------------------------------------------------------
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    51
#                          CFileEditor Main Frame Class
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    52
#-------------------------------------------------------------------------------
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    53
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    54
class PythonEditor(CodeFileEditor):
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1091
diff changeset
    55
    
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: 1110
diff changeset
    56
    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: 1110
diff changeset
    57
        (_("Python code"), "_create_CodePanel")]
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: 1110
diff changeset
    58
    CODE_EDITOR = PythonCodeEditor
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
    59