font size following image in a RichTextCtrl

When using a RichTextCtrl in which I set the font size, and also
include an image, I find that everything works as expected except for
when the cursor is just to the right of the image. When in this
position, text that is entered does not honor the document font size.

Here's a short example, and note that if you move the cursor directly
to the right of the image and enter some text, the font size will not
be correct (though everywhere else works fine). At least on my system
(Mac OS X, Snow Leopard, Python 2.5, wxPython 2.8.10.1) the characters
appear at about half the size. (And thanks in advance for any help...
this has me quite confused.)

import wx
import wx.richtext as rtcm

class MyRTC(rtcm.RichTextCtrl):

    def __init__(self, parent):
        rtcm.RichTextCtrl.__init__(self, parent, -1, style=wx.VSCROLL|
wx.HSCROLL|wx.NO_BORDER|wx.WANTS_CHARS)
        self.BeginFontSize(20)
        self.AddTextAndImage()

    def AddTextAndImage(self):
        bmp = wx.EmptyBitmap(30, 30, -1)
        dc = wx.MemoryDC(bmp)
        dc.DrawCircle(15,15,15)
        img = bmp.ConvertToImage()
        self.WriteText("abc")
        self.WriteImage(img)
        self.WriteText("xyz")

app = wx.PySimpleApp()
frame = wx.Frame(None, -1, "RTC font size", size=(300,200))
frame.Show(True)
tc = MyRTC(frame)
app.MainLoop()

That's odd alright.

I observe the same behavior, although I don't know why.

This will fix the problem tho:

  font = wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False)
  self.SetFont(font)
        #self.BeginFontSize(20)

That's odd alright.

I observe the same behavior, although I don't know why.

This will fix the problem tho:

    font = wx\.Font\(20, wx\.SWISS, wx\.NORMAL, wx\.NORMAL, False\)
    self\.SetFont\(font\)
    \#self\.BeginFontSize\(20\)

Thanks for your reply and it works in this toy example, but using
SetFont won't work a my actual app because SetFont changes the font
for the entire document. For example, if the doc starts in italics,
and then I change to normal, the italics is also changed. Is there a
way to make this not happen with SetFont, and if not, are there any
ideas about how to make local changes?

One observation from the demo might give a clue to this: when the
smiley is copied and pasted into sections of modified fonts (e.g. the
blue region), everything works fine and text entered after the pasted
smiley is OK, but if the smiley is added programatically using
WriteImage, entered text shows the same problem as in my demo. So
maybe there's a cheat here, where I can programatically create the
same consequence as the manual copy and paste?

Please ask about this on the wx-users maillist. The author of wxRichTextCtrl will see it there.

···

On 1/20/10 10:14 AM, Tom wrote:

When using a RichTextCtrl in which I set the font size, and also
include an image, I find that everything works as expected except for
when the cursor is just to the right of the image. When in this
position, text that is entered does not honor the document font size.

Here's a short example, and note that if you move the cursor directly
to the right of the image and enter some text, the font size will not
be correct (though everywhere else works fine). At least on my system
(Mac OS X, Snow Leopard, Python 2.5, wxPython 2.8.10.1) the characters
appear at about half the size. (And thanks in advance for any help...
this has me quite confused.)

--
Robin Dunn
Software Craftsman

Please ask about this on the wx-users maillist. The author of
wxRichTextCtrl will see it there.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

OK, I asked it there. Here's the link if anyone wants to follow
along:
http://groups.google.com/group/wx-users/browse_thread/thread/1fc901d73cfc4b75