wxStyledTextCtrl_2 woes

I'm working on an editor for the Flat Assembler programming language so I need to use the wxStyledTextCtrl_2 for syntax highlighting. I've been trying for hours to use the code from the demo, but I keep getting errors no matter what I do.

Can someone please provide a simple example of the most minimal way to show a wxStyledTextCtrl_2 that is set to fill the empty space of my frame and redraw itself when the window is resized (or whatever it has to do to update itself)? I would really appreciate it.

Thanks,
David

I'm working on an editor for the Flat Assembler programming language so I need to use the wxStyledTextCtrl_2 for syntax highlighting. I've been trying for hours to use the code from the demo, but I keep getting errors no matter what I do.

Can someone please provide a simple example of the most minimal way to show a wxStyledTextCtrl_2 that is set to fill the empty space of my frame and redraw itself when the window is resized (or whatever it has to do to update itself)? I would really appreciate it.

Thanks,
David

Never mind about the above. I finally got it working. My next problem is that nothing is getting highlighted. :frowning: Here's my code:

import wx
from wx import stc
import keyword

class fsCodeEditor(stc.StyledTextCtrl):
    def __init__(self, parent, ID, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0):
        stc.StyledTextCtrl.__init__(self, parent, ID, pos, size, style)
        self.SetLexer(stc.STC_LEX_ASM)
        self.SetKeyWords(0, " ".join(keyword.kwlist))
        self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:Courier New,size:10")
        self.StyleClearAll()

app = wx.App(0)
frame = fsMainUI(None, -1, "FASM Studio")
ce = fsCodeEditor(frame, -1)
ce.EmptyUndoBuffer()
ce.Colourise(0, -1)
app.MainLoop()

NOTE: There are some classes there that are declared elsewhere. But they are too long and have nothing to do with the Code Editor.

Most of that is taken directly from the demo. Any ideas?

Thanks,
David

David Brown wrote:

I'm working on an editor for the Flat Assembler programming language so I need to use the wxStyledTextCtrl_2 for syntax highlighting. I've been trying for hours to use the code from the demo, but I keep getting errors no matter what I do.

Can someone please provide a simple example of the most minimal way to show a wxStyledTextCtrl_2 that is set to fill the empty space of my frame and redraw itself when the window is resized (or whatever it has to do to update itself)? I would really appreciate it.

Thanks,
David

Never mind about the above. I finally got it working. My next problem is that nothing is getting highlighted. :frowning: Here's my code:

import wx
from wx import stc
import keyword

class fsCodeEditor(stc.StyledTextCtrl):
   def __init__(self, parent, ID, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0):
       stc.StyledTextCtrl.__init__(self, parent, ID, pos, size, style)
       self.SetLexer(stc.STC_LEX_ASM)
       self.SetKeyWords(0, " ".join(keyword.kwlist))

Are you sure that you want to use the Python keywords as the ASM keywords?

       self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:Courier New,size:10")
       self.StyleClearAll()

You are not setting any styles, and so all styles used by the lexer are going to be drawn exactly the same way. So it's not a matter of things not getting highlighted, but that the highlighted things are indistinguishable from everything else.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

David Brown wrote:

I'm working on an editor for the Flat Assembler programming language so I need to use the wxStyledTextCtrl_2 for syntax highlighting. I've been trying for hours to use the code from the demo, but I keep getting errors no matter what I do.

Can someone please provide a simple example of the most minimal way to show a wxStyledTextCtrl_2 that is set to fill the empty space of my frame and redraw itself when the window is resized (or whatever it has to do to update itself)? I would really appreciate it.

Thanks,
David

Never mind about the above. I finally got it working. My next problem is that nothing is getting highlighted. :frowning: Here's my code:

import wx
from wx import stc
import keyword

class fsCodeEditor(stc.StyledTextCtrl):
   def __init__(self, parent, ID, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0):
       stc.StyledTextCtrl.__init__(self, parent, ID, pos, size, style)
       self.SetLexer(stc.STC_LEX_ASM)
       self.SetKeyWords(0, " ".join(keyword.kwlist))

Are you sure that you want to use the Python keywords as the ASM keywords?

       self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:Courier New,size:10")
       self.StyleClearAll()

You are not setting any styles, and so all styles used by the lexer are going to be drawn exactly the same way. So it's not a matter of things not getting highlighted, but that the highlighted things are indistinguishable from everything else.

I removed the keyword stuff. I had no idea what that was for, so I just put it there just in case it was required. How do I find out what style types are used in the ASM lexer? Are they the same as the Python lexer? I'm pretty new to Python, so please forgive my dumb questions. :stuck_out_tongue:

Thanks,
David

Generally speaking, if you are using a lexer XXX, setting the lexer with
the name stc.STC_LEX_XXX, then the styles for that language is listed
under stc.STC_XXX_* . You can discover all such names if you do...

    import wx.stc
    for i in dir(wx.stc):
        if i.startswith('STC_ASM_'):
            print i

- Josiah

···

David Brown <david@atomicbinary.com> wrote:

Robin Dunn wrote:
> You are not setting any styles, and so all styles used by the lexer
> are going to be drawn exactly the same way. So it's not a matter of
> things not getting highlighted, but that the highlighted things are
> indistinguishable from everything else.
>
I removed the keyword stuff. I had no idea what that was for, so I just
put it there just in case it was required. How do I find out what style
types are used in the ASM lexer? Are they the same as the Python lexer?
I'm pretty new to Python, so please forgive my dumb questions. :stuck_out_tongue: