00001 from PyQt4.QtGui import * 00002 from PyQt4.QtCore import * 00003 from ost import gui 00004 class DocWidget(QWidget): 00005 def __init__(self, parent=None): 00006 QWidget.__init__(self, parent) 00007 l=QVBoxLayout(self) 00008 l.setMargin(0) 00009 self.setWindowTitle('OpenStructure Help') 00010 self.searchbox=QLineEdit(self) 00011 l.addWidget(self.searchbox) 00012 self.doctext=QTextEdit('', self) 00013 l.addWidget(self.doctext) 00014 self.setLayout(l) 00015 QObject.connect(self.searchbox, SIGNAL('returnPressed()'), 00016 self.OnReturnPressed) 00017 def OnReturnPressed(self): 00018 help(str(self.searchbox.text())) 00019 doc_widget=DocWidget() 00020 doc_widget_for_panel=gui.Widget(doc_widget) 00021 panels=gui.GostyApp.Instance().perspective.panels 00022 panels.AddWidgetToPool("OpenStructure Help",doc_widget_for_panel) 00023 00024 00025 class Help: 00026 def __call__(self, what=None): 00027 import pydoc 00028 d=pydoc.HTMLDoc() 00029 if what==None: 00030 doc_widget.doctext.setHtml('') 00031 doc_widget.searchbox.setText('') 00032 else: 00033 try: 00034 s=d.document(pydoc.resolve(what)[0]) 00035 except ImportError, detail: 00036 s=str(detail) 00037 doc_widget.doctext.setHtml(s) 00038 doc_widget.searchbox.setText('') 00039 if not doc_widget.isVisible(): 00040 panels.AddWidget(gui.PanelPosition.RIGHT_PANEL, doc_widget_for_panel, False) 00041 def __repr__(self): 00042 return 'Type help() for interactive help, or help(object) for help about object.' 00043 00044 help=Help()