Using wxRichTextCtrl: Attribute Error

Hi,

I would like to use wxRichTextCtrl to allow the user to format their text.
I would like to use wxRichTextCharacterStyleDefinitions to add styles to a
wxRichTextStyleSheet and then set that to a wxRichTextStyleListBox.

import wx
import wx.richtext

class RichTextPanel(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
        self.mytext = wx.richtext.RichTextCtrl(self, wx.TE_MULTILINE)
        self.stylesheet = wx.richtext.RichTextCharacterStyleDefinition()
        self.setStyles(self.stylesheet)
        
        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.mytext, 1, wx.EXPAND)
        
        self.SetAutoLayout(True)
        self.SetSizer(box)
        self.Layout()

Unfortunately I get the following error when I try to use
wxRichTextCharacterStyleDefinitions:

AttributeError: 'module' object has no attribute
'RichTextCharacterStyleDefinition'

I have also tried wx.richtext.CharacterStyleDefinition() and I get the same
error.

I get the same error for wxRichTextStyleSheet or wxRichTextStyleListBox.

Any insight as to why these modules don't seem to exist would be appriciated.

Tim <phisig791 <at> gmail.com> writes:

Hi,

I would like to use wxRichTextCtrl to allow the user to format their text.
I would like to use wxRichTextCharacterStyleDefinitions to add styles to a
wxRichTextStyleSheet and then set that to a wxRichTextStyleListBox.

import wx
import wx.richtext

class RichTextPanel(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
        self.mytext = wx.richtext.RichTextCtrl(self, wx.TE_MULTILINE)
        self.stylesheet = wx.richtext.RichTextCharacterStyleDefinition()
        self.setStyles(self.stylesheet)

        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.mytext, 1, wx.EXPAND)

        self.SetAutoLayout(True)
        self.SetSizer(box)
        self.Layout()

Unfortunately I get the following error when I try to use
wxRichTextCharacterStyleDefinitions:

AttributeError: 'module' object has no attribute
'RichTextCharacterStyleDefinition'

I have also tried wx.richtext.CharacterStyleDefinition() and I get the same
error.

I get the same error for wxRichTextStyleSheet or wxRichTextStyleListBox.

Any insight as to why these modules don't seem to exist would be appriciated.

Oops, wrong code. Full code is:

import wx
import wx.richtext

class RichTextPanel(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
        self.mytext = wx.richtext.RichTextCtrl(self, wx.TE_MULTILINE)
        self.stylesheet = wx.richtext.RichTextStyleSheet()
        self.setStyles(self.stylesheet)
        
        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.mytext, 1, wx.EXPAND)
        
        self.SetAutoLayout(True)
        self.SetSizer(box)
        self.Layout()
        
    def BoldClicked(self, event):
        #if(self.mytext.IsSelectionBold()):
            
        #if( self.mytext.getStringSelection() == None ):
            
        print "Bold was clicked!"
        
    def setStyles(self, stylesheet):
        boldDef = wx.richtext.CharacterStyleDefinition("Bold")
        boldAttr = wx.richtext.RichTextAttr()
        
        boldAttr.SetFontWeight(wx.BOLD)
        boldAttr.SetFlags(wx.TEXT_ATTR_FONT_WEIGHT)
        
        boldDef.setStyle(boldAttr)
        stylesheet.AddCharacterStyle(boldDef)

This brings up a question I was thinking about. With wx.RichTextCtrl is
there a way to convert the RTF into HTML? Or must this be done via
custom code?

···

On 7/26/06, Tim phisig791@gmail.com wrote:

Hi,

I would like to use wxRichTextCtrl to allow the user to format their text.
I would like to use wxRichTextCharacterStyleDefinitions to add styles to a
wxRichTextStyleSheet and then set that to a wxRichTextStyleListBox.

import wx
import wx.richtext

class RichTextPanel(wx.Panel):
def init(self, parent, id):
wx.Panel.init(self, parent, id)
self.mytext = wx.richtext.RichTextCtrl(self, wx.TE_MULTILINE
)
self.stylesheet = wx.richtext.RichTextCharacterStyleDefinition()
self.setStyles(self.stylesheet)

    box = wx.BoxSizer(wx.VERTICAL)
    box.Add(self.mytext, 1, wx.EXPAND)

self.SetAutoLayout(True)
self.SetSizer(box)
self.Layout()

Unfortunately I get the following error when I try to use
wxRichTextCharacterStyleDefinitions:

AttributeError: ‘module’ object has no attribute

‘RichTextCharacterStyleDefinition’

I have also tried wx.richtext.CharacterStyleDefinition() and I get the same
error.

I get the same error for wxRichTextStyleSheet or wxRichTextStyleListBox.

Any insight as to why these modules don’t seem to exist would be appriciated.


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org

For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org


-Richard Burton

Tim wrote:

Hi,

I would like to use wxRichTextCtrl to allow the user to format their text.
I would like to use wxRichTextCharacterStyleDefinitions to add styles to a
wxRichTextStyleSheet and then set that to a wxRichTextStyleListBox.

These classes haven't been wrapped yet. I expect to get them done before 2.7.0 is finished up.

···

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

Richard Burton wrote:

This brings up a question I was thinking about. With wx.RichTextCtrl is there a way to convert the RTF into HTML? Or must this be done via custom code?

It appears that the wxRichTextCtrl is expecting to get read/write support for RTF, and at least write support for html, but I don't think it has been done yet.

···

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