Hey all,
So I’ve got my compiler working, but now I’m working on a syntax highlighter for it, but it’s not quite working. It would be great If i could get help in, say, the next ten minutes.
Here’s my code for highlighting syntax:
import wx
import os
import sys
from string import *Custom modules:
ID_TEXTBOX = 401
class MainWin(wx.Frame):
def init(self, parent, id, title):
wx.Frame.init(self, parent, id, title, size=(850, 450))
#Vars-
self.syntaxList =self.cVal = "" self.codePosition = -1 self.blueColor = wx.Colour(0,0,175) self.blackColor = wx.Colour(0,0,0) self.greenColor = wx.Colour(0,200,0) #Menubar [self.sb](http://self.sb) = self.CreateStatusBar() self.code = wx.TextCtrl(self, ID_TEXTBOX, size=(200, 130), style=wx.TE_MULTILINE) self.code.SetFont(wx.Font(11, wx.FONTFAMILY_MODERN, wx.NORMAL, wx.NORMAL)) self.Bind(wx.EVT_UPDATE_UI, self.SyntaxHighlight, id=ID_TEXTBOX) #### self.SetMinSize((300, 150)) self.Centre() self.Show(True) def dlg(self, text): amsg = wx.MessageDialog(None, str(text), "", wx.OK | wx.ICON_INFORMATION) amsg.ShowModal() def SyntaxHighlight(self, event): self.codePosition = 0 self.cVal = self.code.GetValue() for char in self.cVal: if char == "<": if "qt" not in self.syntaxList: self.syntaxList.append("lt") self.code.SetStyle(self.codePosition, self.codePosition + 1, wx.TextAttr(self.blueColor)) self.dlg(self.codePosition) elif char == ">": if "qt" not in self.syntaxList: self.lastItem = len(self.syntaxList) - 1 if self.syntaxList[self.lastItem] == "lt": self.code.SetStyle(self.codePosition, self.codePosition + 1, wx.TextAttr(self.blackColor)) elif char == "\"": self.syntaxList.append("qt") self.code.SetStyle(self.codePosition, self.codePosition + 1, wx.TextAttr(self.greenColor)) self.codePosition += 1
class MyApp(wx.App):
def OnInit(self): MainWin(None, -1, 'Syntax Highlighting').Show() return True
app = MyApp()
app.MainLoop()
MainWin.Destroy(MainWin)
I know that you’ll probably suggest using stc, but I don’t have time to completely redesign my program.
Thanks in advance for any help.