]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/FontDialog.py
4 #---------------------------------------------------------------------------
6 class TestPanel(wx
.Panel
):
7 def __init__(self
, parent
, log
):
8 wx
.Panel
.__init
__(self
, parent
, -1)
11 btn
= wx
.Button(self
, -1, "Select Font")
12 self
.Bind(wx
.EVT_BUTTON
, self
.OnSelectFont
, btn
)
14 self
.sampleText
= wx
.TextCtrl(self
, -1, "Sample Text")
16 self
.curFont
= self
.sampleText
.GetFont()
17 self
.curClr
= wx
.BLACK
19 fgs
= wx
.FlexGridSizer(cols
=2, vgap
=5, hgap
=5)
24 fgs
.Add(self
.sampleText
, 0, wx
.ADJUST_MINSIZE|wx
.GROW
)
26 fgs
.Add((15,15)); fgs
.Add((15,15)) # an empty row
28 fgs
.Add(wx
.StaticText(self
, -1, "PointSize:"))
29 self
.ps
= wx
.StaticText(self
, -1, "")
30 font
= self
.ps
.GetFont()
31 font
.SetWeight(wx
.BOLD
)
33 fgs
.Add(self
.ps
, 0, wx
.ADJUST_MINSIZE
)
35 fgs
.Add(wx
.StaticText(self
, -1, "Family:"))
36 self
.family
= wx
.StaticText(self
, -1, "")
37 self
.family
.SetFont(font
)
38 fgs
.Add(self
.family
, 0, wx
.ADJUST_MINSIZE
)
40 fgs
.Add(wx
.StaticText(self
, -1, "Style:"))
41 self
.style
= wx
.StaticText(self
, -1, "")
42 self
.style
.SetFont(font
)
43 fgs
.Add(self
.style
, 0, wx
.ADJUST_MINSIZE
)
45 fgs
.Add(wx
.StaticText(self
, -1, "Weight:"))
46 self
.weight
= wx
.StaticText(self
, -1, "")
47 self
.weight
.SetFont(font
)
48 fgs
.Add(self
.weight
, 0, wx
.ADJUST_MINSIZE
)
50 fgs
.Add(wx
.StaticText(self
, -1, "Face:"))
51 self
.face
= wx
.StaticText(self
, -1, "")
52 self
.face
.SetFont(font
)
53 fgs
.Add(self
.face
, 0, wx
.ADJUST_MINSIZE
)
55 fgs
.Add((15,15)); fgs
.Add((15,15)) # an empty row
57 fgs
.Add(wx
.StaticText(self
, -1, "wx.NativeFontInfo:"))
58 self
.nfi
= wx
.StaticText(self
, -1, "")
59 self
.nfi
.SetFont(font
)
60 fgs
.Add(self
.nfi
, 0, wx
.ADJUST_MINSIZE
)
62 # give it some border space
63 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
64 sizer
.Add(fgs
, 0, wx
.GROW|wx
.ADJUST_MINSIZE|wx
.ALL
, 25)
71 self
.sampleText
.SetFont(self
.curFont
)
72 self
.ps
.SetLabel(str(self
.curFont
.GetPointSize()))
73 self
.family
.SetLabel(self
.curFont
.GetFamilyString())
74 self
.style
.SetLabel(self
.curFont
.GetStyleString())
75 self
.weight
.SetLabel(self
.curFont
.GetWeightString())
76 self
.face
.SetLabel(self
.curFont
.GetFaceName())
77 self
.nfi
.SetLabel(self
.curFont
.GetNativeFontInfo().ToString())
81 def OnSelectFont(self
, evt
):
83 data
.EnableEffects(True)
84 data
.SetColour(self
.curClr
) # set colour
85 data
.SetInitialFont(self
.curFont
)
87 dlg
= wx
.FontDialog(self
, data
)
89 if dlg
.ShowModal() == wx
.ID_OK
:
90 data
= dlg
.GetFontData()
91 font
= data
.GetChosenFont()
92 colour
= data
.GetColour()
94 self
.log
.WriteText('You selected: "%s", %d points, color %s\n' %
95 (font
.GetFaceName(), font
.GetPointSize(),
102 # Don't destroy the dialog until you get everything you need from the
107 #---------------------------------------------------------------------------
109 def runTest(frame
, nb
, log
):
110 win
= TestPanel(nb
, log
)
113 #---------------------------------------------------------------------------
117 This class allows you to use the system font selection dialog
118 from within your program. Generally speaking, this allows you
119 to select a font by its name, font size, and weight, and
120 on some systems such things as strikethrough and underline.
122 As with other dialogs used in wxPython, it is important to
123 use the class' methods to extract the information you need
124 about the font <b>before</b> you destroy the dialog. Failure
125 to observe this almost always leads to a program failure of
126 some sort, often ugly.
128 This demo serves two purposes; it shows how to use the dialog
129 to GET font information from the user, but also shows how
130 to APPLY that information once you get it.
134 if __name__
== '__main__':
137 run
.main(['', os
.path
.basename(sys
.argv
[0])])