Skip to content

Instantly share code, notes, and snippets.

@driscollis
Last active June 15, 2021 18:21
Show Gist options
  • Save driscollis/051348d5a6ddc280c87a9b12b2d0419f to your computer and use it in GitHub Desktop.
Save driscollis/051348d5a6ddc280c87a9b12b2d0419f to your computer and use it in GitHub Desktop.
import wx
import wx.stc as stc
class XmlSTC(stc.StyledTextCtrl):
def __init__(self, parent):
stc.StyledTextCtrl.__init__(self, parent)
self.SetLexer(stc.STC_LEX_XML)
with open('books.xml') as fobj:
text = fobj.read()
self.SetText(text)
class XmlPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.xml_view = XmlSTC(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.xml_view, 1, wx.EXPAND)
self.SetSizer(sizer)
class XmlFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title='XML View')
panel = XmlPanel(self)
self.Show()
if __name__ == '__main__':
app = wx.App(False)
frame = XmlFrame()
app.MainLoop()
import wx
import wx.stc as stc
class XmlSTC(stc.StyledTextCtrl):
def __init__(self, parent):
stc.StyledTextCtrl.__init__(self, parent)
self.SetLexer(stc.STC_LEX_XML)
self.StyleSetSpec(stc.STC_STYLE_DEFAULT,
"size:10,face:Courier New")
faces = { 'mono' : 'Courier New',
'helv' : 'Arial',
'size' : 10,
}
# XML styles
# Default
self.StyleSetSpec(stc.STC_H_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
# Number
self.StyleSetSpec(stc.STC_H_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
# Tag
self.StyleSetSpec(stc.STC_H_TAG, "fore:#007F7F,bold,size:%(size)d" % faces)
# Value
self.StyleSetSpec(stc.STC_H_VALUE, "fore:#7F0000,size:%(size)d" % faces)
with open('books.xml') as fobj:
text = fobj.read()
self.SetText(text)
class XmlPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.xml_view = XmlSTC(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.xml_view, 1, wx.EXPAND)
self.SetSizer(sizer)
class XmlFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title='XML View')
panel = XmlPanel(self)
self.Show()
if __name__ == '__main__':
app = wx.App(False)
frame = XmlFrame()
app.MainLoop()
@Tecnoll
Copy link

Tecnoll commented Nov 18, 2020

Muito obrigado!

@Kabiirk
Copy link

Kabiirk commented Jun 15, 2021

I am making my Own IDE in wxPython and was looking for ways to add syntax Highlighting. This is very close what I was looking for ! Thanks a ton !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment