To add that attribute, everything should be done in pvector.cpp, and maybe a
little in pvector.h.
You will need to change Vector::init_type, Vector::get_attr, possibly
Vector::set_attr to report that you cannot assign to that attribute, and
possibly a member function to construct the right return to python.
Note that the return to python should be wrapped around FromAPI() aka
asObject () (see CXX/Include/CXX_Objects.h for some documentation).
I don't know if there is more to it than simply printing or returning a
string, you will have to look at other stuff to figure out the solid way to
get the job done.
Don't worry about immutableVector. It is used internally to have the effect
of a 'const Vector'. All it's properties and methods are obtained through
public inheritance of Vector, and an override of set_attr that always
reports that you cannot change the attributes. Thanks to polymorphism, from
python, they look just like a const Vector.
Good luck,
Jonathan
P.S. Please don't CC me directly, I read the list.
----- Original Message -----
From: <ajsiegel at optonline dot net>
Sent: Tuesday, March 18, 2003 12:23 PM
Subject: [Visualpython-users] small "feature" request
> The fact that the VPython vector object has no __class__ attribute seems
inconsistent with the current status of Python objects.Happens that it is
creating a practical problem in something I am attempting.
>
> The issue is illustrated as follows:
>
> >>> from visual import *
> Visual-2003-03-15
> >>> lis = [1,2,3]
> >>> tup =(1,2,3)
> >>> vec = vector(1,2,3)
> >>> lis.__class__
> <type 'list'>
> >>> tup.__class__
> <type 'tuple'>
> >>> vec.__class__
> Traceback (most recent call last):
> File "<pyshell#6>", line 1, in ?
> vec.__class__
> AttributeError: __class__
>
> If I am not mistaken, the __class__ attributte of lists and tuples did not
exist at the time VPython was originally written. So at that time, it was
consistent. The change I have in mind would, I think, bring the vector obje
ct more in line with the type/class unification scheme to which Python has
moved.
>
> I have not - at this point - looked at the VPython code in this regard.
But assume it is a minor patch.
>
> My problem is, assuming that I can do the patch myself, I need to know
that what I am doing using it will ultimately work with the official
distributiion.
|