From: Symion <kn...@ip...> - 2011-03-01 09:54:44
|
I have been exploring the Text object a little more and may have found a bug. I may not be using the text object correctly but I receive the following error when changing text color. from visual import * words = text(text="Test") words.color=(1,0,0) Traceback (most recent call last): File "<pyshell#118>", line 1 words.color=(1,0,0) File "C:\Python27\lib\site-packages\vis\primitives.py", line 945, in set_color for line in range(len(self.lines)): AttributeError: 'text' object has no attribute 'lines' The same error occurs with. words.starts.__class__ |
From: Bruce S. <Bru...@nc...> - 2011-03-01 17:45:13
|
Thanks much for the report. In vis/primitives.py, the code for changing color and material for a text object should look like this: def set_material(self, material): self.extrusion.material = material def get_material(self): return self.__material def set_color(self, color): self.extrusion.color = color def get_color(self): return self.__color These corrections will of course be in the next update to VPython. I also found a mistake in text.starts, but that's less used. History: The year-old 3D text object had a component to convert text to contours, and Python code to generate faces objects to render the 3D text. With the new extrusion object also needing to be able to convert text to contours, that subroutine was split out as shapes.text() and the text and extrusion objects both call shapes.text(). In the process of doing this restructuring I failed to change the setters for text.color and text.material. Note that the text object creates an extrusion object, but this doesn't make the text object obsolete, because it places emphasis on such things as upper left and lower right locations, etc. Bruce Sherwood On Tue, Mar 1, 2011 at 2:54 AM, Symion <kn...@ip...> wrote: > I have been exploring the Text object a little more and may have found a > bug. > I may not be using the text object correctly but I receive the following > error when changing text color. > > from visual import * > words = text(text="Test") > words.color=(1,0,0) > > Traceback (most recent call last): > File "<pyshell#118>", line 1 > words.color=(1,0,0) > File "C:\Python27\lib\site-packages\vis\primitives.py", line 945, in > set_color > for line in range(len(self.lines)): > AttributeError: 'text' object has no attribute 'lines' > > The same error occurs with. > > words.starts.__class__ > > > ------------------------------------------------------------------------------ > Free Software Download: Index, Search & Analyze Logs and other IT data in > Real-Time with Splunk. Collect, index and harness all the fast moving IT data > generated by your applications, servers and devices whether physical, virtual > or in the cloud. Deliver compliance at lower cost and gain new business > insights. http://p.sf.net/sfu/splunk-dev2dev > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > |
From: Guy K. K. <guy...@au...> - 2011-03-02 06:35:01
|
On Wed, 02 Mar 2011 06:45:04 Bruce Sherwood wrote: > In vis/primitives.py, the code for > changing color and material for a text object should look like this: > > def set_material(self, material): > self.extrusion.material = material > def get_material(self): > return self.__material > > def set_color(self, color): > self.extrusion.color = color > def get_color(self): > return self.__color Are you *really* sure about that? Python usually does not use the concept of getters and setters. This turns out to be *very* unpythonic. I'd rather suggest the following: @material.setter def material(self, material): self.extrusion.material = material @property def material(self): return self.__material @color.setter def set_color(self, color): self.extrusion.color = color @property def get_color(self): return self.__color This exposes the given methods to transparently handle access (setting and getting) to mock attributes as they would be normally used within Python classes. It makes a nice API that is idiomatically consistent to use for a Pythoneer. For further reference on how to use the property() built-in, particularly in the way of decorators, have a look here: http://docs.python.org/library/functions.html#property Guy -- Guy K. Kloss School of Computing + Mathematical Sciences Auckland University of Technology Private Bag 92006, Auckland 1142 phone: +64 9 921 9999 ext. 5032 eMail: Guy...@au... |
From: Bruce S. <Bru...@nc...> - 2011-03-03 05:17:09
|
I haven't used decorators myself, and because Visual was initiated in 2000, there aren't any decorators anywhere in the Python portions of Visual. So I'm tone-deaf to the issue here and don't understand what advantage would accrue either to developers of Visual or users of Visual by replacing the following code (currently found in vis/primitives.py) def set_color(self, color): self.extrusion.color = color def get_color(self): return self.__color color = property( get_color, set_color, None) with @color.setter def set_color(self, color): self.extrusion.color = color @property def get_color(self): return self.__color What am I missing? If I were to change this tiny piece of code to use decorators, for consistency it would seem advisable to change all such code segments, and I have no idea why this is advisable. Calling the older scheme "unpythonic" doesn't help me see the light. Bruce Sherwood On Tue, Mar 1, 2011 at 11:11 PM, Guy K. Kloss <guy...@au...> wrote: > On Wed, 02 Mar 2011 06:45:04 Bruce Sherwood wrote: >> In vis/primitives.py, the code for >> changing color and material for a text object should look like this: >> >> def set_material(self, material): >> self.extrusion.material = material >> def get_material(self): >> return self.__material >> >> def set_color(self, color): >> self.extrusion.color = color >> def get_color(self): >> return self.__color > > Are you *really* sure about that? Python usually does not use the concept of > getters and setters. This turns out to be *very* unpythonic. I'd rather > suggest the following: > > @material.setter > def material(self, material): > self.extrusion.material = material > > @property > def material(self): > return self.__material > > @color.setter > def set_color(self, color): > self.extrusion.color = color > > @property > def get_color(self): > return self.__color > > This exposes the given methods to transparently handle access (setting and > getting) to mock attributes as they would be normally used within Python > classes. It makes a nice API that is idiomatically consistent to use for a > Pythoneer. > > For further reference on how to use the property() built-in, particularly in > the way of decorators, have a look here: > > http://docs.python.org/library/functions.html#property > > Guy > > -- > Guy K. Kloss > School of Computing + Mathematical Sciences > Auckland University of Technology > Private Bag 92006, Auckland 1142 > phone: +64 9 921 9999 ext. 5032 > eMail: Guy...@au... > > ------------------------------------------------------------------------------ > Free Software Download: Index, Search & Analyze Logs and other IT data in > Real-Time with Splunk. Collect, index and harness all the fast moving IT data > generated by your applications, servers and devices whether physical, virtual > or in the cloud. Deliver compliance at lower cost and gain new business > insights. http://p.sf.net/sfu/splunk-dev2dev > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > > |