some minor problems

This commit is contained in:
David Rose 2009-07-11 01:16:33 +00:00
parent 8966fe7dbf
commit 4ee298e942
6 changed files with 74 additions and 24 deletions

View File

@ -199,6 +199,17 @@ P3DObject::
assert(_ref_count == 0); assert(_ref_count == 0);
} }
////////////////////////////////////////////////////////////////////
// Function: P3DObject::is_python_object
// Access: Public, Virtual
// Description: Returns true if this is actually an instance of a
// P3DPythonObject, false otherwise.
////////////////////////////////////////////////////////////////////
bool P3DObject::
is_python_object() {
return false;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: P3DObject::get_int // Function: P3DObject::get_int
// Access: Public, Virtual // Access: Public, Virtual

View File

@ -33,6 +33,8 @@ protected:
public: public:
virtual ~P3DObject(); virtual ~P3DObject();
virtual bool is_python_object();
virtual P3D_object_type get_type()=0; virtual P3D_object_type get_type()=0;
virtual bool get_bool()=0; virtual bool get_bool()=0;
virtual int get_int(); virtual int get_int();

View File

@ -43,6 +43,17 @@ P3DPythonObject::
unref_delete(_session); unref_delete(_session);
} }
////////////////////////////////////////////////////////////////////
// Function: P3DPythonObject::is_python_object
// Access: Public, Virtual
// Description: Returns true if this is actually an instance of a
// P3DPythonObject, false otherwise.
////////////////////////////////////////////////////////////////////
bool P3DPythonObject::
is_python_object() {
return true;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: P3DPythonObject::get_type // Function: P3DPythonObject::get_type
// Access: Public, Virtual // Access: Public, Virtual
@ -271,6 +282,18 @@ output(ostream &out) {
} }
} }
////////////////////////////////////////////////////////////////////
// Function: P3DPythonObject::get_session
// Access: Public
// Description: Returns the session that this object is identified
// with.
////////////////////////////////////////////////////////////////////
P3DSession *P3DPythonObject::
get_session() {
return _session;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: P3DPythonObject::get_object_id // Function: P3DPythonObject::get_object_id
// Access: Public // Access: Public

View File

@ -33,6 +33,8 @@ public:
P3DPythonObject(P3DSession *session, int object_id); P3DPythonObject(P3DSession *session, int object_id);
virtual ~P3DPythonObject(); virtual ~P3DPythonObject();
virtual bool is_python_object();
public: public:
virtual P3D_object_type get_type(); virtual P3D_object_type get_type();
virtual bool get_bool(); virtual bool get_bool();
@ -49,6 +51,8 @@ public:
P3D_object *params[], int num_params); P3D_object *params[], int num_params);
virtual void output(ostream &out); virtual void output(ostream &out);
P3DSession *get_session();
int get_object_id(); int get_object_id();
private: private:

View File

@ -458,7 +458,9 @@ p3dobj_to_xml(P3D_object *obj) {
break; break;
case P3D_OT_object: case P3D_OT_object:
if (obj->_class == &P3DObject::_object_class) { if (obj->_class == &P3DObject::_object_class &&
((P3DObject *)obj)->is_python_object() &&
((P3DPythonObject *)obj)->get_session() == this) {
// If it's one of our kind of objects, it must be a // If it's one of our kind of objects, it must be a
// P3DPythonObject. In this case, just send the object_id down, // P3DPythonObject. In this case, just send the object_id down,
// since the actual implementation of this object exists (as a // since the actual implementation of this object exists (as a

View File

@ -473,6 +473,7 @@ class BrowserObject:
return True return True
def __call__(self, *args): def __call__(self, *args):
try:
parentObj, attribName = self.__boundMethod parentObj, attribName = self.__boundMethod
if parentObj: if parentObj:
# Call it as a method. # Call it as a method.
@ -494,10 +495,17 @@ class BrowserObject:
result = self.__runner.scriptRequest('eval', parentObj, value = args[0], needsResponse = needsResponse) result = self.__runner.scriptRequest('eval', parentObj, value = args[0], needsResponse = needsResponse)
else: else:
# This is a normal method call. # This is a normal method call.
try:
result = self.__runner.scriptRequest('call', parentObj, propertyName = attribName, value = args, needsResponse = needsResponse) result = self.__runner.scriptRequest('call', parentObj, propertyName = attribName, value = args, needsResponse = needsResponse)
except EnvironmentError:
# Problem on the call. Maybe no such method?
raise AttributeError
else: else:
# Call it as a plain function. # Call it as a plain function.
result = self.__runner.scriptRequest('call', self, value = args) result = self.__runner.scriptRequest('call', self, value = args)
except EnvironmentError:
# Some odd problem on the call.
raise TypeError
return result return result