Skip to content
Snippets Groups Projects
Select Git revision
  • 6e60b71df07234c329fcf448ec67e26e5d84d525
  • master default protected
  • develop protected
  • cmake_boost_refactor
  • ubuntu_ci
  • mmtf
  • non-orthogonal-maps
  • no_boost_filesystem
  • data_viewer
  • 2.11.1
  • 2.11.0
  • 2.10.0
  • 2.9.3
  • 2.9.2
  • 2.9.1
  • 2.9.0
  • 2.8.0
  • 2.7.0
  • 2.6.1
  • 2.6.0
  • 2.6.0-rc4
  • 2.6.0-rc3
  • 2.6.0-rc2
  • 2.6.0-rc
  • 2.5.0
  • 2.5.0-rc2
  • 2.5.0-rc
  • 2.4.0
  • 2.4.0-rc2
29 results

helpwidget.py

Blame
  • Gabriel Studer's avatar
    Studer Gabriel authored
    This commit doesn't make OpenStructure work with Python 3. The goal of this
    commit was to perform an automated port of the Python code and make it compile.
    The performed steps:
    
    - Edited CMakeLists.txt to search for Python with 3.6 as min version 3.6 is the
      Python version shipped by default with Ubuntu 18.04 LTS
    - Add version 3.6 to cmake_support/FindPython.cmake
    - Adapt setup_boost macro in cmake_support/OST.cmake to prefer versioned
      libraries and not first check for boost_python.so. In the example of
      Ubuntu 18.04, libboost_python.so is specific for Python 2 but
      libboost_python3.so is the one we want.
    - apply the following command: 2to3-2.7 -n -w <OST_DIR>
    - adapt base/pymod/wrap_base.cc, gui/pymod/wrap_gui.cc and
      gui/pymod/export_message_widget.cc as PyString functionalities do not exist
      anymore in the Python 3 interpreter (replaced by PyUnicode)
    - adapt gui/src/python_shell/python_interpreter_worker.hh to resolve issue
      discussed in https://stackoverflow.com/questions/23068700/embedding-python3-in-qt-5
      Long story short: Qt does a typedef for "slots" which causes trouble with
      other headers that are pulled in from the Python interpreter
    6e60b71d
    History
    helpwidget.py 1.35 KiB
    from PyQt5 import QtWidgets
    from ost import gui
    class DocWidget(QtWidgets.QWidget):
      def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        l=QtWidgets.QVBoxLayout(self)
        l.setContentsMargins(0,0,0,0)
        self.setWindowTitle('OpenStructure Help')
        self.searchbox=QtWidgets.QLineEdit(self)
        l.addWidget(self.searchbox)
        self.doctext=QtWidgets.QTextEdit('', self)
        l.addWidget(self.doctext)
        self.setLayout(l)
        self.searchbox.returnPressed.connect(self.OnReturnPressed)
      def OnReturnPressed(self):
        help(str(self.searchbox.text()))
    doc_widget=DocWidget()
    doc_widget_for_panel=gui.Widget(doc_widget)
    panels=gui.GostyApp.Instance().perspective.panels
    panels.AddWidgetToPool("OpenStructure Help",doc_widget_for_panel)
    
    
    class Help:
      def __call__(self, what=None):
        import pydoc
        d=pydoc.HTMLDoc()
        if what==None:
          doc_widget.doctext.setHtml('')
          doc_widget.searchbox.setText('')
        else:
          try:
            s=d.document(pydoc.resolve(what)[0])
          except ImportError as detail:
            s=str(detail)
          doc_widget.doctext.setHtml(s)
          doc_widget.searchbox.setText('')
        if not doc_widget.isVisible():
          panels.AddWidget(gui.PanelPosition.RIGHT_PANEL, doc_widget_for_panel, False)
      def __repr__(self):
        return 'Type help() for interactive help, or help(object) for help about object.'
    
    help=Help()