]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/demo/FontDialog.py
Another package name fix
[wxWidgets.git] / wxPython / demo / FontDialog.py
... / ...
CommitLineData
1
2import wx
3from wx.lib import stattext
4
5#---------------------------------------------------------------------------
6
7class TestPanel(wx.Panel):
8 def __init__(self, parent, log):
9 wx.Panel.__init__(self, parent, -1)
10 self.log = log
11
12 btn = wx.Button(self, -1, "Select Font")
13 self.Bind(wx.EVT_BUTTON, self.OnSelectFont, btn)
14
15 self.sampleText = stattext.GenStaticText(self, -1, "Sample Text")
16 self.sampleText.SetBackgroundColour(wx.WHITE)
17
18 self.curFont = self.sampleText.GetFont()
19 self.curClr = wx.BLACK
20
21 fgs = wx.FlexGridSizer(cols=2, vgap=5, hgap=5)
22 fgs.AddGrowableCol(1)
23 fgs.AddGrowableRow(0)
24
25 fgs.Add(btn)
26 fgs.Add(self.sampleText, 0, wx.ADJUST_MINSIZE|wx.GROW)
27
28 fgs.Add((15,15)); fgs.Add((15,15)) # an empty row
29
30 fgs.Add(wx.StaticText(self, -1, "PointSize:"))
31 self.ps = wx.StaticText(self, -1, "")
32 font = self.ps.GetFont()
33 font.SetWeight(wx.BOLD)
34 self.ps.SetFont(font)
35 fgs.Add(self.ps, 0, wx.ADJUST_MINSIZE)
36
37 fgs.Add(wx.StaticText(self, -1, "Family:"))
38 self.family = wx.StaticText(self, -1, "")
39 self.family.SetFont(font)
40 fgs.Add(self.family, 0, wx.ADJUST_MINSIZE)
41
42 fgs.Add(wx.StaticText(self, -1, "Style:"))
43 self.style = wx.StaticText(self, -1, "")
44 self.style.SetFont(font)
45 fgs.Add(self.style, 0, wx.ADJUST_MINSIZE)
46
47 fgs.Add(wx.StaticText(self, -1, "Weight:"))
48 self.weight = wx.StaticText(self, -1, "")
49 self.weight.SetFont(font)
50 fgs.Add(self.weight, 0, wx.ADJUST_MINSIZE)
51
52 fgs.Add(wx.StaticText(self, -1, "Face:"))
53 self.face = wx.StaticText(self, -1, "")
54 self.face.SetFont(font)
55 fgs.Add(self.face, 0, wx.ADJUST_MINSIZE)
56
57 fgs.Add((15,15)); fgs.Add((15,15)) # an empty row
58
59 fgs.Add(wx.StaticText(self, -1, "wx.NativeFontInfo:"))
60 self.nfi = wx.StaticText(self, -1, "")
61 self.nfi.SetFont(font)
62 fgs.Add(self.nfi, 0, wx.ADJUST_MINSIZE)
63
64 # give it some border space
65 sizer = wx.BoxSizer(wx.VERTICAL)
66 sizer.Add(fgs, 0, wx.GROW|wx.ADJUST_MINSIZE|wx.ALL, 25)
67
68 self.SetSizer(sizer)
69 self.UpdateUI()
70
71
72 def UpdateUI(self):
73 self.sampleText.SetFont(self.curFont)
74 self.sampleText.SetForegroundColour(self.curClr)
75 self.ps.SetLabel(str(self.curFont.GetPointSize()))
76 self.family.SetLabel(self.curFont.GetFamilyString())
77 self.style.SetLabel(self.curFont.GetStyleString())
78 self.weight.SetLabel(self.curFont.GetWeightString())
79 self.face.SetLabel(self.curFont.GetFaceName())
80 self.nfi.SetLabel(self.curFont.GetNativeFontInfo().ToString())
81 self.Layout()
82
83
84 def OnSelectFont(self, evt):
85 data = wx.FontData()
86 data.EnableEffects(True)
87 data.SetColour(self.curClr) # set colour
88 data.SetInitialFont(self.curFont)
89
90 dlg = wx.FontDialog(self, data)
91
92 if dlg.ShowModal() == wx.ID_OK:
93 data = dlg.GetFontData()
94 font = data.GetChosenFont()
95 colour = data.GetColour()
96
97 self.log.WriteText('You selected: "%s", %d points, color %s\n' %
98 (font.GetFaceName(), font.GetPointSize(),
99 colour.Get()))
100
101 self.curFont = font
102 self.curClr = colour
103 self.UpdateUI()
104
105 # Don't destroy the dialog until you get everything you need from the
106 # dialog!
107 dlg.Destroy()
108
109
110#---------------------------------------------------------------------------
111
112def runTest(frame, nb, log):
113 win = TestPanel(nb, log)
114 return win
115
116#---------------------------------------------------------------------------
117
118
119overview = """\
120This class allows you to use the system font selection dialog
121from within your program. Generally speaking, this allows you
122to select a font by its name, font size, and weight, and
123on some systems such things as strikethrough and underline.
124
125As with other dialogs used in wxPython, it is important to
126use the class' methods to extract the information you need
127about the font <b>before</b> you destroy the dialog. Failure
128to observe this almost always leads to a program failure of
129some sort, often ugly.
130
131This demo serves two purposes; it shows how to use the dialog
132to GET font information from the user, but also shows how
133to APPLY that information once you get it.
134
135"""
136
137if __name__ == '__main__':
138 import sys,os
139 import run
140 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
141