Dear Shroedinger (or possibly just Thomas Holder),
Hi, I'm Max Klein. I'm a 5th year PhD student the computational biophysics department at Johns Hopkins. I've been a heavy Pymol user for about 7 years now.
I first ran into issues with the Pymol external GUI on OS X 5 years ago when I started making builds of the open source Pymol. Up until now, the best fix that had been available was to build a version of tcl-tk against X11 using homebrew (which is in general pretty great), then build a version of Python using homebrew against that brewed tcl-tk, and then build Pymol itself against that brewed Python.
It was a pretty involved build, but it worked fine once you got the hang of it. The problem now is that Homebrew has dropped all support for X11, including in tcl-tk. In light of that, I worked out how to get the external GUI to actually run just using the tcl-tk that's shipped with OS X, and that uses the OS X native Aqua winowing manager. You can find the complete patch code in context (built on top of a mirror of this SVN) over on GitHub at https://github.com/telamonian/pymol/tree/osx_gui_fix_-_invert_threads.
And it works! Pretty well actually, from my initial testing. Basically, any Aqua windows made by Python's Tkinter absolutely have to run in the main thread or else they trigger errors at both the Python level and the operating system level (via Apple's Core Services libs). In order to accomodate this, and only when Pymol is running on OS X using Aqua, I wrote a patch that tweaks Pymol's kickoff routine. What ends up happening is that the external GUI thread runs in the main thread, while the glut GUI, which normally runs on the main thread, runs instead in a child thread.
This inversion of threads does not seem to have any effect on the performance or function of Pymol, so I think that this is a viable fix for a long-standing bug. Please feel free to ask me for any changes to the patch that you think are appropriate. Everything has been throroughly tested on several different version of OS X, but I assume that there will be at least a few issues of syntanx and/or semantics to iron out with respect to the rest of the Pymol project. Overall I have attempted to alter as little as possible, both in terms of program execution and the code itself.
Thank you very much for your attention, and I hope that this patch will prove useful to the community of open source Pymol users. Some extra notes can be found in the header of the patchfile itself.
Best regards,
Max Klein
PhD Candidate in Biophysics
Roberts Lab, Johns Hopkins
Here's the latest verson of the patch, with a fix for a bug that showed up durring testing on Linux.
Hi Max -
This is fantastic! Great work! I will do some heavy testing and see how this plays with the other available environments on macOS (macports, fink, anaconda, system python, GLUT framework, ...).
Thomas
Hi Max -
Would you mind testing my modified patch (tk-aqua-v2.patch)? It reuses more existing code.
Also, please add a note or comment to this issue that you put your patch in the public domain or under a BSD-like license.
For the record, this works for me with:
- homebrew
- system Python
- anaconda
It does not work with:
- macports (tk +quartz), threading issues
- GLUT framework instead of X11 freeglut
Thomas
I haven't gotten any feedback on my revised patch (tk-aqua-v2.patch). Is there still interest is getting this patch in?