MCPcopy Create free account
hub / github.com/commontk/CTK / initialize

Method initialize

Libs/Scripting/Python/Widgets/ctkPythonConsole.cpp:644–686  ·  view source on GitHub ↗

/----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

642
643////----------------------------------------------------------------------------
644void ctkPythonConsole::initialize(ctkAbstractPythonManager* newPythonManager)
645{
646 Q_D(ctkPythonConsole);
647
648 if (d->PythonManager)
649 {
650 qWarning() << "ctkPythonConsole already initialized !";
651 return;
652 }
653
654 // The call to mainContext() ensures that python has been initialized.
655 Q_ASSERT(newPythonManager);
656 newPythonManager->mainContext();
657 Q_ASSERT(PythonQt::self()); // PythonQt should be initialized
658
659 ctkPythonConsoleCompleter* completer = new ctkPythonConsoleCompleter(*newPythonManager);
660 this->setCompleter(completer);
661
662 d->PythonManager = newPythonManager;
663
664 d->initializeInteractiveConsole();
665
666 this->connect(PythonQt::self(), SIGNAL(pythonStdOut(QString)),
667 this, SLOT(printOutputMessage(QString)));
668 this->connect(PythonQt::self(), SIGNAL(pythonStdErr(QString)),
669 this, SLOT(printErrorMessage(QString)));
670
671 PythonQt::self()->setRedirectStdInCallback(
672 ctkConsole::stdInRedirectCallBack, reinterpret_cast<void*>(this));
673
674 // Set primary and secondary prompt
675 this->setPs1(">>> ");
676 this->setPs2("... ");
677
678 this->reset();
679
680 // Expose help() function
681 QStringList helpImportCode;
682 helpImportCode << "from pydoc import help";
683 d->PythonManager->executeString(helpImportCode.join("\n"));
684
685 this->setDisabled(false);
686}
687
688//----------------------------------------------------------------------------
689QString ctkPythonConsole::ps1() const

Callers

nothing calls this directly

Calls 10

setPs1Method · 0.95
setPs2Method · 0.95
resetMethod · 0.95
printErrorMessageFunction · 0.85
mainContextMethod · 0.80
setCompleterMethod · 0.80
connectMethod · 0.80
joinMethod · 0.80
executeStringMethod · 0.45

Tested by

no test coverage detected