]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxFontDialog.py
fix text scrolling in GTK2 (patch 703988)
[wxWidgets.git] / wxPython / demo / wxFontDialog.py
1
2 from wxPython.wx import *
3
4 #---------------------------------------------------------------------------
5
6 class TestPanel(wxPanel):
7 def __init__(self, parent, log):
8 wxPanel.__init__(self, parent, -1)
9 self.log = log
10
11 btn = wxButton(self, -1, "Select Font")
12 EVT_BUTTON(self, btn.GetId(), self.OnSelectFont)
13
14 self.sampleText = wxTextCtrl(self, -1, "Sample Text")
15 #from wxPython.lib.stattext import wxGenStaticText
16 #self.sampleText = wxGenStaticText(self, -1, "Sample Text")
17
18 self.curFont = self.sampleText.GetFont()
19 self.curClr = wxBLACK
20
21 fgs = wxFlexGridSizer(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, wxADJUST_MINSIZE|wxGROW)
27
28 fgs.Add(15,15); fgs.Add(15,15) # an empty row
29
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)
36
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)
41
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)
46
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)
51
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)
56
57 fgs.Add(15,15); fgs.Add(15,15) # an empty row
58
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()
81
82
83 def OnSelectFont(self, evt):
84 data = wxFontData()
85 data.EnableEffects(True)
86 data.SetColour(self.curClr) # set colour
87 data.SetInitialFont(self.curFont)
88
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
108 def runTest(frame, nb, log):
109 win = TestPanel(nb, log)
110 return win
111
112
113 #---------------------------------------------------------------------------
114
115
116
117
118 overview = """\
119 This class allows you to use the system font chooser dialog.
120
121 """
122
123
124
125 if __name__ == '__main__':
126 import sys,os
127 import run
128 run.main(['', os.path.basename(sys.argv[0])])
129