From 58555a28958b4f0f3795245f0ab5e6f242ac1aac Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 1 Sep 2009 00:18:31 +0000 Subject: [PATCH] windows issues --- direct/src/p3d/AppRunner.py | 9 ++++++ direct/src/p3d/Packager.py | 6 ++++ direct/src/plugin/p3dPythonRun.cxx | 41 +++++++++++++++++++----- direct/src/plugin_standalone/panda3d.cxx | 12 ++++--- 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/direct/src/p3d/AppRunner.py b/direct/src/p3d/AppRunner.py index dc01e43ff2..cc2b61d902 100644 --- a/direct/src/p3d/AppRunner.py +++ b/direct/src/p3d/AppRunner.py @@ -303,6 +303,12 @@ class AppRunner(DirectObject): if mainName: moduleName = mainName + # Temporarily clear this flag while we import the app, so + # that if the app calls run() within its own main.py, it + # will properly get ignored by ShowBase. + interactiveConsole = self.interactiveConsole + self.interactiveConsole = False + try: __import__(moduleName) except ImportError: @@ -312,6 +318,9 @@ class AppRunner(DirectObject): if hasattr(main, 'main') and callable(main.main): main.main(self) + # Now restore this flag. + self.interactiveConsole = interactiveConsole + if self.interactiveConsole: # At this point, we have successfully loaded the app. # If the interactive_console flag is enabled, stop the diff --git a/direct/src/p3d/Packager.py b/direct/src/p3d/Packager.py index 332a78e6d7..8efd549819 100644 --- a/direct/src/p3d/Packager.py +++ b/direct/src/p3d/Packager.py @@ -435,6 +435,9 @@ class Packager: # files). This will include the extension modules we just # discovered above. for file in self.files: + if file.isExcluded(self): + # Skip this file. + continue ext = Filename(file.newName).getExtension() if file.unprocessed: # Add an unprocessed file verbatim. @@ -466,6 +469,9 @@ class Packager: # We walk through the list as we modify it. That's OK, # because we may add new files that we want to process. for file in self.files: + if file.isExcluded(self): + # Skip this file. + continue ext = Filename(file.newName).getExtension() if file.unprocessed: # Already handled, above. diff --git a/direct/src/plugin/p3dPythonRun.cxx b/direct/src/plugin/p3dPythonRun.cxx index baff6f5705..9ef6ce6c36 100755 --- a/direct/src/plugin/p3dPythonRun.cxx +++ b/direct/src/plugin/p3dPythonRun.cxx @@ -130,14 +130,32 @@ run_python() { // We'll need libpandaexpress to be imported before we can load // _vfsimporter. So, find it and load it. - Filename libpandaexpress(_archive_file.get_dirname(), - Filename::dso_filename("libpandaexpress.so")); -#if defined(__APPLE__) && PY_VERSION_HEX < 0x02050000 - // On OSX, for Python versions 2.4 and before, we have to load the - // .so file, not the .dylib file. - libpandaexpress.set_type(Filename::T_general); -#endif + Filename libpandaexpress; +#ifdef _WIN32 + // Of course it's already resident, so use that version. + HMODULE h = GetModuleHandle("libpandaexpress.dll"); + if (h == NULL) { + nout << "Can't find libpandaexpress in memory.\n"; + } else { + static const int buffer_size = 4096; + char buffer[buffer_size]; + GetModuleFileName(h, buffer, buffer_size); + libpandaexpress = Filename::from_os_specific(buffer); + } +#endif // _WIN32 + + if (libpandaexpress.empty()) { + // Go look for it on disk. + libpandaexpress = Filename(_archive_file.get_dirname(), + Filename::dso_filename("libpandaexpress.so")); +#if defined(__APPLE__) && PY_VERSION_HEX < 0x02050000 + // On OSX, for Python versions 2.4 and before, we have to load the + // .so file, not the .dylib file. + libpandaexpress.set_type(Filename::T_general); +#endif + } + if (!libpandaexpress.exists()) { nout << "Can't find " << libpandaexpress << "\n"; return false; @@ -350,12 +368,19 @@ run_python() { //////////////////////////////////////////////////////////////////// void P3DPythonRun:: run_interactive_console() { +#ifdef _WIN32 + // Make sure that control-C support is enabled for the interpreter. + SetConsoleCtrlHandler(NULL, false); +#endif + // The "readline" module makes the Python prompt friendlier, with // command history and everything. Simply importing it is // sufficient. PyObject *readline_module = PyImport_ImportModule("readline"); if (readline_module == NULL) { - PyErr_Print(); + // But, the module might not exist on certain platforms. If not, + // no sweat. + PyErr_Clear(); } else { Py_DECREF(readline_module); } diff --git a/direct/src/plugin_standalone/panda3d.cxx b/direct/src/plugin_standalone/panda3d.cxx index e766e88ccb..8ef7a8b4f3 100644 --- a/direct/src/plugin_standalone/panda3d.cxx +++ b/direct/src/plugin_standalone/panda3d.cxx @@ -148,11 +148,13 @@ run(int argc, char *argv[]) { token._value = "1"; _tokens.push_back(token); -#ifndef _WIN32 - // We should also ignore SIGINT in this case, so that a - // control-C operation will be delivered to the subordinate - // Python process and return to a command shell, and won't - // just kill the panda3d process. + // We should also ignore control-C in this case, so that an + // interrupt will be delivered to the subordinate Python + // process and return to a command shell, and won't just kill + // the panda3d process. +#ifdef _WIN32 + SetConsoleCtrlHandler(NULL, true); +#else struct sigaction ignore; memset(&ignore, 0, sizeof(ignore)); ignore.sa_handler = SIG_IGN;