python wx提示框字体_Python wx.FontDialog方法代碼示例

# 需要導入模塊: import wx [as 別名]

# 或者: from wx import FontDialog [as 別名]

def OnButtonSelect(self, evt):

if self.textModified: # text has newer value

try:

self.value = eval(self.text.GetValue())

except SyntaxError:

wx.LogError('Syntax error in parameter value: ' + self.GetName())

self.value = self._defaultValue()

# Make initial font

# Default values

size = g._sysFont.GetPointSize()

family = wx.DEFAULT

style = weight = wx.NORMAL

underlined = 0

face = ''

enc = wx.FONTENCODING_DEFAULT

# Fall back to default if exceptions

error = False

try:

try: size = int(self.value[0])

except ValueError: error = True; wx.LogError('Invalid size specification')

try: family = fontFamiliesXml2wx[self.value[1]]

except KeyError: error = True; wx.LogError('Invalid family specification')

try: style = fontStylesXml2wx[self.value[2]]

except KeyError: error = True; wx.LogError('Invalid style specification')

try: weight = fontWeightsXml2wx[self.value[3]]

except KeyError: error = True; wx.LogError('Invalid weight specification')

try: underlined = bool(self.value[4])

except ValueError: error = True; wx.LogError('Invalid underlined flag specification')

face = self.value[5]

except IndexError:

error = True

mapper = wx.FontMapper()

if not self.value[6]: enc = mapper.CharsetToEncoding(self.value[6])

if error: wx.LogError('Invalid font specification')

if enc == wx.FONTENCODING_DEFAULT: enc = wx.FONTENCODING_SYSTEM

font = wx.Font(size, family, style, weight, underlined, face, enc)

data = wx.FontData()

data.SetInitialFont(font)

dlg = wx.FontDialog(self, data)

if dlg.ShowModal() == wx.ID_OK:

font = dlg.GetFontData().GetChosenFont()

if font.GetEncoding() == wx.FONTENCODING_SYSTEM:

encName = ''

else:

encName = wx.FontMapper.GetEncodingName(font.GetEncoding()).encode()

value = [str(font.GetPointSize()),

fontFamiliesWx2Xml.get(font.GetFamily(), "default"),

fontStylesWx2Xml.get(font.GetStyle(), "normal"),

fontWeightsWx2Xml.get(font.GetWeight(), "normal"),

str(int(font.GetUnderlined())),

font.GetFaceName().encode(),

encName

]

self.SetValue(value)

self.SetModified()

self.textModified = False

dlg.Destroy()

################################################################################

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值