本文整理汇总了C++中PythonQtObjectPtr::addObject方法的典型用法代码示例。如果您正苦于以下问题:C++ PythonQtObjectPtr::addObject方法的具体用法?C++ PythonQtObjectPtr::addObject怎么用?C++ PythonQtObjectPtr::addObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PythonQtObjectPtr
的用法示例。
在下文中一共展示了PythonQtObjectPtr::addObject方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateGeometry
//----------------------------------------------------------------------------
void DolfinGui::updateGeometry(Geometry *geometry)
{
// Use python script to obtain values in QLineEdit boxes
PythonQt::init();
PythonQtObjectPtr mainModule = PythonQt::self()->getMainModule();
mainModule.addObject("infoBox", geometry->getInfoBox());
double *points = new double[geometry->getPointCount()];
double *radius = new double[geometry->getRadiusCount()];
std::cout << "Points: " << std::endl;
for (int i=0; i < geometry->getPointCount(); ++i){
points[i] = mainModule.evalScript(QString("eval(infoBox.pointEdit%1.text)").arg(i),
Py_eval_input).toDouble();
std::cout << i << ": " << points[i] << std::endl;
}
if (geometry->getRadiusCount() > 0){
for (int i=0; i < geometry->getRadiusCount(); ++i){
radius[i] = mainModule.evalScript(QString("eval(infoBox.radiusEdit%1.text)").arg(i),
Py_eval_input).toDouble();
}
}
geometry->setPoints(points);
geometry->setRadius(radius);
geometry->setGeometryPointer(generateGeometry(geometry));
std::cout << "Point count: " << geometry->getPointCount() << std::endl;
plotGeometry();
}
示例2: main
int main( int argc, char **argv )
{
QApplication qapp(argc, argv);
PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut);
PythonQt_QtAll::init();
PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
PythonQtScriptingConsole console(NULL, mainContext);
// add a QObject to the namespace of the main python context
PyExampleObject example;
mainContext.addObject("example", &example);
mainContext.evalFile(":example.py");
console.show();
return qapp.exec();
}
示例3: main
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QSplashScreen* splash = new QSplashScreen(QPixmap(":splash/cgogn/splash.png"));
splash->show();
splash->showMessage("Welcome to SCHNApps", Qt::AlignBottom | Qt::AlignCenter);
// init PythonQt and Python itself
PythonQt::init();
QStringList classNames;
classNames.append("View");
classNames.append("Camera");
classNames.append("Plugin");
classNames.append("MapHandlerGen");
PythonQt::self()->registerQObjectClassNames(classNames);
// get a smart pointer to the __main__ module of the Python interpreter
PythonQtObjectPtr pythonContext = PythonQt::self()->getMainModule();
PythonQtScriptingConsole* pythonConsole = new PythonQtScriptingConsole(NULL, pythonContext);
CGoGN::SCHNApps::SCHNApps schnapps(app.applicationDirPath(), pythonContext, *pythonConsole);
schnapps.show();
pythonContext.addObject("schnapps", &schnapps);
if(argc > 1)
{
QString filename(argv[1]);
QFileInfo fi(filename);
if (fi.exists())
//pythonContext.evalFile(fi.filePath());
schnapps.loadPythonScriptFromFile(fi.filePath());
}
splash->finish(&schnapps);
delete splash;
return app.exec();;
}
示例4: updateSphere
//----------------------------------------------------------------------------
void DolfinGui::updateSphere(SphereGeometry *sphere){
std::cout << "In method updateSphere(): \n";
std::cout << "-------- HELLO!!! --------" << std::endl;
// Use python script to obtain values for corner points
PythonQtObjectPtr mainModule = PythonQt::self()->getMainModule();
mainModule.addObject("sphereInfoBox", sphere->getInfoBox());
for (int i=0; i<sphere->getPointCount(); ++i)
sphere->getPoints()[i] = mainModule.evalScript(QString("eval(sphereInfoBox.sphereEdit%1.text)").arg(i),
Py_eval_input).toDouble();
// Use python script to obtain values for radius
for (int i=0; i<sphere->getRadiusCount(); ++i)
sphere->getRadius()[i] = mainModule.evalScript(QString("eval(sphereInfoBox.radiusEdit%1.text)").arg(i),
Py_eval_input).toDouble();
plotSphere(sphere);
sphereSelected = false;
}
示例5: updateCone
//----------------------------------------------------------------------------
void DolfinGui::updateCone(ConeGeometry *cone){
std::cout << "In method updateCone(): \n";
std::cout << "-------- HELLO!!! --------" << std::endl;
for (int i=0; i<6; ++i)
std::cout << cone->getPoints()[i] << " " << std::endl;
// Use python script to obtain values for corner points
PythonQtObjectPtr mainModule = PythonQt::self()->getMainModule();
mainModule.addObject("coneInfoBox", cone->getInfoBox());
for (int i=0; i<cone->getPointCount(); ++i)
cone->getPoints()[i] = mainModule.evalScript(QString("eval(coneInfoBox.coneEdit%1.text)").arg(i),
Py_eval_input).toDouble();
// Use python script to obtain values for radius
for (int i=0; i<cone->getRadiusCount(); ++i)
cone->getRadius()[i] = mainModule.evalScript(QString("eval(coneInfoBox.radiusEdit%1.text)").arg(i),
Py_eval_input).toDouble();
plotCone(cone);
std::cout << "Ferdig" << std::endl;
//coneSelected = false;
}
示例6: updateCube
//----------------------------------------------------------------------------
void DolfinGui::updateCube(CubeGeometry *cube)
{
// Set up arrays to hold information about corner points
//GeometryInfo *cubeInfo = new GeometryInfo(6);
//double dataList[cube->getPointCount()];
//cube->setPoints(dataList);
updateRequested = true;
std::cout << "In method updateCube(): \n";
std::cout << "-------- HELLO!!! --------" << std::endl;
//for (int i=0; i<6; ++i)
// std::cout << cube->getPoints()[i] << " " << std::endl;
// Use python script to obtain new values for corner points
PythonQtObjectPtr mainModule = PythonQt::self()->getMainModule();
mainModule.addObject("cubeInfoBox", cube->getInfoBox());
for (int i=0; i<cube->getPointCount(); ++i){
cube->getPoints()[i] = mainModule.evalScript(QString("eval(cubeInfoBox.cubeEdit%1.text)").arg(i),
Py_eval_input).toDouble();
}
plotCube(cube);
cubeSelected = false;
}
示例7: PostInitialize
void PythonScriptModule::PostInitialize()
{
// An error has occurred on startup.
if (!pythonQtStarted_)
return;
// Get python main module.
PythonQtObjectPtr mainModule = PythonQt::self()->getMainModule();
if (mainModule.isNull())
{
LogError("PythonScriptModule::StartPythonQt(): Failed to get main module from PythonQt after init!");
return;
}
// Add PythonScriptModule as '_pythonscriptmodule'
// and Framework as '_tundra' to python.
mainModule.addObject("_pythonscriptmodule", this);
mainModule.addObject("_tundra", GetFramework());
QDir pythonPlugins(Application::InstallationDirectory() + "pyplugins");
QDir pythonLibrary(pythonPlugins.absoluteFilePath("python/"));
// Add Tundra python plugins source location.
AddSystemPath(pythonPlugins.absolutePath());
AddSystemPath(pythonPlugins.absoluteFilePath("lib"));
// Add Python Library DLL and on windows pass whole python as a archive file.
/// \todo Is the 'DLLs' really needed also outside windows?
AddSystemPath(pythonLibrary.absoluteFilePath("DLLs"));
#ifdef _WIN32
AddSystemPath(pythonLibrary.absoluteFilePath("Python26.zip"));
#endif
// Connect to SceneAPI
QObject::connect(GetFramework()->Scene(), SIGNAL(SceneAdded(const QString&)), this, SLOT(OnSceneAdded(const QString&)));
// Console commands to ConsoleAPI
GetFramework()->Console()->RegisterCommand("PyExec", "Execute given code in the embedded Python interpreter. Usage: PyExec(mycodestring)",
this, SLOT(ConsoleRunString(const QStringList&)));
GetFramework()->Console()->RegisterCommand("PyLoad", "Execute a python file. Usage: PyLoad(mypymodule)",
this, SLOT(ConsoleRunFile(const QStringList&)));
GetFramework()->Console()->RegisterCommand("PyRestart", "Restarts the Tundra Python ModuleManager",
this, SLOT(ConsoleRestartPython(const QStringList&)));
GetFramework()->Console()->RegisterCommand("PyConsole", "Creates a new Python console window.",
this, SLOT(ShowConsole()));
// Done in PostInitialize() so all modules/APIs are loaded and initialized.
//StartPythonModuleManager();
// --p --python --pythonapitests are special command line options that on purpose not put
// to the Framework program options parsing. So lets do a special parse here for there hidden variables.
/// \todo See if we should return --p --python as official cmd line options back to Framework. Probably best to have modules give own params somehow,
/// we should not mess python specific things to core SDK params in Framework.cpp :I
namespace po = boost::program_options;
po::variables_map commandLineVariables;
po::options_description commandLineDescriptions;
commandLineDescriptions.add_options()
("p", po::value<std::string>(), "Run a python script on startup")
("python", po::value<std::string>(), "Run a python script on startup")
("pythonapitests", "Run a python api test script on startup");
try
{
/// \note QApplication::argc() and QApplication::argv() are deprecated.
po::store(po::command_line_parser(QApplication::argc(), QApplication::argv()).options(commandLineDescriptions).allow_unregistered().run(), commandLineVariables);
}
catch(std::exception &e)
{
LogWarning(Name() + ": " + + e.what());
}
po::notify(commandLineVariables);
if (commandLineVariables.count("python"))
RunScript(commandLineVariables["python"].as<std::string>().c_str());
if (commandLineVariables.count("p"))
RunScript(commandLineVariables["p"].as<std::string>().c_str());
LoadStartupScripts();
}