Setting the Font in the new RichTextCtrl sample/demo

I am trying to set the font without using the fontdialog box in the new RichTextCtrl module.

What I have tried so far is below (with some extra to show where I am trying to modify the code). My attempts start at line 28 of the latest release of Docs and Demos.

Can anyone help me? I have tried to find my way using the wxWidgets manual, but it seems that things are just a bit different between the sample and the manual.

My first attempts are marked by #'s below.

Thanks, thom

    self.rtc.BeginParagraphSpacing(0, 20)

    self.rtc.BeginAlignment(rt.TEXT_ALIGNMENT_CENTRE)
    self.rtc.BeginBold()

    # Thom Modified Starting Here
    self.rtc.BeginFontSize(14)
    self.rtc.WriteText("This is Greek")
    self.rtc.EndFontSize()
    self.rtc.Newline()

    fontData = wx.FontData()
    fontData.EnableEffects(False)
    attr = rt.RichTextAttr()
    attr.SetFlags(rt.TEXT_ATTR_FONT)
    if self.rtc.GetStyle(0, attr):
        fontData.SetInitialFont(attr.CreateFont())

    font = 'SymbolPS' #'4-KeyTimesRoman' #fontData.GetChosenFont()
    if font:
        attr.SetFlags(rt.TEXT_ATTR_FONT)
        attr.SetFont(font)
        self.rtc.SetStyle(r, attr)

    #attr = rt.RichTextAttr()
    #attr.SetFlags(rt.TEXT_ATTR_FONT)
    #attr.SetFont('SymbolPS') #CharacterStyleName
    #self.rtc.SetStyle((0,8),attr)

    # Thom's Modifications Ended Here

    self.rtc.BeginFontSize(14)
    self.rtc.WriteText("Velcome to wxRichTextCtrl, a wxWidgets control for editing and presenting styled text and images")
    self.rtc.EndFontSize()
    self.rtc.Newline()

Ives, Thomas Wayne wrote:

I am trying to set the font without using the fontdialog box in the new RichTextCtrl module.

        #attr.SetFont('SymbolPS') #CharacterStyleName

You probably want SetFontFaceName.

···

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

Robin,

I appreciate your reply. I had already tried what you suggest from
looking at the wxWidgets manual (SetFont is nowhere to be found in the
wxWidgets manual). If you look down lower in the RichTextCtrl demo file,
at the OnFont function, you will see that I am only trying to mimic what
goes on there, and you will see that Julian uses "attr.SetFont(..."

I think the crux of the problem is that I am not supplying the right
information to SetFont (i.e. font = <what to put here>), but I have been
unable to figure out how to find out what it needs.

Simply put, I want to hard code text to the RichTextCtrl window in the
font of my choice (from available system fonts) so that that font
appears on startup without having to go through the font dialog control
to change it after startup.

Can you or Julian or anyone else help with this? My coding attempts are
repeated below your reply again for convenience.

Thanks,
thom

···

-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Wednesday, June 13, 2007 1:34 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] Setting the Font in the new RichTextCtrl
sample/demo

Ives, Thomas Wayne wrote:

I am trying to set the font without using the fontdialog box in the
new RichTextCtrl module.

        #attr.SetFont('SymbolPS') #CharacterStyleName

You probably want SetFontFaceName.

***** MY CODE ATTEMPTS STARTING AT LINE 25 OF THE DEMO FOR RICHTEXTCTRL
*****
    self.rtc.BeginAlignment(rt.TEXT_ALIGNMENT_CENTRE)
        self.rtc.BeginBold()

        # Thom Modified Starting Here
        self.rtc.BeginFontSize(14)
        self.rtc.WriteText("This is Greek")
        self.rtc.EndFontSize()

        fontData = wx.FontData()
        fontData.EnableEffects(False)
        attr = rt.RichTextAttr()
        attr.SetFlags(rt.TEXT_ATTR_FONT)
        if self.rtc.GetStyle(0, attr):
            fontData.SetInitialFont(attr.CreateFont())

        font = 'SymbolPS'
        if font:
            attr.SetFlags(rt.TEXT_ATTR_FONT)
            attr.SetFontFaceName(font)
            self.rtc.SetStyle(r, attr)

        self.rtc.Newline()

        #attr = rt.RichTextAttr()
        #attr.SetFlags(rt.TEXT_ATTR_FONT)
        #attr.SetFont('4-KeyTimesRoman') #CharacterStyleName
        #self.rtc.SetStyle((0,8),attr)

        # Thom's Modifications Ended Here

        self.rtc.BeginFontSize(14)
        self.rtc.WriteText("Velcome to wxRichTextCtrl, a wxWidgets
control for editing and presenting styled text and images")
        self.rtc.EndFontSize()
        self.rtc.Newline()

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

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

Ives, Thomas Wayne wrote:

Robin,

I appreciate your reply. I had already tried what you suggest from
looking at the wxWidgets manual (SetFont is nowhere to be found in the
wxWidgets manual). If you look down lower in the RichTextCtrl demo file,
at the OnFont function, you will see that I am only trying to mimic what
goes on there, and you will see that Julian uses "attr.SetFont(..."

I think the crux of the problem is that I am not supplying the right
information to SetFont (i.e. font = <what to put here>), but I have been
unable to figure out how to find out what it needs.

It needs a wx.Font object. To create a font with a specific face name you either need to set it in the constructor, or with SetFaceName.

···

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