[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28819] trunk/blender/release/scripts/ modules/bpy_types.py: text utility functions.
Campbell Barton
ideasman42 at gmail.com
Tue May 18 17:24:10 CEST 2010
Id rather have all RNA objects act the same and have a predictable str(obj)
Without meaning to you could end up spewing pages of text into the console.
for text in bpy.data.texts:
print("%s blah blah" % text)
a text in blender is more similar to a file then a string so I'd
rather have python implement functions over Text which make it act
like a file object.
text.read()/seek()/tell()/readlines()/write() etc..
This way you could do
sys.stdout = bpy.data.texts["output"]
This should remove the need for as_string/from_string but also needs
more time to check functions work as expected.
On Tue, May 18, 2010 at 5:00 PM, Dalai Felinto <dfelinto at gmail.com> wrote:
> quick question:
> instead of text.as_string() would be better to define the __str__ for
> this class?
> so str(text) could be used?
>
> 2010/5/18 Campbell Barton <ideasman42 at gmail.com>:
>> Revision: 28819
>> http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28819
>> Author: campbellbarton
>> Date: 2010-05-18 11:07:58 +0200 (Tue, 18 May 2010)
>>
>> Log Message:
>> -----------
>> text utility functions.
>> - st = text.as_string()
>> - text.from_string(st)
>>
>> Modified Paths:
>> --------------
>> trunk/blender/release/scripts/modules/bpy_types.py
>>
>> Modified: trunk/blender/release/scripts/modules/bpy_types.py
>> ===================================================================
>> --- trunk/blender/release/scripts/modules/bpy_types.py 2010-05-18 08:10:05 UTC (rev 28818)
>> +++ trunk/blender/release/scripts/modules/bpy_types.py 2010-05-18 09:07:58 UTC (rev 28819)
>> @@ -410,6 +410,19 @@
>> return ord_ind(verts[0], verts[1]), ord_ind(verts[1], verts[2]), ord_ind(verts[2], verts[3]), ord_ind(verts[3], verts[0])
>>
>>
>> +class Text(bpy_types.ID):
>> + __slots__ = ()
>> +
>> + def as_string(self):
>> + """Return the text as a string."""
>> + return "\n".join(line.line for line in self.lines)
>> +
>> + def from_string(self, string):
>> + """Replace text with this string."""
>> + self.clear()
>> + self.write(string)
>> +
>> +
>> import collections
>>
>>
>>
>>
>> _______________________________________________
>> Bf-blender-cvs mailing list
>> Bf-blender-cvs at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-blender-cvs
>>
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers
>
--
- Campbell
More information about the Bf-committers
mailing list