简体   繁体   中英

Getting a RichTextCtrl's default font size in wxPython

I have a RichTextCtrl , which I've modified to accept HTML input. The HTML parsing code needs to be able to increase and decrease the font size as it gets tags like <font size="-1"> , but I can't work out how to get the control's default font size to adjust.
I tried the following (where self is my RichTextCtrl ):

fred = wx.richtext.RichTextAttr()
self.GetStyle(0,fred)
print fred.GetFontSize()

However, the final instruction fails, because GetStyle turns fred into a TextAttrEx and so I get AttributeError: 'TextAttrEx' object has no attribute 'GetFontSize' . Am I missing a vastly easier way of getting the default font size?

Worked this out. Before any data is written to the control:

self.defaultstyle = wx.richtext.RichTextAttr()
self.GetStyle(self.GetInsertionPoint(), self.defaultstyle)
self.defaultsize = self.defaultstyle.GetFont().GetPointSize()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM