From 4ee298e94234da431933c42cc765edc4de55b6ea Mon Sep 17 00:00:00 2001 From: David Rose Date: Sat, 11 Jul 2009 01:16:33 +0000 Subject: [PATCH] some minor problems --- direct/src/plugin/p3dObject.cxx | 11 ++++++ direct/src/plugin/p3dObject.h | 2 + direct/src/plugin/p3dPythonObject.cxx | 23 ++++++++++++ direct/src/plugin/p3dPythonObject.h | 4 ++ direct/src/plugin/p3dSession.cxx | 4 +- direct/src/showutil/runp3d.py | 54 +++++++++++++++------------ 6 files changed, 74 insertions(+), 24 deletions(-) diff --git a/direct/src/plugin/p3dObject.cxx b/direct/src/plugin/p3dObject.cxx index 07ab878f92..55fc415e01 100644 --- a/direct/src/plugin/p3dObject.cxx +++ b/direct/src/plugin/p3dObject.cxx @@ -199,6 +199,17 @@ P3DObject:: 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 // Access: Public, Virtual diff --git a/direct/src/plugin/p3dObject.h b/direct/src/plugin/p3dObject.h index 3977012a56..0bf2ef0314 100644 --- a/direct/src/plugin/p3dObject.h +++ b/direct/src/plugin/p3dObject.h @@ -33,6 +33,8 @@ protected: public: virtual ~P3DObject(); + virtual bool is_python_object(); + virtual P3D_object_type get_type()=0; virtual bool get_bool()=0; virtual int get_int(); diff --git a/direct/src/plugin/p3dPythonObject.cxx b/direct/src/plugin/p3dPythonObject.cxx index 7d3b641fa1..8917cbba23 100644 --- a/direct/src/plugin/p3dPythonObject.cxx +++ b/direct/src/plugin/p3dPythonObject.cxx @@ -43,6 +43,17 @@ P3DPythonObject:: 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 // 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 // Access: Public diff --git a/direct/src/plugin/p3dPythonObject.h b/direct/src/plugin/p3dPythonObject.h index 186b89d29c..0c5fc358bb 100644 --- a/direct/src/plugin/p3dPythonObject.h +++ b/direct/src/plugin/p3dPythonObject.h @@ -33,6 +33,8 @@ public: P3DPythonObject(P3DSession *session, int object_id); virtual ~P3DPythonObject(); + virtual bool is_python_object(); + public: virtual P3D_object_type get_type(); virtual bool get_bool(); @@ -49,6 +51,8 @@ public: P3D_object *params[], int num_params); virtual void output(ostream &out); + + P3DSession *get_session(); int get_object_id(); private: diff --git a/direct/src/plugin/p3dSession.cxx b/direct/src/plugin/p3dSession.cxx index 72a447e303..42ed8e7885 100644 --- a/direct/src/plugin/p3dSession.cxx +++ b/direct/src/plugin/p3dSession.cxx @@ -458,7 +458,9 @@ p3dobj_to_xml(P3D_object *obj) { break; 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 // P3DPythonObject. In this case, just send the object_id down, // since the actual implementation of this object exists (as a diff --git a/direct/src/showutil/runp3d.py b/direct/src/showutil/runp3d.py index 1d797c4fc1..1c24ae1a96 100755 --- a/direct/src/showutil/runp3d.py +++ b/direct/src/showutil/runp3d.py @@ -473,31 +473,39 @@ class BrowserObject: return True def __call__(self, *args): - parentObj, attribName = self.__boundMethod - if parentObj: - # Call it as a method. - needsResponse = True - if parentObj is self.__runner.dom and attribName == 'alert': - # As a special hack, we don't wait for the return - # value from the alert() call, since this is a - # blocking call, and waiting for this could cause - # problems. - needsResponse = False - - if parentObj is self.__runner.dom and attribName == 'eval' and len(args) == 1 and isinstance(args[0], types.StringTypes): - # As another special hack, we make dom.eval() a - # special case, and map it directly into an eval() - # call. If the string begins with 'void ', we further - # assume we're not waiting for a response. - if args[0].startswith('void '): + try: + parentObj, attribName = self.__boundMethod + if parentObj: + # Call it as a method. + needsResponse = True + if parentObj is self.__runner.dom and attribName == 'alert': + # As a special hack, we don't wait for the return + # value from the alert() call, since this is a + # blocking call, and waiting for this could cause + # problems. needsResponse = False - result = self.__runner.scriptRequest('eval', parentObj, value = args[0], needsResponse = needsResponse) + + if parentObj is self.__runner.dom and attribName == 'eval' and len(args) == 1 and isinstance(args[0], types.StringTypes): + # As another special hack, we make dom.eval() a + # special case, and map it directly into an eval() + # call. If the string begins with 'void ', we further + # assume we're not waiting for a response. + if args[0].startswith('void '): + needsResponse = False + result = self.__runner.scriptRequest('eval', parentObj, value = args[0], needsResponse = needsResponse) + else: + # This is a normal method call. + try: + 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: - # This is a normal method call. - result = self.__runner.scriptRequest('call', parentObj, propertyName = attribName, value = args, needsResponse = needsResponse) - else: - # Call it as a plain function. - result = self.__runner.scriptRequest('call', self, value = args) + # Call it as a plain function. + result = self.__runner.scriptRequest('call', self, value = args) + except EnvironmentError: + # Some odd problem on the call. + raise TypeError return result