Selaa lähdekoodia

ctkPythonConsole - help() function is now available

Jean-Christophe Fillion-Robin 14 vuotta sitten
vanhempi
commit
95d5e5de73
1 muutettua tiedostoa jossa 9 lisäystä ja 2 poistoa
  1. 9 2
      Libs/Scripting/Python/Widgets/ctkPythonConsole.cpp

+ 9 - 2
Libs/Scripting/Python/Widgets/ctkPythonConsole.cpp

@@ -265,10 +265,10 @@ ctkPythonConsole::ctkPythonConsole(ctkAbstractPythonManager* pythonManager, QWid
   // The call to mainContext() ensures that python has been initialized.
   Q_ASSERT(d->PythonManager);
   d->PythonManager->mainContext();
-  d->initializeInteractiveConsole();
-
   Q_ASSERT(PythonQt::self()); // PythonQt should be initialized
 
+  d->initializeInteractiveConsole();
+
   this->connect(PythonQt::self(), SIGNAL(pythonStdOut(const QString&)),
                 d, SLOT(printOutputMessage(const QString&)));
   this->connect(PythonQt::self(), SIGNAL(pythonStdErr(const QString&)),
@@ -282,6 +282,13 @@ ctkPythonConsole::ctkPythonConsole(ctkAbstractPythonManager* pythonManager, QWid
   this->setPs2("... ");
 
   this->reset();
+
+  // Expose help() function
+  QStringList helpImportCode;
+  helpImportCode << "import pydoc";
+  helpImportCode << "help = pydoc.help.help";
+  helpImportCode << "del pydoc";
+  d->PythonManager->executeString(helpImportCode.join("\n"));
 }
 
 //----------------------------------------------------------------------------