1 |
""" |
2 |
@author: John NGUI |
3 |
""" |
4 |
|
5 |
import vtk |
6 |
from actor import Actor2D |
7 |
from constant import Viewport, Color |
8 |
|
9 |
class Text2D(Actor2D): |
10 |
""" |
11 |
Class that defines a 2D text actor. |
12 |
""" |
13 |
|
14 |
def __init__(self, scene, text, viewport = Viewport.SOUTH_WEST): |
15 |
""" |
16 |
Initialise the 2D text actor. |
17 |
|
18 |
@type text: String |
19 |
@param text: 2D text to be displayed |
20 |
""" |
21 |
|
22 |
self.__scene = scene |
23 |
self.__text = text |
24 |
self.__viewport = viewport |
25 |
self._vtk_actor2D = vtk.vtkTextActor() |
26 |
|
27 |
self.__setupText2D() |
28 |
|
29 |
def __setupText2D(self): |
30 |
""" |
31 |
Setup the 2D text. |
32 |
""" |
33 |
|
34 |
self.__setInput() |
35 |
# Add the 2D text to the appropriate renderer. |
36 |
self.__scene._addActor2D(self.__viewport, self._vtk_actor2D) |
37 |
|
38 |
def __setInput(self): |
39 |
""" |
40 |
Set the 2D text to be displayed. |
41 |
""" |
42 |
|
43 |
self._vtk_actor2D.SetInput(self.__text) |
44 |
|
45 |
def setFontSize(self, size): |
46 |
""" |
47 |
Set the 2D text size. |
48 |
|
49 |
@type size: Number |
50 |
@param size: Size of the 2D text |
51 |
""" |
52 |
|
53 |
self._vtk_actor2D.GetTextProperty().SetFontSize(size) |
54 |
|
55 |
def setFontToTimes(self): |
56 |
""" |
57 |
Set the 2D text font type to times new roman. |
58 |
""" |
59 |
|
60 |
self._vtk_actor2D.GetTextProperty().SetFontFamilyToTimes() |
61 |
|
62 |
def setFontToArial(self): |
63 |
""" |
64 |
Set the 2D text font type to arial. |
65 |
""" |
66 |
|
67 |
self._vtk_actor2D.GetTextProperty().SetFontFamilyToArial() |
68 |
|
69 |
def setFontToCourier(self): |
70 |
""" |
71 |
Set the 2D text front type to courier. |
72 |
""" |
73 |
|
74 |
self._vtk_actor2D.GetTextProperty().SetFontFamilyToCourier() |
75 |
|
76 |
def setJustificationToCenter(self): |
77 |
""" |
78 |
Set the 2D text to center justification. |
79 |
""" |
80 |
|
81 |
self._vtk_actor2D.GetTextProperty().SetJustificationToCentered() |
82 |
|
83 |
def setJustificationToLeft(self): |
84 |
""" |
85 |
Set the 2D text to left justification. |
86 |
""" |
87 |
|
88 |
self._vtk_actor2D.GetTextProperty().SetJustificationToLeft() |
89 |
|
90 |
def setJustificationToRight(self): |
91 |
""" |
92 |
Set the 2D text to right justification. |
93 |
""" |
94 |
|
95 |
self._vtk_actor2D.GetTextProperty().SetJustificationToRight() |
96 |
|
97 |
def boldOn(self): |
98 |
""" |
99 |
Bold the 2D text. |
100 |
""" |
101 |
|
102 |
self._vtk_actor2D.GetTextProperty().BoldOn() |
103 |
|
104 |
def shadowOn(self): |
105 |
""" |
106 |
Apply shadow onto the 2D text to ease visibility. |
107 |
""" |
108 |
|
109 |
self._vtk_actor2D.GetTextProperty().ShadowOn() |
110 |
|
111 |
def setColor(self, color): |
112 |
""" |
113 |
Set the color of the text. |
114 |
|
115 |
@type color: L{Color <constant.Color>} constant |
116 |
@param color: 2D text color |
117 |
""" |
118 |
|
119 |
self._vtk_actor2D.GetTextProperty().SetColor(color) |
120 |
|