]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxFontDialog.py
fixed extraneous scrolling when scrollbars are added/removed (patch 788026; bug 746618)
[wxWidgets.git] / wxPython / demo / wxFontDialog.py
CommitLineData
cf694132
RD
1
2from wxPython.wx import *
3
4#---------------------------------------------------------------------------
5
1e4a197e
RD
6class TestPanel(wxPanel):
7 def __init__(self, parent, log):
8 wxPanel.__init__(self, parent, -1)
9 self.log = log
cf694132 10
1e4a197e
RD
11 btn = wxButton(self, -1, "Select Font")
12 EVT_BUTTON(self, btn.GetId(), self.OnSelectFont)
cf694132 13
1e4a197e
RD
14 self.sampleText = wxTextCtrl(self, -1, "Sample Text")
15 #from wxPython.lib.stattext import wxGenStaticText
16 #self.sampleText = wxGenStaticText(self, -1, "Sample Text")
cf694132 17
1e4a197e
RD
18 self.curFont = self.sampleText.GetFont()
19 self.curClr = wxBLACK
cf694132 20
1e4a197e
RD
21 fgs = wxFlexGridSizer(cols=2, vgap=5, hgap=5)
22 fgs.AddGrowableCol(1)
23 fgs.AddGrowableRow(0)
cf694132 24
1e4a197e
RD
25 fgs.Add(btn)
26 fgs.Add(self.sampleText, 0, wxADJUST_MINSIZE|wxGROW)
cf694132 27
1e4a197e 28 fgs.Add(15,15); fgs.Add(15,15) # an empty row
cf694132 29
1e4a197e
RD
30 fgs.Add(wxStaticText(self, -1, "PointSize:"))
31 self.ps = wxStaticText(self, -1, "")
32 font = self.ps.GetFont()
33 font.SetWeight(wxBOLD)
34 self.ps.SetFont(font)
35 fgs.Add(self.ps, 0, wxADJUST_MINSIZE)
cf694132 36
1e4a197e
RD
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)
cf694132 41
1e4a197e
RD
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)
cf694132 46
1e4a197e
RD
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)
cf694132 51
1e4a197e
RD
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)
cf694132 56
1e4a197e 57 fgs.Add(15,15); fgs.Add(15,15) # an empty row
cf694132 58
1e4a197e
RD
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)
63
64 # give it some border space
65 sizer = wxBoxSizer(wxVERTICAL)
66 sizer.Add(fgs, 0, wxGROW|wxADJUST_MINSIZE|wxALL, 25)
67
68 self.SetSizer(sizer)
69 self.UpdateUI()
70
71
72 def UpdateUI(self):
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())
80 self.Layout()
cf694132 81
cf694132 82
1e4a197e
RD
83 def OnSelectFont(self, evt):
84 data = wxFontData()
85 data.EnableEffects(True)
86 data.SetColour(self.curClr) # set colour
87 data.SetInitialFont(self.curFont)
cf694132 88
1e4a197e
RD
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(),
96 colour.Get()))
97 self.curFont = font
98 self.curClr = colour
99 self.UpdateUI()
100 dlg.Destroy()
101
102
103
104
105
106#---------------------------------------------------------------------------
107
108def runTest(frame, nb, log):
109 win = TestPanel(nb, log)
110 return win
111
112
113#---------------------------------------------------------------------------
114
115
116
117
118overview = """\
119This class allows you to use the system font chooser dialog.
cf694132 120
cf694132 121"""
1e4a197e
RD
122
123
124
125if __name__ == '__main__':
126 import sys,os
127 import run
128 run.main(['', os.path.basename(sys.argv[0])])
129