1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import wx
20
21
22 FONT_FACE_ENCODING = "utf-8"
23
24
26
27 - def __init__(self, point_size=12, family=wx.FONTFAMILY_DEFAULT, style=wx.FONTSTYLE_NORMAL,
28 weight=wx.FONTWEIGHT_NORMAL, underlined=False, face_name="", encoding=wx.FONTENCODING_DEFAULT,
29 wxcolor=wx.BLACK):
30 self.wxcolor = wxcolor
31 wx.Font.__init__(self, point_size, family, style, weight, underlined, face_name, encoding)
32
35
37 self.wxcolor = wxcolor
38
39 WxColor = property(_get_wxcolor, _set_wxcolor)
40
43
45 self.PointSize = wxfont.PointSize
46 self.Family = wxfont.Family
47 self.Style = wxfont.Style
48 self.Weight = wxfont.Weight
49 self.SetUnderlined(wxfont.GetUnderlined())
50 self.FaceName = wxfont.FaceName
51 self.Encoding = wxfont.Encoding
52
53 WxFont = property(_get_wxfont, _set_wxfont)
54
56 return "%s:%s:%s:%s:%s:%s:%s:%s" % (
57 self.PointSize,
58 self.Family,
59 self.Style,
60 self.Weight,
61 self.GetUnderlined(),
62 self.FaceName.encode(FONT_FACE_ENCODING),
63 self.Encoding,
64 self.WxColor,
65 )
66
68 self.PointSize += step
69
71 self.PointSize -= step
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93 font_cache = {}
94
95
97 if serialized_font not in font_cache:
98 bool_map = {"True": True, "False": False}
99 (
100 point_size,
101 family,
102 style,
103 weight,
104 underlined,
105 facename,
106 encoding,
107 color,
108 ) = serialized_font.split(":")
109 color_args = color[1:-1].split(",")
110 wxcolor = wx.Colour(
111 int(color_args[0]),
112 int(color_args[1]),
113 int(color_args[2]),
114 int(color_args[3])
115 )
116 font = Font(
117 int(point_size),
118 int(family),
119 int(style),
120 int(weight),
121 bool_map[underlined],
122 facename.decode(FONT_FACE_ENCODING),
123 int(encoding),
124 wxcolor
125 )
126 font_cache[serialized_font] = font
127 return font_cache[serialized_font]
128
129
130 -def set_minor_strip_text_font(font, dc, force_bold=False, force_normal=False, force_italic=False, force_upright=False):
131 set_text_font(font, dc, force_bold, force_normal, force_italic, force_upright)
132
133
134 -def set_major_strip_text_font(font, dc, force_bold=False, force_normal=False, force_italic=False, force_upright=False):
135 set_text_font(font, dc, force_bold, force_normal, force_italic, force_upright)
136
137
138 -def set_balloon_text_font(font, dc, force_bold=False, force_normal=False, force_italic=False, force_upright=False):
139 set_text_font(font, dc, force_bold, force_normal, force_italic, force_upright)
140
141
144
145
146 -def set_text_font(selectable_font, dc, force_bold=False, force_normal=False, force_italic=False, force_upright=False):
147 font = deserialize_font(selectable_font)
148 old_weight = font.Weight
149 old_style = font.Style
150 if force_bold:
151 font.Weight = wx.FONTWEIGHT_BOLD
152 elif force_normal:
153 font.Weight = wx.FONTWEIGHT_NORMAL
154 if force_italic:
155 font.Style = wx.FONTSTYLE_ITALIC
156 elif force_upright:
157 font.Style = wx.FONTSTYLE_NORMAL
158 dc.SetFont(font)
159 dc.SetTextForeground(font.WxColor)
160 font.Style = old_style
161 font.Weight = old_weight
162
163
165 data = wx.FontData()
166 data.SetInitialFont(font)
167 data.SetColour(font.WxColor)
168 dialog = wx.FontDialog(parent_window, data)
169 try:
170 if dialog.ShowModal() == wx.ID_OK:
171 font_data = dialog.GetFontData()
172 font.WxFont = font_data.GetChosenFont()
173 font.WxColor = font_data.GetColour()
174 return True
175 else:
176 return False
177 finally:
178 dialog.Destroy()
179