Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

font size following image in a RichTextCtrl

5 views
Skip to first unread message

Tom

unread,
Jan 25, 2010, 12:39:00 PM1/25/10
to wx-users
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 current 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()

Some other notes which may be useful:
1) I need to use multiple fonts and styles within the same document,
so I can't just use SetFont.
2) One observation from the demo: when the smiley image 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?
3) I originally posted this to the wxPython group and they directed me
to wx-users. If anyone cares to see, the link is here:
http://groups.google.com/group/wxpython-users/browse_thread/thread/b5d9f26b54f12ba0

Reply all
Reply to author
Forward
0 new messages