]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/FancyText.py
reSWIGged
[wxWidgets.git] / wxPython / demo / FancyText.py
CommitLineData
8fa876ca
RD
1# 11/5/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o Updated to wx namespace
4#
5# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
6#
7# o Issues previously noted have evaporated.
8# o Hoo boy, the doc string in the lib needs fixed :-)
9#
10# 12/02/2003 - Jeff Grimmett (grimmtooth@softhome.net)
11#
12# o Making the library's doc string acceptable for the overview rendered
13# it unusable in the library's own test code, so I copied it over
14# and massaged the XML into useful HTML.
15#
16
17import wx
18import wx.lib.fancytext as fancytext
1b62f00d
RD
19
20#----------------------------------------------------------------------
21
22test_str = ('<font style="italic" family="swiss" color="red" weight="bold" >'
23 'some |<sup>23</sup> <angle/>text<sub>with <angle/> subscript</sub>'
24 '</font> some other text')
25
26test_str2 = '<font family="swiss" color="dark green" size="40">big green text</font>'
27
28
8fa876ca 29class TestPanel(wx.Panel):
1b62f00d 30 def __init__(self, parent):
8fa876ca
RD
31 wx.Panel.__init__(self, parent, -1)
32 self.Bind(wx.EVT_PAINT, self.OnPaint)
1b62f00d
RD
33
34 def OnPaint(self, evt):
8fa876ca 35 dc = wx.PaintDC(self)
1b62f00d 36
d14a1e28
RD
37 w, h = fancytext.GetExtent(test_str, dc)
38 fancytext.RenderToDC(test_str, dc, 20, 20)
1b62f00d 39
d14a1e28 40 fancytext.RenderToDC(test_str2, dc, 20, 20 + h + 10)
1b62f00d
RD
41
42
43#----------------------------------------------------------------------
44
45def runTest(frame, nb, log):
46 win = TestPanel(nb)
47 return win
48
49#----------------------------------------------------------------------
50
51
52
8fa876ca
RD
53overview = \
54"""
55<html>
56<body>
57<h1>FancyText -- <i>methods for rendering XML specified text</i></h1>
58
59<p>This module exports four main methods::
60<pre>
61 def GetExtent(str, dc=None, enclose=True)
62 def GetFullExtent(str, dc=None, enclose=True)
63 def RenderToBitmap(str, background=None, enclose=True)
64 def RenderToDC(str, dc, x, y, enclose=True)
65</pre>
66
67In all cases, 'str' is an XML string. Note that start and end tags
68are only required if *enclose* is set to False. In this case the
69text should be wrapped in FancyText tags.
70
71<p>In addition, the module exports one class::
72<pre>
73 class StaticFancyText(self, window, id, text, background, ...)
74</pre>
75This class works similar to StaticText except it interprets its text
76as FancyText.
77
78<p>The text can support<sup>superscripts</sup> and <sub>subscripts</sub>, text
79in different <font size="+3">sizes</font>, <font color="blue">colors</font>,
80<i>styles</i>, <b>weights</b> and
81<font family="script">families</font>. It also supports a limited set of symbols,
82currently <times/>, <infinity/>, <angle/> as well as greek letters in both
83upper case (<Alpha/><Beta/>...<Omega/>) and lower case (<alpha/><beta/>...<omega/>).
84
85</font></font>
86The End
87</body>
88</html>
89"""
1fded56b
RD
90
91
92
93if __name__ == '__main__':
94 import sys,os
95 import run
96 run.main(['', os.path.basename(sys.argv[0])])
97