I'm developing a QGIS plugin to search classes and classes methods of QGIS. The dir equivalent option it was answered in:
As an example, the next image shows the search for methods with 'geo' pattern in QgsVectorLayer class and the result was as it expected.
When I tried out the equivalent help option at the plugin, with the next fixed example (see snipped code) for the 'geometryType' method of QgsVectorLayer, result it was always printed at the Python Console (not into the QTextBrowser object); as it can be observed at the next image.
. . . def getClasses(self): if self.dlg.checkBox.isChecked() == False: . . . else: message = help(QgsVectorLayer.geometryType) txtBox = self.dlg.textFeedback txtBox.setText(message) def run(self): """Run method that performs all the real work""" . . .
Other arbitrary messages were printed as I expected so, it was pointed out that this part of the code works well.
My question is:
There is any option to redirect the text of the help command to the QTextBrowser object or it is impossible?
I did a search based at the links supplied by Joseph:
and I can build this code:
import sys #save a reference to the Python Console of QGIS before reassignment oldstdout = sys.stdout #open an arbitrary file in disc to reassign the standard output sys.stdout = open('file', 'w') #write to the open file print help(QgsVectorLayer.geometryType) #force the flush to the open file sys.stdout.flush() #reassign the standard output to the Python Console sys.stdout = oldstdout
It works; as it can be observed at the next image (and the Python Console can be used again as standard output). However, I would like to improve the code by using a tempfile in memory before writing it to the QTextBrowser.