]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxFontDialog.py
1 # 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
8 #---------------------------------------------------------------------------
10 class TestPanel(wx
.Panel
):
11 def __init__(self
, parent
, log
):
12 wx
.Panel
.__init
__(self
, parent
, -1)
15 btn
= wx
.Button(self
, -1, "Select Font")
16 self
.Bind(wx
.EVT_BUTTON
, self
.OnSelectFont
, btn
)
18 self
.sampleText
= wx
.TextCtrl(self
, -1, "Sample Text")
19 #from wxPython.lib.stattext import wxGenStaticText
20 #self.sampleText = wxGenStaticText(self, -1, "Sample Text")
22 self
.curFont
= self
.sampleText
.GetFont()
23 self
.curClr
= wx
.BLACK
25 fgs
= wx
.FlexGridSizer(cols
=2, vgap
=5, hgap
=5)
30 fgs
.Add(self
.sampleText
, 0, wx
.ADJUST_MINSIZE|wx
.GROW
)
32 fgs
.Add((15,15)); fgs
.Add((15,15)) # an empty row
34 fgs
.Add(wx
.StaticText(self
, -1, "PointSize:"))
35 self
.ps
= wx
.StaticText(self
, -1, "")
36 font
= self
.ps
.GetFont()
37 font
.SetWeight(wx
.BOLD
)
39 fgs
.Add(self
.ps
, 0, wx
.ADJUST_MINSIZE
)
41 fgs
.Add(wx
.StaticText(self
, -1, "Family:"))
42 self
.family
= wx
.StaticText(self
, -1, "")
43 self
.family
.SetFont(font
)
44 fgs
.Add(self
.family
, 0, wx
.ADJUST_MINSIZE
)
46 fgs
.Add(wx
.StaticText(self
, -1, "Style:"))
47 self
.style
= wx
.StaticText(self
, -1, "")
48 self
.style
.SetFont(font
)
49 fgs
.Add(self
.style
, 0, wx
.ADJUST_MINSIZE
)
51 fgs
.Add(wx
.StaticText(self
, -1, "Weight:"))
52 self
.weight
= wx
.StaticText(self
, -1, "")
53 self
.weight
.SetFont(font
)
54 fgs
.Add(self
.weight
, 0, wx
.ADJUST_MINSIZE
)
56 fgs
.Add(wx
.StaticText(self
, -1, "Face:"))
57 self
.face
= wx
.StaticText(self
, -1, "")
58 self
.face
.SetFont(font
)
59 fgs
.Add(self
.face
, 0, wx
.ADJUST_MINSIZE
)
61 fgs
.Add((15,15)); fgs
.Add((15,15)) # an empty row
63 fgs
.Add(wx
.StaticText(self
, -1, "wx.NativeFontInfo:"))
64 self
.nfi
= wx
.StaticText(self
, -1, "")
65 self
.nfi
.SetFont(font
)
66 fgs
.Add(self
.nfi
, 0, wx
.ADJUST_MINSIZE
)
68 # give it some border space
69 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
70 sizer
.Add(fgs
, 0, wx
.GROW|wx
.ADJUST_MINSIZE|wx
.ALL
, 25)
77 self
.sampleText
.SetFont(self
.curFont
)
78 self
.ps
.SetLabel(str(self
.curFont
.GetPointSize()))
79 self
.family
.SetLabel(self
.curFont
.GetFamilyString())
80 self
.style
.SetLabel(self
.curFont
.GetStyleString())
81 self
.weight
.SetLabel(self
.curFont
.GetWeightString())
82 self
.face
.SetLabel(self
.curFont
.GetFaceName())
83 self
.nfi
.SetLabel(self
.curFont
.GetNativeFontInfo().ToString())
87 def OnSelectFont(self
, evt
):
89 data
.EnableEffects(True)
90 data
.SetColour(self
.curClr
) # set colour
91 data
.SetInitialFont(self
.curFont
)
93 dlg
= wx
.FontDialog(self
, data
)
95 if dlg
.ShowModal() == wx
.ID_OK
:
96 data
= dlg
.GetFontData()
97 font
= data
.GetChosenFont()
98 colour
= data
.GetColour()
100 self
.log
.WriteText('You selected: "%s", %d points, color %s\n' %
101 (font
.GetFaceName(), font
.GetPointSize(),
108 # Don't destroy the dialog until you get everything you need from the
113 #---------------------------------------------------------------------------
115 def runTest(frame
, nb
, log
):
116 win
= TestPanel(nb
, log
)
119 #---------------------------------------------------------------------------
123 This class allows you to use the system font selection dialog
124 from within your program. Generally speaking, this allows you
125 to select a font by its name, font size, and weight, and
126 on some systems such things as strikethrough and underline.
128 As with other dialogs used in wxPython, it is important to
129 use the class' methods to extract the information you need
130 about the font <b>before</b> you destroy the dialog. Failure
131 to observe this almost always leads to a program failure of
132 some sort, often ugly.
134 This demo serves two purposes; it shows how to use the dialog
135 to GET font information from the user, but also shows how
136 to APPLY that information once you get it.
140 if __name__
== '__main__':
143 run
.main(['', os
.path
.basename(sys
.argv
[0])])