2 from wxPython
.wx
import *
4 #---------------------------------------------------------------------------
6 class TestPanel(wxPanel
):
7 def __init__(self
, parent
, log
):
8 wxPanel
.__init
__(self
, parent
, -1)
11 btn
= wxButton(self
, -1, "Select Font")
12 EVT_BUTTON(self
, btn
.GetId(), self
.OnSelectFont
)
14 self
.sampleText
= wxTextCtrl(self
, -1, "Sample Text")
15 #from wxPython.lib.stattext import wxGenStaticText
16 #self.sampleText = wxGenStaticText(self, -1, "Sample Text")
18 self
.curFont
= self
.sampleText
.GetFont()
21 fgs
= wxFlexGridSizer(cols
=2, vgap
=5, hgap
=5)
26 fgs
.Add(self
.sampleText
, 0, wxADJUST_MINSIZE|wxGROW
)
28 fgs
.Add(15,15); fgs
.Add(15,15) # an empty row
30 fgs
.Add(wxStaticText(self
, -1, "PointSize:"))
31 self
.ps
= wxStaticText(self
, -1, "")
32 font
= self
.ps
.GetFont()
33 font
.SetWeight(wxBOLD
)
35 fgs
.Add(self
.ps
, 0, wxADJUST_MINSIZE
)
37 fgs
.Add(wxStaticText(self
, -1, "Family:"))
38 self
.family
= wxStaticText(self
, -1, "")
39 self
.family
.SetFont(font
)
40 fgs
.Add(self
.family
, 0, wxADJUST_MINSIZE
)
42 fgs
.Add(wxStaticText(self
, -1, "Style:"))
43 self
.style
= wxStaticText(self
, -1, "")
44 self
.style
.SetFont(font
)
45 fgs
.Add(self
.style
, 0, wxADJUST_MINSIZE
)
47 fgs
.Add(wxStaticText(self
, -1, "Weight:"))
48 self
.weight
= wxStaticText(self
, -1, "")
49 self
.weight
.SetFont(font
)
50 fgs
.Add(self
.weight
, 0, wxADJUST_MINSIZE
)
52 fgs
.Add(wxStaticText(self
, -1, "Face:"))
53 self
.face
= wxStaticText(self
, -1, "")
54 self
.face
.SetFont(font
)
55 fgs
.Add(self
.face
, 0, wxADJUST_MINSIZE
)
57 fgs
.Add(15,15); fgs
.Add(15,15) # an empty row
59 fgs
.Add(wxStaticText(self
, -1, "wxNativeFontInfo:"))
60 self
.nfi
= wxStaticText(self
, -1, "")
61 self
.nfi
.SetFont(font
)
62 fgs
.Add(self
.nfi
, 0, wxADJUST_MINSIZE
)
64 # give it some border space
65 sizer
= wxBoxSizer(wxVERTICAL
)
66 sizer
.Add(fgs
, 0, wxGROW|wxADJUST_MINSIZE|wxALL
, 25)
73 self
.sampleText
.SetFont(self
.curFont
)
74 self
.ps
.SetLabel(str(self
.curFont
.GetPointSize()))
75 self
.family
.SetLabel(self
.curFont
.GetFamilyString())
76 self
.style
.SetLabel(self
.curFont
.GetStyleString())
77 self
.weight
.SetLabel(self
.curFont
.GetWeightString())
78 self
.face
.SetLabel(self
.curFont
.GetFaceName())
79 self
.nfi
.SetLabel(self
.curFont
.GetNativeFontInfo().ToString())
83 def OnSelectFont(self
, evt
):
85 data
.EnableEffects(True)
86 data
.SetColour(self
.curClr
) # set colour
87 data
.SetInitialFont(self
.curFont
)
89 dlg
= wxFontDialog(self
, data
)
90 if dlg
.ShowModal() == wxID_OK
:
91 data
= dlg
.GetFontData()
92 font
= data
.GetChosenFont()
93 colour
= data
.GetColour()
94 self
.log
.WriteText('You selected: "%s", %d points, color %s\n' %
95 (font
.GetFaceName(), font
.GetPointSize(),
106 #---------------------------------------------------------------------------
108 def runTest(frame
, nb
, log
):
109 win
= TestPanel(nb
, log
)
113 #---------------------------------------------------------------------------
119 This class allows you to use the system font chooser dialog.
125 if __name__
== '__main__':
128 run
.main(['', os
.path
.basename(sys
.argv
[0])])