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