Source code for schrodinger.utils.documentation
import os
from urllib.parse import urlparse
import pyhelp
from schrodinger import get_maestro
from schrodinger.infra import mm
from schrodinger.Qt import QtCore
from schrodinger.Qt import QtGui
from schrodinger.Qt import QtWidgets
from schrodinger.utils import fileutils
from schrodinger.utils import log
from schrodinger.utils.config import get_knime_workflows_url
from schrodinger.utils.env import swap_ld_library_path
logger = log.get_output_logger("documentation")
return_if_url_fails = True
[docs]def show_topic(topic_name):
"""
Opens a window to display the help topic.
:param topic_name Name of help topic
:type topic_name str
"""
docsdir = os.path.join(os.environ['SCHRODINGER'], "docs")
if not os.path.isdir(docsdir):
warn_message = ("Documentation is not installed. "
"Please check and fix your installation.")
return show_message(warn_message)
relative_topic_url = pyhelp.mmpyhelp_get_relative_topic_url(topic_name)
if not relative_topic_url:
warn_message = ("Missing help topic ID: {}<br/>"
"Please report this problem to Schrödinger."
).format(topic_name)
return show_message(warn_message)
relative_topic_fp = urlparse(relative_topic_url).path
topic_fp = os.path.normpath(os.path.join(docsdir, relative_topic_fp))
if not os.path.isfile(topic_fp):
warn_message = ("Missing help topic file: {}<br/>"
"Please report this problem to Schrödinger."
).format(relative_topic_fp)
return show_message(warn_message)
doc_base_path = os.path.join(docsdir, 'Documentation.htm')
open_url(doc_base_path, fragment=relative_topic_fp)
[docs]def show_python_api():
"""
Opens a browser to display local python API.
"""
url = ("http://www.schrodinger.com/docs/suite{}/python_api/api"
"/frames.html".format(mm.mmfile_get_release_name()))
status = open_url(url, return_if_url_fails)
if not status:
url = os.path.join(os.environ['SCHRODINGER'], "docs", "python_api",
"api", "frames.html")
open_url(url)
[docs]def show_python_overview():
url = ("http://www.schrodinger.com/docs/suite{}/python_api/overview."
"html".format(mm.mmfile_get_release_name()))
status = open_url(url, return_if_url_fails)
if not status:
url = os.path.join(os.environ['SCHRODINGER'], "docs", "python_api",
"overview.html")
open_url(url)
[docs]def show_python_search():
url = "http://www.schrodinger.com/pythonapi/"
open_url(url)
[docs]def show_manuals_index():
help_dir = pyhelp.mmpyhelp_get_docs_dir()
url = os.path.join(help_dir, "Documentation.htm")
open_url(url)
[docs]def show_knowledge_base(context=""):
url = "http://www.schrodinger.com/kb_redirect.php%s" % context
open_url(url)
[docs]def show_new_features(context=""):
url = "http://www.schrodinger.com/new_features_general_redirect.php%s" % context
open_url(url)
[docs]def show_new_maestro_features(context=""):
url = "http://www.schrodinger.com/new_features_maestro_redirect.php%s" % context
open_url(url)
[docs]def show_known_issues(context=""):
url = "http://www.schrodinger.com/Known_Issues.html%s" % context
open_url(url)
[docs]def show_canvas_user_manual():
help_dir = pyhelp.mmpyhelp_get_docs_dir()
url = os.path.join(help_dir, "canvas_user_manual",
"canvas_user_manualTOC.htm")
open_url(url)
# Maestro URLS
[docs]def show_elements_visualization_tutorial():
url = os.path.join(os.environ['SCHRODINGER'], "docs", "maestro_elements",
'maestro_elements_tutorial_vis.pdf')
open_url(url)
[docs]def show_elements_task_tutorial():
url = os.path.join(os.environ['SCHRODINGER'], "docs", "maestro_elements",
'maestro_elements_tutorial_tasks.pdf')
open_url(url)
[docs]def show_about_utilities():
help_dir = pyhelp.mmpyhelp_get_docs_dir()
url = os.path.join(help_dir, "quick_reference", "schrodinger_utilities.htm")
open_url(url)
[docs]def show_legal_notice():
url = os.path.join(os.environ['SCHRODINGER'], "docs",
"third_party_legal.html")
open_url(url)
[docs]def show_maestro_training_videos(context=""):
url = "http://www.schrodinger.com/videos_redirect.php%s" % context
open_url(url)
[docs]def show_knime_workflows():
open_url(get_knime_workflows_url())
[docs]@swap_ld_library_path()
def open_url(url, show_warning=True, fragment=None):
if os.path.isfile(url):
#normalizes path separators
qurl = QtCore.QUrl.fromLocalFile(url)
else:
qurl = QtCore.QUrl(url)
qurl.setFragment(fragment)
status = openTempURL(qurl)
if not status:
if show_warning:
warn_msg = (
"WARNING Please check if the given path - {} is okay and has a "
"valid associated application to open it.").format(url)
show_message(warn_msg)
return status
[docs]def openTempURL(qurl):
"""
Create a temporary file containing HTML and open it in browser
The HTML redirects the browser to the appropriate url. This circumvents a
bug in Windows and MacOS that chops off the anchor of a URL if the URL
points to a local file.
:param qurl: The QUrl to redirect to
:type qurl: QtCore.QUrl
:return: Success of opening the temp URL
:rtype: bool
"""
url = qurl.toString()
temp_dir = fileutils.get_directory_path(fileutils.TEMP)
redir_file = os.path.join(temp_dir, "redir.html")
html = ("<html><head>"
"<meta http-equiv=\"refresh\" "
"content=\"0;url={}\" />"
"</head></html>").format(url)
with open(redir_file, mode="w") as fh:
fh.write(html)
redir_qurl = QtCore.QUrl.fromLocalFile(redir_file)
status = QtGui.QDesktopServices.openUrl(redir_qurl)
return status
[docs]def show_message(message):
if not QtWidgets.QApplication.instance():
logger.error(message)
else:
QtWidgets.QMessageBox.warning(None, "Warning", message)