andrej@1511: #!/usr/bin/env python andrej@1511: # -*- coding: utf-8 -*- andrej@1511: andrej@1511: # This file is part of Beremiz, a Integrated Development Environment for andrej@1511: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. andrej@1511: # andrej@1511: # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD andrej@1511: # andrej@1511: # See COPYING file for copyrights details. andrej@1511: # andrej@1511: # This program is free software; you can redistribute it and/or andrej@1511: # modify it under the terms of the GNU General Public License andrej@1511: # as published by the Free Software Foundation; either version 2 andrej@1511: # of the License, or (at your option) any later version. andrej@1511: # andrej@1511: # This program is distributed in the hope that it will be useful, andrej@1511: # but WITHOUT ANY WARRANTY; without even the implied warranty of andrej@1511: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrej@1511: # GNU General Public License for more details. andrej@1511: # andrej@1511: # You should have received a copy of the GNU General Public License andrej@1511: # along with this program; if not, write to the Free Software andrej@1511: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. andrej@1511: Laurent@1057: import keyword Laurent@1057: import wx.stc as stc Laurent@1057: Laurent@1097: from controls.CustomStyledTextCtrl import faces Laurent@1097: from editors.CodeFileEditor import CodeFileEditor, CodeEditor laurent@657: andrej@1736: Laurent@1097: class PythonCodeEditor(CodeEditor): Laurent@1057: Laurent@1097: KEYWORDS = keyword.kwlist Laurent@1110: COMMENT_HEADER = "#" andrej@1730: Laurent@1097: def SetCodeLexer(self): Laurent@1097: self.SetLexer(stc.STC_LEX_PYTHON) andrej@1730: Laurent@1097: # Line numbers in margin andrej@1740: self.StyleSetSpec(stc.STC_STYLE_LINENUMBER, 'fore:#000000,back:#99A9C2,size:%(size)d' % faces) Laurent@1097: # Highlighted brace andrej@1740: self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, 'fore:#00009D,back:#FFFF00,size:%(size)d' % faces) Laurent@1097: # Unmatched brace andrej@1740: self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, 'fore:#00009D,back:#FF0000,size:%(size)d' % faces) Laurent@1097: # Indentation guide Laurent@1097: self.StyleSetSpec(stc.STC_STYLE_INDENTGUIDE, 'fore:#CDCDCD,size:%(size)d' % faces) Laurent@1057: Laurent@1097: # Python styles Laurent@1097: self.StyleSetSpec(stc.STC_P_DEFAULT, 'fore:#000000,size:%(size)d' % faces) Laurent@1097: # Comments Laurent@1097: self.StyleSetSpec(stc.STC_P_COMMENTLINE, 'fore:#008000,back:#F0FFF0,size:%(size)d' % faces) Laurent@1097: self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, 'fore:#008000,back:#F0FFF0,size:%(size)d' % faces) Laurent@1097: # Numbers Laurent@1097: self.StyleSetSpec(stc.STC_P_NUMBER, 'fore:#008080,size:%(size)d' % faces) Laurent@1097: # Strings and characters Laurent@1097: self.StyleSetSpec(stc.STC_P_STRING, 'fore:#800080,size:%(size)d' % faces) Laurent@1097: self.StyleSetSpec(stc.STC_P_CHARACTER, 'fore:#800080,size:%(size)d' % faces) Laurent@1097: # Keywords Laurent@1097: self.StyleSetSpec(stc.STC_P_WORD, 'fore:#000080,bold,size:%(size)d' % faces) Laurent@1097: # Triple quotes Laurent@1097: self.StyleSetSpec(stc.STC_P_TRIPLE, 'fore:#800080,back:#FFFFEA,size:%(size)d' % faces) Laurent@1097: self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, 'fore:#800080,back:#FFFFEA,size:%(size)d' % faces) Laurent@1097: # Class names Laurent@1097: self.StyleSetSpec(stc.STC_P_CLASSNAME, 'fore:#0000FF,bold,size:%(size)d' % faces) Laurent@1097: # Function names Laurent@1097: self.StyleSetSpec(stc.STC_P_DEFNAME, 'fore:#008080,bold,size:%(size)d' % faces) Laurent@1097: # Operators Laurent@1097: self.StyleSetSpec(stc.STC_P_OPERATOR, 'fore:#800000,bold,size:%(size)d' % faces) Laurent@1097: # Identifiers. I leave this as not bold because everything seems Laurent@1097: # to be an identifier if it doesn't match the above criterae Laurent@1097: self.StyleSetSpec(stc.STC_P_IDENTIFIER, 'fore:#000000,size:%(size)d' % faces) andrej@1730: laurent@366: andrej@1782: # ------------------------------------------------------------------------------- Laurent@1097: # CFileEditor Main Frame Class andrej@1782: # ------------------------------------------------------------------------------- laurent@366: Laurent@1097: class PythonEditor(CodeFileEditor): andrej@1730: Laurent@1138: CONFNODEEDITOR_TABS = [ Laurent@1138: (_("Python code"), "_create_CodePanel")] Laurent@1138: CODE_EDITOR = PythonCodeEditor