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: Laurent@1097: class PythonCodeEditor(CodeEditor): Laurent@1057: Laurent@1097: KEYWORDS = keyword.kwlist Laurent@1097: COMMENT_HEADER = "##" Laurent@1097: Laurent@1097: def SetCodeLexer(self): Laurent@1097: self.SetLexer(stc.STC_LEX_PYTHON) Laurent@1097: Laurent@1097: # Line numbers in margin Laurent@1097: self.StyleSetSpec(stc.STC_STYLE_LINENUMBER,'fore:#000000,back:#99A9C2,size:%(size)d' % faces) Laurent@1097: # Highlighted brace Laurent@1097: self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT,'fore:#00009D,back:#FFFF00,size:%(size)d' % faces) Laurent@1097: # Unmatched brace Laurent@1097: 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) Laurent@1097: laurent@366: Laurent@1097: #------------------------------------------------------------------------------- Laurent@1097: # CFileEditor Main Frame Class Laurent@1097: #------------------------------------------------------------------------------- laurent@366: Laurent@1097: class PythonEditor(CodeFileEditor): Laurent@1097: Laurent@1097: CONFNODEEDITOR_TABS = CodeFileEditor.CONFNODEEDITOR_TABS + [ Laurent@920: (_("Python code"), "_create_PythonCodeEditor")] Laurent@920: Laurent@920: def _create_PythonCodeEditor(self, prnt): Laurent@1097: self.PythonCodeEditor = PythonCodeEditor(prnt, self.ParentWindow, self.Controler) Laurent@920: Laurent@920: return self.PythonCodeEditor laurent@657: Laurent@1097: def RefreshView(self): Laurent@1097: CodeFileEditor.RefreshView(self) laurent@657: Laurent@1097: self.PythonCodeEditor.RefreshView() Laurent@1057: Laurent@1057: def Find(self, direction, search_params): Laurent@1097: self.PythonCodeEditor.Find(direction, search_params)