]>
Commit | Line | Data |
---|---|---|
8fa876ca RD |
1 | # 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
2 | # | |
3 | # o Updated for wx namespace | |
4 | # | |
cf694132 | 5 | |
8fa876ca | 6 | import wx |
cf694132 RD |
7 | |
8 | #--------------------------------------------------------------------------- | |
9 | ||
8fa876ca | 10 | class TestPanel(wx.Panel): |
1e4a197e | 11 | def __init__(self, parent, log): |
8fa876ca | 12 | wx.Panel.__init__(self, parent, -1) |
1e4a197e | 13 | self.log = log |
cf694132 | 14 | |
8fa876ca RD |
15 | btn = wx.Button(self, -1, "Select Font") |
16 | self.Bind(wx.EVT_BUTTON, self.OnSelectFont, btn) | |
cf694132 | 17 | |
8fa876ca | 18 | self.sampleText = wx.TextCtrl(self, -1, "Sample Text") |
1e4a197e RD |
19 | #from wxPython.lib.stattext import wxGenStaticText |
20 | #self.sampleText = wxGenStaticText(self, -1, "Sample Text") | |
cf694132 | 21 | |
1e4a197e | 22 | self.curFont = self.sampleText.GetFont() |
8fa876ca | 23 | self.curClr = wx.BLACK |
cf694132 | 24 | |
8fa876ca | 25 | fgs = wx.FlexGridSizer(cols=2, vgap=5, hgap=5) |
1e4a197e RD |
26 | fgs.AddGrowableCol(1) |
27 | fgs.AddGrowableRow(0) | |
cf694132 | 28 | |
1e4a197e | 29 | fgs.Add(btn) |
8fa876ca | 30 | fgs.Add(self.sampleText, 0, wx.ADJUST_MINSIZE|wx.GROW) |
cf694132 | 31 | |
fbd5dd1d | 32 | fgs.Add((15,15)); fgs.Add((15,15)) # an empty row |
cf694132 | 33 | |
8fa876ca RD |
34 | fgs.Add(wx.StaticText(self, -1, "PointSize:")) |
35 | self.ps = wx.StaticText(self, -1, "") | |
1e4a197e | 36 | font = self.ps.GetFont() |
8fa876ca | 37 | font.SetWeight(wx.BOLD) |
1e4a197e | 38 | self.ps.SetFont(font) |
8fa876ca | 39 | fgs.Add(self.ps, 0, wx.ADJUST_MINSIZE) |
cf694132 | 40 | |
8fa876ca RD |
41 | fgs.Add(wx.StaticText(self, -1, "Family:")) |
42 | self.family = wx.StaticText(self, -1, "") | |
1e4a197e | 43 | self.family.SetFont(font) |
8fa876ca | 44 | fgs.Add(self.family, 0, wx.ADJUST_MINSIZE) |
cf694132 | 45 | |
8fa876ca RD |
46 | fgs.Add(wx.StaticText(self, -1, "Style:")) |
47 | self.style = wx.StaticText(self, -1, "") | |
1e4a197e | 48 | self.style.SetFont(font) |
8fa876ca | 49 | fgs.Add(self.style, 0, wx.ADJUST_MINSIZE) |
cf694132 | 50 | |
8fa876ca RD |
51 | fgs.Add(wx.StaticText(self, -1, "Weight:")) |
52 | self.weight = wx.StaticText(self, -1, "") | |
1e4a197e | 53 | self.weight.SetFont(font) |
8fa876ca | 54 | fgs.Add(self.weight, 0, wx.ADJUST_MINSIZE) |
cf694132 | 55 | |
8fa876ca RD |
56 | fgs.Add(wx.StaticText(self, -1, "Face:")) |
57 | self.face = wx.StaticText(self, -1, "") | |
1e4a197e | 58 | self.face.SetFont(font) |
8fa876ca | 59 | fgs.Add(self.face, 0, wx.ADJUST_MINSIZE) |
cf694132 | 60 | |
fbd5dd1d | 61 | fgs.Add((15,15)); fgs.Add((15,15)) # an empty row |
cf694132 | 62 | |
8fa876ca RD |
63 | fgs.Add(wx.StaticText(self, -1, "wx.NativeFontInfo:")) |
64 | self.nfi = wx.StaticText(self, -1, "") | |
1e4a197e | 65 | self.nfi.SetFont(font) |
8fa876ca | 66 | fgs.Add(self.nfi, 0, wx.ADJUST_MINSIZE) |
1e4a197e RD |
67 | |
68 | # give it some border space | |
8fa876ca RD |
69 | sizer = wx.BoxSizer(wx.VERTICAL) |
70 | sizer.Add(fgs, 0, wx.GROW|wx.ADJUST_MINSIZE|wx.ALL, 25) | |
1e4a197e RD |
71 | |
72 | self.SetSizer(sizer) | |
73 | self.UpdateUI() | |
74 | ||
75 | ||
76 | def UpdateUI(self): | |
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()) | |
84 | self.Layout() | |
cf694132 | 85 | |
cf694132 | 86 | |
1e4a197e | 87 | def OnSelectFont(self, evt): |
8fa876ca | 88 | data = wx.FontData() |
1e4a197e RD |
89 | data.EnableEffects(True) |
90 | data.SetColour(self.curClr) # set colour | |
91 | data.SetInitialFont(self.curFont) | |
cf694132 | 92 | |
8fa876ca RD |
93 | dlg = wx.FontDialog(self, data) |
94 | ||
95 | if dlg.ShowModal() == wx.ID_OK: | |
1e4a197e RD |
96 | data = dlg.GetFontData() |
97 | font = data.GetChosenFont() | |
98 | colour = data.GetColour() | |
8fa876ca | 99 | |
1e4a197e RD |
100 | self.log.WriteText('You selected: "%s", %d points, color %s\n' % |
101 | (font.GetFaceName(), font.GetPointSize(), | |
102 | colour.Get())) | |
8fa876ca | 103 | |
1e4a197e RD |
104 | self.curFont = font |
105 | self.curClr = colour | |
106 | self.UpdateUI() | |
1e4a197e | 107 | |
8fa876ca RD |
108 | # Don't destroy the dialog until you get everything you need from the |
109 | # dialog! | |
110 | dlg.Destroy() | |
1e4a197e RD |
111 | |
112 | ||
113 | #--------------------------------------------------------------------------- | |
114 | ||
115 | def runTest(frame, nb, log): | |
116 | win = TestPanel(nb, log) | |
117 | return win | |
118 | ||
1e4a197e RD |
119 | #--------------------------------------------------------------------------- |
120 | ||
121 | ||
1e4a197e | 122 | overview = """\ |
8fa876ca RD |
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. | |
cf694132 | 127 | |
8fa876ca RD |
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. | |
1e4a197e | 133 | |
8fa876ca RD |
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. | |
1e4a197e | 137 | |
8fa876ca | 138 | """ |
1e4a197e RD |
139 | |
140 | if __name__ == '__main__': | |
141 | import sys,os | |
142 | import run | |
143 | run.main(['', os.path.basename(sys.argv[0])]) | |
144 |