I am trying to get a wx.stc.StyledTextCtrl to highlight keywords – but without success.
Can anyone tell me how to fix this please?
Code is attached.sqledit.py (1.1 KB)
and inline here:
#!/usr/bin/env python3
import wx
import wx.stc
class SQLedit(wx.stc.StyledTextCtrl):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.SetLexer(wx.stc.STC_LEX_SQL)
self.SetKeyWords(0, 'CREATE DEFAULT KEY PRIMARY TABLE TEXT')
self.StyleClearAll()
self.StyleSetSpec(wx.stc.STC_SQL_COMMENTLINE,
'fore:green,italic')
self.StyleSetSpec(wx.stc.STC_SQL_NUMBER, 'fore:red')
self.StyleSetSpec(wx.stc.STC_SQL_OPERATOR, 'fore:magenta')
self.StyleSetSpec(wx.stc.STC_SQL_WORD, 'fore:blue,bold')
self.StyleSetSpec(wx.stc.STC_SQL_WORD2, 'fore:blue,bold')
if __name__ == '__main__':
SQL = '''CREATE TABLE test (
one PRIMARY KEY INTEGER , -- One
two DEFAULT '' TEXT -- TWO
);'''
class Dialog(wx.Dialog):
def __init__(self):
super().__init__(None)
self.editor = SQLedit(self)
self.editor.ChangeValue(SQL)
self.Size = (350, 150)
app = wx.App()
dialog = Dialog()
dialog.ShowModal()
As you can see, the keywords are not blue bold.