[Paraview] pqPythonShell on local server & local client

Alexander Wille alexander.wille at mytum.de
Fri Feb 15 06:18:09 EST 2008


Hello everyone,

I am trying to make a toolbar button which will do exactly the same as clicking 'Tools->Python Shell->Run Script'. I have a local server running, with a local client process GUI attached to it. Into that GUI I load a plugin with my toolbar, which has a button for running python scripts. The problem arises when I try to tie a PythonShell (without a PythonShellDialog) to my server. The PythonShell-constructor needs a QWidget*, and I think I should supply it with a pointer at the MainWindow (but I don't know, documentation on this is slim). Pointers at MainWindows can be retrievied through ProcessModuleGUIHelpers, but I can only create a new ProcessModuleGUIHelper, not get the one in charge of my currently running GUI.

I think the significant lines of code are these:

  ProcessModuleGUIHelper* gui = ProcessModuleGUIHelper::New() //Problem: This creates a NEW ParaView-Process instead of connecting to the one that's currently running
  pqPythonShell* py = new pqPythonShell(gui->getMainWindow()); //I'd like to connect a new PythonShell to my process like this


It is strange that a pqPythonShell needs a QWidget* for initialization; This contradicts the seperation of core functionality and GUI.

Can anybode tell me how to properly attach a PythonShell to a (local) server?


Thanks in advance,
Alex

P.S.: The entire source code for my toolbar is as follows:

#ifndef __paToolbar_h
#define __paToolbar_h

#include 
#include 
#include 
#include 
#include 
#include "pqApplicationCore.h"
#include "pqServerManagerModel.h"
#include "pqServer.h"
#include "ProcessModuleGUIHelper.h"
#include "pqPythonShell.h"

class paToolbar : public QActionGroup
{
Q_OBJECT

 public:
paToolbar(QObject* p) : QActionGroup(p)
   {
     // Using a Qt icon somehow depicting that there should be another icon there
     QIcon icon = qApp->style()->standardIcon(QStyle::SP_MessageBoxCritical);
     QAction* a = new QAction(icon, "Open & silently run a script in the python shell", this);
     this->addAction(a);
     QObject::connect(this, SIGNAL(triggered(QAction*)), this, SLOT(onAction(QAction*)));
   }

public slots:
void onAction(QAction* a)
   {
     pqServerManagerModel* sm = pqApplicationCore::instance()->getServerManagerModel();
     QList servers = sm->findItems();
     if(servers.size()) // Now I could easly retrieve a pqServer*
       {
	 ProcessModuleGUIHelper* gui = ProcessModuleGUIHelper::New()
	 QWidget* mwnd = gui->GetMainWindow();
	 a->setData(QFileDialog::getOpenFileName(mwnd, "Run script", "","Python Scripts (*.py)"));
	 if(a->data())
	   {
	     pqPythonShell* py = new pqPythonShell(mwnd);
	     py->initializeInterpretor();
	     py->executeScript(a->data().toString());
	   }
       }
   }
};
#endif


More information about the ParaView mailing list