/[escript]/trunk/pyvisi/py_src/text.py
ViewVC logotype

Contents of /trunk/pyvisi/py_src/text.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1189 - (show annotations)
Thu Jun 7 05:31:25 2007 UTC (13 years, 10 months ago) by jongui
File MIME type: text/x-python
File size: 2401 byte(s)
A Scalar Bar can now be displayed by creating an instance of a 'Legend'. The Scalar Bar can either show the scalar data range or vector data range. Corresponding examples and tests have also been added.
1 """
2 @author: John NGUI
3 """
4
5 import vtk
6 from actor import Actor2D
7 from constant import Viewport, Color
8
9 # NOTE: Actor2D was inherited to allow access to its public methods from
10 # the driver.
11 class Text2D(Actor2D):
12 """
13 Class that defines a 2D text actor. A two-dimensional text is used to
14 annotate the rendered object (i.e. inserting titles, authors and labels).
15 """
16
17 def __init__(self, scene, text, viewport = Viewport.SOUTH_WEST):
18 """
19 Initialise the 2D text actor.
20
21 @type scene: L{Scene <scene.Scene>} object
22 @param scene: Scene in which objects are to be rendered on
23 @type text: String
24 @param text: 2D text to be displayed
25 @type viewport: L{Viewport <constant.Viewport>} constant
26 @param viewport: Viewport in which objects are to be rendered on
27 """
28
29 self.__text = text
30 self.__viewport = viewport
31 self._vtk_actor2D = vtk.vtkTextActor()
32
33 self.__setupText2D(scene)
34
35 def __setupText2D(self, scene):
36 """
37 Setup the 2D text.
38
39 @type scene: L{Scene <scene.Scene>} object
40 @param scene: Scene in which objects are to be rendered on
41 """
42
43 self.__setInput()
44 self.setColor(Color.BLACK)
45 # Add the 2D text to the appropriate renderer.
46 scene._addActor2D(self.__viewport, self._vtk_actor2D)
47
48 def __setInput(self):
49 """
50 Set the input for the 2D text.
51 """
52
53 self._vtk_actor2D.SetInput(self.__text)
54
55 def setFontSize(self, size):
56 """
57 Set the 2D text size.
58
59 @type size: Number
60 @param size: Size of the 2D text
61 """
62
63 self._vtk_actor2D.GetTextProperty().SetFontSize(size)
64
65 def setFontToTimes(self):
66 """
67 Set the 2D text font type to Times New Roman.
68 """
69
70 self._vtk_actor2D.GetTextProperty().SetFontFamilyToTimes()
71
72 def setFontToArial(self):
73 """
74 Set the 2D text font type to Arial.
75 """
76
77 self._vtk_actor2D.GetTextProperty().SetFontFamilyToArial()
78
79 def setFontToCourier(self):
80 """
81 Set the 2D text front type to Courier.
82 """
83
84 self._vtk_actor2D.GetTextProperty().SetFontFamilyToCourier()
85
86 def boldOn(self):
87 """
88 Bold the 2D text.
89 """
90
91 self._vtk_actor2D.GetTextProperty().BoldOn()
92
93 def shadowOn(self):
94 """
95 Apply shadow onto the 2D text to ease visibility.
96 """
97
98 self._vtk_actor2D.GetTextProperty().ShadowOn()
99
100 def setColor(self, color):
101 """
102 Set the color of the 2D text.
103
104 @type color: L{Color <constant.Color>} constant
105 @param color: 2D text color
106 """
107
108 self._vtk_actor2D.GetTextProperty().SetColor(color)
109

  ViewVC Help
Powered by ViewVC 1.1.26