Last active
June 15, 2021 18:21
-
-
Save driscollis/051348d5a6ddc280c87a9b12b2d0419f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
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
Muito obrigado!