简体   繁体   English

在wxPython中获取RichTextCtrl的默认字体大小

[英]Getting a RichTextCtrl's default font size in wxPython

I have a RichTextCtrl , which I've modified to accept HTML input. 我有一个RichTextCtrl ,已对其进行了修改以接受HTML输入。 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. HTML解析代码需要能够获得和减小诸如<font size="-1">类的标记时的<font size="-1"> ,但是我不知道如何调整控件的默认字体大小。
I tried the following (where self is my RichTextCtrl ): 我尝试了以下操作(其中self是我的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' . 但是,最后一条指令失败了,因为GetStyle将fred变成了TextAttrEx ,所以我得到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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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