]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/FancyText.py
Tool tweaks and metadata update
[wxWidgets.git] / wxPython / demo / FancyText.py
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
17 import wx
18 import wx.lib.fancytext as fancytext
19
20 #----------------------------------------------------------------------
21
22 test_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
26 test_str2 = '<font family="swiss" color="dark green" size="40">big green text</font>'
27
28
29 class TestPanel(wx.Panel):
30 def __init__(self, parent):
31 wx.Panel.__init__(self, parent, -1)
32 self.Bind(wx.EVT_PAINT, self.OnPaint)
33
34 def OnPaint(self, evt):
35 dc = wx.PaintDC(self)
36
37 w, h = fancytext.GetExtent(test_str, dc)
38 fancytext.RenderToDC(test_str, dc, 20, 20)
39
40 fancytext.RenderToDC(test_str2, dc, 20, 20 + h + 10)
41
42
43 #----------------------------------------------------------------------
44
45 def runTest(frame, nb, log):
46 win = TestPanel(nb)
47 return win
48
49 #----------------------------------------------------------------------
50
51
52
53 overview = \
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
67 In all cases, 'str' is an XML string. Note that start and end tags
68 are only required if *enclose* is set to False. In this case the
69 text 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>
75 This class works similar to StaticText except it interprets its text
76 as FancyText.
77
78 <p>The text can support<sup>superscripts</sup> and <sub>subscripts</sub>, text
79 in 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,
82 currently <times/>, <infinity/>, <angle/> as well as greek letters in both
83 upper case (<Alpha/><Beta/>...<Omega/>) and lower case (<alpha/><beta/>...<omega/>).
84
85 </font></font>
86 The End
87 </body>
88 </html>
89 """
90
91
92
93 if __name__ == '__main__':
94 import sys,os
95 import run
96 run.main(['', os.path.basename(sys.argv[0])])
97