示例#1
0
  void PythonEngine::loadScript(const QString &filename)
  {
    QFileInfo info(filename);
    initializePython(info.canonicalPath());
    PythonThread pt;

    PythonScript *script = new PythonScript(filename);
    m_identifier = script->identifier();

    if(script->module()) {
      // make sure there is an Engine class defined
      if (PyObject_HasAttrString(script->module().ptr(), "Engine")) {

        try {
          prepareToCatchError();
          // instatiate the new Engine
          m_instance = script->module().attr("Engine")();
        } catch (error_already_set const &) {
          catchError();
          return;
        }

        m_script = script;

      } else {
        delete script;
        PythonError::instance()->append(tr("PythonEngine: checking ") + filename + "...");
        PythonError::instance()->append(tr("  - script has no 'Engine' class defined"));
      }
    } else {
      delete script;
      PythonError::instance()->append(tr("PythonEngine: checking ") + filename + "...");
      PythonError::instance()->append(tr("  - no module"));
    }
  }
示例#2
0
BehaviorsModule::BehaviorsModule(int teamNum, int playerNum)
    : error_state(false),
      brain_module(NULL),
      brain_instance(NULL),
      do_reload(0),
      pyInterface(),
      ledCommandOut(base()),
      motionRequestOut(base()),
      bodyMotionCommandOut(base()),
      headMotionCommandOut(base()),
      resetLocOut(base()),
      myWorldModelOut(base())
{
    std::cout << "BehaviorsModule::initializing" << std::endl;

    // Store team and player numbers
    teamNumber = teamNum;
    playerNumber = playerNum;

    // Initialize the PyInterface pointer
    set_interface_ptr(boost::shared_ptr<PyInterface> (&pyInterface));

    // Initialize the interpreter and C python extensions
    initializePython();

    // import noggin.Brain and instantiate a Brain reference
    import_modules();

    std::cout << "  Retrieving Brain.Brain instance" << std::endl;

    // Instantiate a Brain instance
    getBrainInstance();
}
示例#3
0
PythonBridge::PythonBridge( isis::viewer::QViewerCore *core )
	: m_ViewerCore( core )
{
	initializePython();

	exposeViewerCore();
	exposeImageHolder();
	exposeEnums();
}
示例#4
0
void doInitializePython(){
	if(functionPointersSet && pathSet){
		if(!pythonInitialized){
			pythonInitialized = true;
			printf("Starting to initialize python\n");
			initializePython(pluginPath);
		}
	}
}
示例#5
0
void BehaviorsModule::reload_hard ()
{
    std::cout << "Reloading Python interpreter" << std::endl;
    // finalize and reinitialize the Python interpreter
    Py_Finalize();
    // load C extension modules
    initializePython();
    // import noggin.Brain and instantiate a Brain reference
    import_modules();
    // Instantiate a Brain instance
    getBrainInstance();
}
示例#6
0
  void PythonTool::loadScript(const QString &filename)
  {
    QFileInfo info(filename);
    initializePython(info.canonicalPath());
    
    PythonThread pt;

    PythonScript *script = new PythonScript(filename);
    m_identifier = script->identifier();

    if(script->module()) {
      // make sure there is a Tool class defined
      if (PyObject_HasAttrString(script->module().ptr(), "Tool")) {
        try {
          prepareToCatchError();
          // instantiate the new tool
          m_instance = script->module().attr("Tool")();
          // if we have a settings widget already, add the python content...
          if (m_settingsWidget) {
            if (PyObject_HasAttrString(m_instance.ptr(), "settingsWidget")) {
              QWidget *widget = extract<QWidget*>(m_instance.attr("settingsWidget")());
              if (widget)
                m_settingsWidget->layout()->addWidget(widget);
            }
          }
        } catch (error_already_set const &) {
          catchError();
          return;
        }

        m_script = script;

      } else {
        delete script;
        PythonError::instance()->append(tr("PythonTool: checking ") + filename + "...");
        PythonError::instance()->append(tr("  - script has no 'Tool' class defined"));
      }
    } else {
      delete script;
      PythonError::instance()->append(tr("PythonTool: checking ") + filename + "...");
      PythonError::instance()->append(tr("  - no module"));
    }
  }