RichTextCtrl custom editor problems

Hello all,

I am currently trying to make a text editor which has the ability to syntax highlight. This is my first time working with RichTextCtrl and I am running into some situations I don’t quite understand. I have looked in detail at the demo code for RichTextCtrl and understand what is going on.

Basically what I want to do is to be able to create a new blank document that loads user settings, such as background, text color, etc. I don’t want to add any text initially. The background color loads no problem but for some reason the text color does not load. If I pre-load text into the RichTextCtrl it reflects the settings I specified, but if I don’t add any text it does not recognize my changes. I am creating the RichTextCtrl inside of a wx.aui.Notebook tab. Here is the snippet of code which I am trying to get working.

def openNewDocument(self):

    # Create a blank text editor with black background and white text, add the textctrl to the notebook tab
    defText = rt.RichTextCtrl(self.nb, id=-1, style=wx.TE_MULTILINE);

    wx.CallAfter(defText.SetFocus)

    defText.Freeze()

    defText.SetBackgroundColour((0,0,0))
    defText.BeginTextColour((255,255,255))

   defText.Thaw()

   self.nb.AddPage(defText, "Untitled[%d]" % self.untitleCnt)

   self.untitleCnt = self.untitleCnt + 1

If anyone has any ideas of what I need to do or what I am doing wrong, I would appreciate it. I am running python 2.5 with wxPython 2.8.8.1 on Ubuntu.

Also if anyone also knows how to go about changing the cursor color for a RichTextCtrl I would also appreciate that as well.

Thanks in advance,
Scott

Hello,

For this sort of task you are better off looking at wx.stc.StyledTextCtrl. It already has syntax highlighting builtin for many languages and has facilities for adding custom highlighting as well. If you decide to use it instead it has a method (wx.stc.StyledTextCtrl.SetCaretForeground) for setting the caret color.

Cody

···

On Aug 16, 2008, at 12:50 PM, Scott Hall wrote:

Hello all,

I am currently trying to make a text editor which has the ability to syntax highlight. This is my first time working with RichTextCtrl and I am running into some situations I don’t quite understand. I have looked in detail at the demo code for RichTextCtrl and understand what is going on.

Basically what I want to do is to be able to create a new blank document that loads user settings, such as background, text color, etc. I don’t want to add any text initially. The background color loads no problem but for some reason the text color does not load. If I pre-load text into the RichTextCtrl it reflects the settings I specified, but if I don’t add any text it does not recognize my changes. I am creating the RichTextCtrl inside of a wx.aui.Notebook tab. Here is the snippet of code which I am trying to get working.

def openNewDocument(self):

    # Create a blank text editor with black background and white text, add the textctrl to the notebook tab
    defText = rt.RichTextCtrl(self.nb, id=-1, style=wx.TE_MULTILINE);
     wx.CallAfter(defText.SetFocus)

    defText.Freeze()

    defText.SetBackgroundColour((0,0,0))
    defText.BeginTextColour((255,255,255))

   defText.Thaw()

   self.nb.AddPage(defText, "Untitled[%d]" % self.untitleCnt)
    self.untitleCnt = self.untitleCnt + 1

If anyone has any ideas of what I need to do or what I am doing wrong, I would appreciate it. I am running python 2.5 with wxPython 2.8.8.1 on Ubuntu.

Also if anyone also knows how to go about changing the cursor color for a RichTextCtrl I would also appreciate that as well.

Thanks in advance,
Scott


wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

I'm also interested in using RichTextCtrl for syntax highlighting for
the simple reason that I want to be able to include icons and images
in my code and StyledTextCtrl won't allow that.

I'm guessing that the problem you're having is that the default style
is still black-on-white and since there's no text to set in the new
style, when the user starts typing, they get the default text color.
You could try something like waiting for the first character to be
pressed by the user and then set the foreground color oft that
character so that there's something to attach the new style to. One
note, though...I'm neither sure that that's the problem or that my
suggested solution might work. :slight_smile:

···

On Sat, Aug 16, 2008 at 2:01 PM, Cody Precord <codyprecord@gmail.com> wrote:

Hello,
For this sort of task you are better off looking at wx.stc.StyledTextCtrl.
It already has syntax highlighting builtin for many languages and has
facilities for adding custom highlighting as well. If you decide to use it
instead it has a method (wx.stc.StyledTextCtrl.SetCaretForeground) for
setting the caret color.
Cody
On Aug 16, 2008, at 12:50 PM, Scott Hall wrote:

Hello all,

I am currently trying to make a text editor which has the ability to syntax
highlight. This is my first time working with RichTextCtrl and I am running
into some situations I don't quite understand. I have looked in detail at
the demo code for RichTextCtrl and understand what is going on.

Basically what I want to do is to be able to create a new blank document
that loads user settings, such as background, text color, etc. I don't want
to add any text initially. The background color loads no problem but for
some reason the text color does not load. If I pre-load text into the
RichTextCtrl it reflects the settings I specified, but if I don't add any
text it does not recognize my changes. I am creating the RichTextCtrl
inside of a wx.aui.Notebook tab. Here is the snippet of code which I am
trying to get working.

def openNewDocument(self):

        # Create a blank text editor with black background and white text,
add the textctrl to the notebook tab
        defText = rt.RichTextCtrl(self.nb, id=-1, style=wx.TE_MULTILINE);
        wx.CallAfter(defText.SetFocus)

        defText.Freeze()

        defText.SetBackgroundColour((0,0,0))
        defText.BeginTextColour((255,255,255))

       defText.Thaw()

       self.nb.AddPage(defText, "Untitled[%d]" % self.untitleCnt)
       self.untitleCnt = self.untitleCnt + 1
If anyone has any ideas of what I need to do or what I am doing wrong, I
would appreciate it. I am running python 2.5 with wxPython 2.8.8.1 on
Ubuntu.

Also if anyone also knows how to go about changing the cursor color for a
RichTextCtrl I would also appreciate that as well.

Thanks in advance,
Scott
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users