# 需要導入模塊: 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()
################################################################################