1 # Blender.Text module and the Text PyType object
4 The Blender.Text submodule.
9 This module provides access to B{Text} objects in Blender.
13 from Blender import Text
15 txt = Text.New("MyText") # create a new Text object
16 print Text.Get() # current list of Texts in Blender
17 txt.write("Appending some ") # appending text
18 txt.write("text to my\\n") # '\\n' inserts new-line markers
19 txt.write("text buffer.")
20 print txt.asLines() # retrieving the buffer as a list of lines
21 Text.unlink(txt) # removing a Text object
24 def New (name = None, follow_cursor = 0):
26 Create a new Text object.
28 @param name: The Text name.
29 @type follow_cursor: int
30 @param follow_cursor: The text follow flag: if 1, the text display always
33 @return: The created Text Data object.
36 def Get (name = None):
38 Get the Text object(s) from Blender.
40 @param name: The name of the Text object.
41 @rtype: Blender Text or a list of Blender Texts
42 @return: It depends on the 'name' parameter:
43 - (name): The Text object with the given name;
44 - (): A list with all Text objects in the current scene.
49 Load a file into a Blender Text object.
50 @type filename: string
51 @param filename: The name of the file to load.
53 @return: A Text object with the contents of the loaded file.
58 Unlink (remove) the given Text object from Blender.
59 @type textobj: Blender Text
60 @param textobj: The Text object to be deleted.
67 This object gives access to Texts in Blender.
68 @ivar filename: The filename of the file loaded into this Text.
69 @ivar mode: The follow_mode flag: if 1 it is 'on'; if 0, 'off'.
70 @ivar nlines: The number of lines in this Text.
75 Get the name of this Text object.
81 Set the name of this Text object.
83 @param name: The new name.
88 Get the filename of the file loaded into this Text object.
94 Get the number of lines in this Text buffer.
100 Clear this Text object: its buffer becomes empty.
105 Reset the read IO pointer to the start of the buffer.
110 Reads a line of text from the buffer from the current IO pointer
111 position to the end of the line.
115 def set(attribute, value):
117 Set this Text's attributes.
118 @type attribute: string
119 @param attribute: The attribute to change:
120 currently, 'follow_cursor' is the only one available. It can be
121 turned 'on' with value = 1 and 'off' with value = 0.
123 @param value: The new attribute value.
128 Append a string to this Text buffer.
130 @param data: The string to append to the text buffer.
135 Inserts a string into this Text buffer at the cursor.
137 @param data: The string to insert into the text buffer.
142 Retrieve the contents of this Text buffer as a list of strings.
143 @rtype: list of strings
144 @return: A list of strings, one for each line in the buffer
149 Retrieve the position of the cursor in this Text buffer.
151 @return: A pair (row, col) indexing the line and character of the
155 def setCursorPos(row, col):
157 Set the position of the cursor in this Text buffer.
159 @param row: The index of the line in which to position the cursor.
161 @param col: The index of the character within the line to position the
165 def suggest(list, prefix=''):
167 Suggest a list of names. If list is a list of tuples (name, type) the
168 list will be formatted to syntax-highlight each entry type. Types must
169 be strings in the list ['m', 'f', 'v', 'k', '?']. It is recommended that
170 the list be sorted, case-insensitively by name.
172 @type list: list of tuples or strings
173 @param list: List of pair-tuples of the form (name, type) where name is
174 the suggested name and type is one of 'm' (module or class), 'f'
175 (function or method), 'v' (variable), 'k' (keyword), '?' (other).
176 Lists of plain strings are also accepted where the type is always
179 @param prefix: The optional prefix used to limit what is suggested from
180 the list. This is usually whatever precedes the cursor so that
181 backspace will update it.
186 Displays a word-wrapped message box containing the specified
187 documentation when this Text object is visible.
189 @param docs: The documentation string to display.
193 Text.__doc__ += id_generics.attributes