Here's what I'm currently using. It seems to work so far. Looking through
the PyMol binary I see about 50 possible names though, so it would be nice
if there were a built-in way to detect X11.
def hasTk():
""" Make an educated guess as to whether Tk is installed,
hopefully without triggering any installation on Macs
"""
hasTk = True
if sys.platform=="darwin": #Mac
# Hack: check the path for entries containing 'X11'
hasTk = any([ "X11" in p.upper() for p in sys.path])
if hasTk:
try:
import Tkinter
except ImportError:
hasTk = False
return hasTk
On Mon, Apr 14, 2014 at 10:46 AM, Spencer Bliven <sbli...@ucsd.edu> wrote:
> I'm working on a plugin with a command line interface and a light-weight
> tk interface through the plugins menu. This works fine on Linux, Windows,
> and open-source Mac builds, but not on MacPyMol.app. Importing Tkinter
> causes PyMol to quit with a prompt to install X11 (but not an ImportError,
> as far as I can tell). If X11 is installed there are no errors, but there
> is not a plugins menu, so I'd rather not bother loading and initializing
> the Tk interface to the plugin.
>
> How can I detect whether Tk is available?
>
> I can think of two approaches, but haven't figured out the correct
> commands for either. (1) Check the name that pymol was started with.
> "MacPyMol.app" does not have Tk, while "PyMOLX11Hybrid.app" does. I'm not
> sure how to get the name (maybe could be guessed from sys.path?), and I
> know there are a lot more variants than those two available. (2) Check for
> the existence of the plugins menu. But this would have to be done without
> importing Tk and triggering the X11 check.
>
> Is there a simple way to do this I'm overlooking?
>
> Thanks,
> -Spencer
>
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net