1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
import wx
|
1999-04-30 03:29:54 +00:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
class TestPanel(wx.Panel):
|
2003-03-25 06:35:27 +00:00
|
|
|
def __init__(self, parent, log):
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
2003-03-25 06:35:27 +00:00
|
|
|
self.log = log
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
btn = wx.Button(self, -1, "Select Font")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnSelectFont, btn)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
self.sampleText = wx.TextCtrl(self, -1, "Sample Text")
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-03-25 06:35:27 +00:00
|
|
|
self.curFont = self.sampleText.GetFont()
|
2003-12-09 01:23:28 +00:00
|
|
|
self.curClr = wx.BLACK
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
fgs = wx.FlexGridSizer(cols=2, vgap=5, hgap=5)
|
2003-03-25 06:35:27 +00:00
|
|
|
fgs.AddGrowableCol(1)
|
|
|
|
fgs.AddGrowableRow(0)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-03-25 06:35:27 +00:00
|
|
|
fgs.Add(btn)
|
2003-12-09 01:23:28 +00:00
|
|
|
fgs.Add(self.sampleText, 0, wx.ADJUST_MINSIZE|wx.GROW)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-11-21 07:36:53 +00:00
|
|
|
fgs.Add((15,15)); fgs.Add((15,15)) # an empty row
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
fgs.Add(wx.StaticText(self, -1, "PointSize:"))
|
|
|
|
self.ps = wx.StaticText(self, -1, "")
|
2003-03-25 06:35:27 +00:00
|
|
|
font = self.ps.GetFont()
|
2003-12-09 01:23:28 +00:00
|
|
|
font.SetWeight(wx.BOLD)
|
2003-03-25 06:35:27 +00:00
|
|
|
self.ps.SetFont(font)
|
2003-12-09 01:23:28 +00:00
|
|
|
fgs.Add(self.ps, 0, wx.ADJUST_MINSIZE)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
fgs.Add(wx.StaticText(self, -1, "Family:"))
|
|
|
|
self.family = wx.StaticText(self, -1, "")
|
2003-03-25 06:35:27 +00:00
|
|
|
self.family.SetFont(font)
|
2003-12-09 01:23:28 +00:00
|
|
|
fgs.Add(self.family, 0, wx.ADJUST_MINSIZE)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
fgs.Add(wx.StaticText(self, -1, "Style:"))
|
|
|
|
self.style = wx.StaticText(self, -1, "")
|
2003-03-25 06:35:27 +00:00
|
|
|
self.style.SetFont(font)
|
2003-12-09 01:23:28 +00:00
|
|
|
fgs.Add(self.style, 0, wx.ADJUST_MINSIZE)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
fgs.Add(wx.StaticText(self, -1, "Weight:"))
|
|
|
|
self.weight = wx.StaticText(self, -1, "")
|
2003-03-25 06:35:27 +00:00
|
|
|
self.weight.SetFont(font)
|
2003-12-09 01:23:28 +00:00
|
|
|
fgs.Add(self.weight, 0, wx.ADJUST_MINSIZE)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
fgs.Add(wx.StaticText(self, -1, "Face:"))
|
|
|
|
self.face = wx.StaticText(self, -1, "")
|
2003-03-25 06:35:27 +00:00
|
|
|
self.face.SetFont(font)
|
2003-12-09 01:23:28 +00:00
|
|
|
fgs.Add(self.face, 0, wx.ADJUST_MINSIZE)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-11-21 07:36:53 +00:00
|
|
|
fgs.Add((15,15)); fgs.Add((15,15)) # an empty row
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
fgs.Add(wx.StaticText(self, -1, "wx.NativeFontInfo:"))
|
|
|
|
self.nfi = wx.StaticText(self, -1, "")
|
2003-03-25 06:35:27 +00:00
|
|
|
self.nfi.SetFont(font)
|
2003-12-09 01:23:28 +00:00
|
|
|
fgs.Add(self.nfi, 0, wx.ADJUST_MINSIZE)
|
2003-03-25 06:35:27 +00:00
|
|
|
|
|
|
|
# give it some border space
|
2003-12-09 01:23:28 +00:00
|
|
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
sizer.Add(fgs, 0, wx.GROW|wx.ADJUST_MINSIZE|wx.ALL, 25)
|
2003-03-25 06:35:27 +00:00
|
|
|
|
|
|
|
self.SetSizer(sizer)
|
|
|
|
self.UpdateUI()
|
|
|
|
|
|
|
|
|
|
|
|
def UpdateUI(self):
|
|
|
|
self.sampleText.SetFont(self.curFont)
|
|
|
|
self.ps.SetLabel(str(self.curFont.GetPointSize()))
|
|
|
|
self.family.SetLabel(self.curFont.GetFamilyString())
|
|
|
|
self.style.SetLabel(self.curFont.GetStyleString())
|
|
|
|
self.weight.SetLabel(self.curFont.GetWeightString())
|
|
|
|
self.face.SetLabel(self.curFont.GetFaceName())
|
|
|
|
self.nfi.SetLabel(self.curFont.GetNativeFontInfo().ToString())
|
|
|
|
self.Layout()
|
1999-04-30 03:29:54 +00:00
|
|
|
|
|
|
|
|
2003-03-25 06:35:27 +00:00
|
|
|
def OnSelectFont(self, evt):
|
2003-12-09 01:23:28 +00:00
|
|
|
data = wx.FontData()
|
2003-03-25 06:35:27 +00:00
|
|
|
data.EnableEffects(True)
|
|
|
|
data.SetColour(self.curClr) # set colour
|
|
|
|
data.SetInitialFont(self.curFont)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
dlg = wx.FontDialog(self, data)
|
|
|
|
|
|
|
|
if dlg.ShowModal() == wx.ID_OK:
|
2003-03-25 06:35:27 +00:00
|
|
|
data = dlg.GetFontData()
|
|
|
|
font = data.GetChosenFont()
|
|
|
|
colour = data.GetColour()
|
2003-12-09 01:23:28 +00:00
|
|
|
|
2003-03-25 06:35:27 +00:00
|
|
|
self.log.WriteText('You selected: "%s", %d points, color %s\n' %
|
|
|
|
(font.GetFaceName(), font.GetPointSize(),
|
|
|
|
colour.Get()))
|
2003-12-09 01:23:28 +00:00
|
|
|
|
2003-03-25 06:35:27 +00:00
|
|
|
self.curFont = font
|
|
|
|
self.curClr = colour
|
|
|
|
self.UpdateUI()
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# Don't destroy the dialog until you get everything you need from the
|
|
|
|
# dialog!
|
|
|
|
dlg.Destroy()
|
2003-03-25 06:35:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestPanel(nb, log)
|
|
|
|
return win
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
overview = """\
|
2003-12-09 01:23:28 +00:00
|
|
|
This class allows you to use the system font selection dialog
|
|
|
|
from within your program. Generally speaking, this allows you
|
|
|
|
to select a font by its name, font size, and weight, and
|
|
|
|
on some systems such things as strikethrough and underline.
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
As with other dialogs used in wxPython, it is important to
|
|
|
|
use the class' methods to extract the information you need
|
|
|
|
about the font <b>before</b> you destroy the dialog. Failure
|
|
|
|
to observe this almost always leads to a program failure of
|
|
|
|
some sort, often ugly.
|
2003-03-25 06:35:27 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
This demo serves two purposes; it shows how to use the dialog
|
|
|
|
to GET font information from the user, but also shows how
|
|
|
|
to APPLY that information once you get it.
|
2003-03-25 06:35:27 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
"""
|
2003-03-25 06:35:27 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
2004-03-05 00:06:33 +00:00
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
2003-03-25 06:35:27 +00:00
|
|
|
|