|
|
@@ -83,6 +83,8 @@ P3DInstance(P3D_request_ready_func *func,
|
|
|
|
|
|
// Set some initial properties.
|
|
|
_panda_script_object->set_float_property("downloadProgress", 0.0);
|
|
|
+ _panda_script_object->set_bool_property("downloadComplete", false);
|
|
|
+ _panda_script_object->set_string_property("status", "initial");
|
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
@@ -166,20 +168,8 @@ set_p3d_filename(const string &p3d_filename) {
|
|
|
|
|
|
// Generate a special notification: onpluginload, indicating the
|
|
|
// plugin has read its parameters and is ready to be queried (even
|
|
|
- // if Python has not yet started). This notification is special
|
|
|
- // because it generated at the C++ level, here; most of them are
|
|
|
- // generated by the Python code, once that is running.
|
|
|
- P3D_request *request = new P3D_request;
|
|
|
- request->_request_type = P3D_RT_notify;
|
|
|
- request->_request._notify._message = strdup("onpluginload");
|
|
|
- add_baked_request(request);
|
|
|
-
|
|
|
- // Also eval the HTML associated token.
|
|
|
- string expression = _fparams.lookup_token("onpluginload");
|
|
|
- if (!expression.empty() && _browser_script_object != NULL) {
|
|
|
- P3D_object *result = P3D_OBJECT_EVAL(_browser_script_object, expression.c_str());
|
|
|
- P3D_OBJECT_XDECREF(result);
|
|
|
- }
|
|
|
+ // if Python has not yet started).
|
|
|
+ send_notify("onpluginload");
|
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
@@ -321,6 +311,30 @@ get_request() {
|
|
|
P3D_request *request = _baked_requests.front();
|
|
|
_baked_requests.pop_front();
|
|
|
_request_pending = !_baked_requests.empty();
|
|
|
+
|
|
|
+ if (request != NULL) {
|
|
|
+ if (request->_request_type == P3D_RT_notify) {
|
|
|
+ // Also eval the associated HTML token, if any.
|
|
|
+ string message = request->_request._notify._message;
|
|
|
+ string expression = _fparams.lookup_token(message);
|
|
|
+ if (!expression.empty() && _browser_script_object != NULL) {
|
|
|
+ P3D_object *result = P3D_OBJECT_EVAL(_browser_script_object, expression.c_str());
|
|
|
+ P3D_OBJECT_XDECREF(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (request->_request_type == P3D_RT_stop) {
|
|
|
+ // We also send an implicit message when Python requests itself
|
|
|
+ // to shutdown.
|
|
|
+ _panda_script_object->set_pyobj(NULL);
|
|
|
+ _panda_script_object->set_string_property("status", "stopped");
|
|
|
+
|
|
|
+ string expression = _fparams.lookup_token("onpythonstop");
|
|
|
+ if (!expression.empty() && _browser_script_object != NULL) {
|
|
|
+ P3D_object *result = P3D_OBJECT_EVAL(_browser_script_object, expression.c_str());
|
|
|
+ P3D_OBJECT_XDECREF(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return request;
|
|
|
}
|
|
|
@@ -720,6 +734,7 @@ make_p3d_request(TiXmlElement *xrequest) {
|
|
|
if (strcmp(rtype, "notify") == 0) {
|
|
|
const char *message = xrequest->Attribute("message");
|
|
|
if (message != NULL) {
|
|
|
+ // A notify message from Python code.
|
|
|
request = new P3D_request;
|
|
|
request->_request_type = P3D_RT_notify;
|
|
|
request->_request._notify._message = strdup(message);
|
|
|
@@ -816,6 +831,8 @@ handle_notify_request(const string &message) {
|
|
|
P3D_OBJECT_DECREF(result);
|
|
|
}
|
|
|
|
|
|
+ _panda_script_object->set_string_property("status", "running");
|
|
|
+
|
|
|
} else if (message == "onwindowopen") {
|
|
|
// The process told us that it just succesfully opened its
|
|
|
// window. Tear down the splash window.
|
|
|
@@ -825,6 +842,8 @@ handle_notify_request(const string &message) {
|
|
|
_splash_window = NULL;
|
|
|
}
|
|
|
|
|
|
+ _panda_script_object->set_string_property("status", "open");
|
|
|
+
|
|
|
#ifdef __APPLE__
|
|
|
// Start a timer to update the frame repeatedly. This seems to be
|
|
|
// steadier than waiting for nullEvent.
|
|
|
@@ -976,6 +995,17 @@ make_splash_window() {
|
|
|
start_download(download);
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: P3DInstance::start_package_download
|
|
|
+// Access: Private
|
|
|
+// Description: Notified when the package download begins.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+void P3DInstance::
|
|
|
+start_package_download(P3DPackage *package) {
|
|
|
+ _panda_script_object->set_string_property("status", "downloading");
|
|
|
+ send_notify("ondownloadbegin");
|
|
|
+}
|
|
|
+
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: P3DInstance::install_progress
|
|
|
// Access: Private
|
|
|
@@ -990,6 +1020,40 @@ install_progress(P3DPackage *package, double progress) {
|
|
|
_panda_script_object->set_float_property("downloadProgress", progress);
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: P3DInstance::package_ready
|
|
|
+// Access: Private
|
|
|
+// Description: Notified when the package is fully downloaded.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+void P3DInstance::
|
|
|
+package_ready(P3DPackage *package, bool success) {
|
|
|
+ if (success) {
|
|
|
+ install_progress(package, 1.0);
|
|
|
+ _panda_script_object->set_bool_property("downloadComplete", true);
|
|
|
+ _panda_script_object->set_string_property("status", "starting");
|
|
|
+ send_notify("ondownloadcomplete");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: P3DInstance::send_notify
|
|
|
+// Access: Private
|
|
|
+// Description: Generates a synthetic notify message here at the C++
|
|
|
+// level.
|
|
|
+//
|
|
|
+// Most notify messages are generated from within the
|
|
|
+// Python code, and don't use this method; but a few
|
|
|
+// have to be sent before Python has started, and those
|
|
|
+// come through this method.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+void P3DInstance::
|
|
|
+send_notify(const string &message) {
|
|
|
+ P3D_request *request = new P3D_request;
|
|
|
+ request->_request_type = P3D_RT_notify;
|
|
|
+ request->_request._notify._message = strdup(message.c_str());
|
|
|
+ add_baked_request(request);
|
|
|
+}
|
|
|
+
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: P3DInstance::paint_window
|
|
|
// Access: Private
|