← Back to team overview

yade-dev team mailing list archive

[svn] r1801 - in trunk/gui: py qt3

 

Author: eudoxos
Date: 2009-06-16 22:20:22 +0200 (Tue, 16 Jun 2009)
New Revision: 1801

Modified:
   trunk/gui/py/PythonUI_rc.py
   trunk/gui/qt3/QtGUI-python.cpp
   trunk/gui/qt3/QtGUI.cpp
   trunk/gui/qt3/QtGUI.hpp
   trunk/gui/qt3/YadeQtMainWindow.cpp
   trunk/gui/qt3/YadeQtMainWindow.hpp
   trunk/gui/qt3/qt.py
Log:
A few changes to allow run primarily python with qt3 on the top of that (open, close etc as needed). This paves way to running main yade process in python ;-) (just kidding, for now)


Modified: trunk/gui/py/PythonUI_rc.py
===================================================================
--- trunk/gui/py/PythonUI_rc.py	2009-06-15 17:42:13 UTC (rev 1800)
+++ trunk/gui/py/PythonUI_rc.py	2009-06-16 20:20:22 UTC (rev 1801)
@@ -70,9 +70,11 @@
 
 def cleanup():
 	try:
-		import yade.qt, time
-		yade.qt.close()
-		while True: time.sleep(.1) # wait to be killed
+		#import yade.qt, time
+		import yade._qt
+		if yade._qt.isActive(): yade._qt.close();
+		#yade.qt.close()
+		#while True: time.sleep(.1) # wait to be killed
 	except ImportError: pass
 
 

Modified: trunk/gui/qt3/QtGUI-python.cpp
===================================================================
--- trunk/gui/qt3/QtGUI-python.cpp	2009-06-15 17:42:13 UTC (rev 1800)
+++ trunk/gui/qt3/QtGUI-python.cpp	2009-06-16 20:20:22 UTC (rev 1801)
@@ -20,8 +20,16 @@
 	void setRefSe3(){ proxee->setBodiesRefSe3(Omega::instance().getRootBody()); }
 BASIC_PY_PROXY_TAIL;
 
-YadeQtMainWindow* ensuredMainWindow(){if(!YadeQtMainWindow::self) throw runtime_error("No instance of YadeQtMainWindow"); return YadeQtMainWindow::self; }
+#include<yade/gui-qt3/QtGUI.hpp>
+bool qtGuiIsActive(){return (bool)YadeQtMainWindow::self; }
+void qtGuiActivate(){
+	if(qtGuiIsActive()) return;
+	QtGUI* gui=new QtGUI();
+	gui->runNaked();
+}
 
+YadeQtMainWindow* ensuredMainWindow(){if(!qtGuiIsActive()){qtGuiActivate(); while(!YadeQtMainWindow::self) usleep(50000); } /* throw runtime_error("No instance of YadeQtMainWindow");*/ return YadeQtMainWindow::self; }
+
 void centerViews(void){ensuredMainWindow()->centerViews();}
 void Quit(void){ if(YadeQtMainWindow::self) YadeQtMainWindow::self->Quit(); }
 pyOpenGLRenderingEngine ensuredRenderer(){ensuredMainWindow()->ensureRenderer(); return pyOpenGLRenderingEngine(ensuredMainWindow()->renderer);}
@@ -30,7 +38,6 @@
 POST_SYNTH_EVENT(PLAYER,player);
 POST_SYNTH_EVENT(CONTROLLER,controller);
 POST_SYNTH_EVENT(GENERATOR,generator);
-// BOOST_PYTHON_FUNCTION_OVERLOADS(evtPLAYER_overloads,evtPLAYER,0,1); BOOST_PYTHON_FUNCTION_OVERLOADS(evtCONTROLLER_overloads,evtCONTROLLER,0,1); BOOST_PYTHON_FUNCTION_OVERLOADS(evtGENERATOR_overloads,evtGENERATOR,0,1);
 #undef POST_SYNT_EVENT
 
 // event associated data will be deleted in the event handler
@@ -80,7 +87,7 @@
 	shared_ptr<QtSimulationPlayer> player=ensuredMainWindow()->player;
 	GLSimulationPlayerViewer* glv=player->glSimulationPlayerViewer;
 	string snapBase2(snapBase);
-	if(snapBase2.empty()){ char tmpnam_str [L_tmpnam]; tmpnam(tmpnam_str); snapBase2=tmpnam_str; LOG_INFO("Using "<<snapBase2<<" as temporary basename for snapshots."); }
+	if(snapBase2.empty()){ char tmpnam_str [L_tmpnam]; char* ret=tmpnam(tmpnam_str); if(ret!=tmpnam_str) throw runtime_error("tmpnam failed."); snapBase2=tmpnam_str; LOG_INFO("Using "<<snapBase2<<" as temporary basename for snapshots."); }
 	glv->stride=stride;
 	glv->load(savedSim); // Omega locks rendering here for us
 	glv->saveSnapShots=true;
@@ -102,7 +109,6 @@
 	return python::make_tuple(snapBase2+"-%.04d.png",snaps);
 }
 
-bool qtGuiIsActive(){return (bool)YadeQtMainWindow::self;}
 
 BOOST_PYTHON_FUNCTION_OVERLOADS(runPlayerSession_overloads,runPlayerSession,2,7);
 
@@ -110,53 +116,57 @@
 python::tuple vec2tuple(qglviewer::Vec v){return python::make_tuple(v[0],v[1],v[2]);};
 
 class pyGLViewer{
-	shared_ptr<GLViewer> glv;
-	void init(size_t viewNo){
-		if(YadeQtMainWindow::self->glViews.size()<viewNo+1 || !YadeQtMainWindow::self->glViews[viewNo]){throw runtime_error("No view #"+lexical_cast<string>(viewNo));}
-		glv=YadeQtMainWindow::self->glViews[viewNo];
+	size_t viewNo;
+	void init(size_t _viewNo){
+		viewNo=_viewNo;
+		getGlv();
 	}
+	GLViewer* getGlv(){ if(YadeQtMainWindow::self->glViews.size()<viewNo+1 || !YadeQtMainWindow::self->glViews[viewNo]){throw runtime_error("No view #"+lexical_cast<string>(viewNo));} return YadeQtMainWindow::self->glViews[viewNo].get(); }
 	public:
-		#define MUTEX GLLock _lock(glv.get());
+		#define MUTEX GLLock _lock(glv)
+		#define GLV GLViewer* glv=getGlv()
 		pyGLViewer(){ init(0); }
-		pyGLViewer(size_t viewNo){init(viewNo);}
-		pyGLViewer(const shared_ptr<GLViewer>& _glv){glv=_glv;}
-		python::tuple get_grid(){return python::make_tuple(glv->drawGridXYZ[0],glv->drawGridXYZ[1],glv->drawGridXYZ[2]);}
-		void set_grid(python::tuple t){MUTEX; for(int i=0;i<3;i++)glv->drawGridXYZ[i]=python::extract<bool>(t[i])();}
-		#define VEC_GET_SET(property,getter,setter) python::object get_##property(){return vec2tuple(getter());} void set_##property(python::tuple t){MUTEX; setter(tuple2vec(t));}
+		pyGLViewer(size_t _viewNo){init(_viewNo);}
+		python::tuple get_grid(){GLV; return python::make_tuple(glv->drawGridXYZ[0],glv->drawGridXYZ[1],glv->drawGridXYZ[2]);}
+		void set_grid(python::tuple t){GLV; MUTEX; for(int i=0;i<3;i++)glv->drawGridXYZ[i]=python::extract<bool>(t[i])();}
+		#define VEC_GET_SET(property,getter,setter) python::object get_##property(){GLV; return vec2tuple(getter());} void set_##property(python::tuple t){GLV; MUTEX; setter(tuple2vec(t));}
 		VEC_GET_SET(upVector,glv->camera()->upVector,glv->camera()->setUpVector);
 		VEC_GET_SET(lookAt,glv->camera()->position()+glv->camera()->viewDirection,glv->camera()->lookAt);
 		VEC_GET_SET(viewDir,glv->camera()->viewDirection,glv->camera()->setViewDirection);
 		VEC_GET_SET(eyePosition,glv->camera()->position,glv->camera()->setPosition);
-		#define BOOL_GET_SET(property,getter,setter)void set_##property(bool b){MUTEX; setter(b);} bool get_##property(){return getter();}
+		#define BOOL_GET_SET(property,getter,setter)void set_##property(bool b){GLV; MUTEX; setter(b);} bool get_##property(){GLV; return getter();}
 		BOOL_GET_SET(axes,glv->axisIsDrawn,glv->setAxisIsDrawn);
 		BOOL_GET_SET(fps,glv->FPSIsDisplayed,glv->setFPSIsDisplayed);
-		bool get_scale(){return glv->drawScale;} void set_scale(bool b){MUTEX; glv->drawScale=b;}
-		bool get_orthographic(){return glv->camera()->type()==qglviewer::Camera::ORTHOGRAPHIC;}
-		void set_orthographic(bool b){MUTEX; return glv->camera()->setType(b ? qglviewer::Camera::ORTHOGRAPHIC : qglviewer::Camera::PERSPECTIVE);}
-		#define FLOAT_GET_SET(property,getter,setter)void set_##property(Real r){MUTEX; setter(r);} Real get_##property(){return getter();}
+		bool get_scale(){GLV; return glv->drawScale;} void set_scale(bool b){GLV; MUTEX; glv->drawScale=b;}
+		bool get_orthographic(){GLV; return glv->camera()->type()==qglviewer::Camera::ORTHOGRAPHIC;}
+		void set_orthographic(bool b){GLV; MUTEX; return glv->camera()->setType(b ? qglviewer::Camera::ORTHOGRAPHIC : qglviewer::Camera::PERSPECTIVE);}
+		#define FLOAT_GET_SET(property,getter,setter)void set_##property(Real r){GLV; MUTEX; setter(r);} Real get_##property(){GLV; return getter();}
 		FLOAT_GET_SET(sceneRadius,glv->sceneRadius,glv->setSceneRadius);
-		void fitAABB(python::tuple min, python::tuple max){MUTEX; glv->camera()->fitBoundingBox(tuple2vec(min),tuple2vec(max));}
-		void fitSphere(python::tuple center,Real radius){MUTEX; glv->camera()->fitSphere(tuple2vec(center),radius);}
-		void showEntireScene(){MUTEX; glv->camera()->showEntireScene();}
-		void center(bool median=false){MUTEX; if(median)glv->centerMedianQuartile(); else glv->centerScene();}
-		python::tuple get_screenSize(){return python::make_tuple(glv->width(),glv->height());} void set_screenSize(python::tuple t){ MUTEX; vector<int>* ii=new(vector<int>); ii->push_back(ensuredMainWindow()->viewNo(glv)); ii->push_back(python::extract<int>(t[0])()); ii->push_back(python::extract<int>(t[1])()); QApplication::postEvent(ensuredMainWindow(),new QCustomEvent((QEvent::Type)YadeQtMainWindow::EVENT_RESIZE_VIEW,(void*)ii));}
-		string pyStr(){return string("<GLViewer for view #")+lexical_cast<string>(ensuredMainWindow()->viewNo(glv))+">";}
-		void saveDisplayParameters(size_t n){MUTEX; glv->saveDisplayParameters(n);}
-		void useDisplayParameters(size_t n){MUTEX; glv->useDisplayParameters(n);}
-		string get_timeDisp(){const int& m(glv->timeDispMask); string ret; if(m&GLViewer::TIME_REAL) ret+='r'; if(m&GLViewer::TIME_VIRT) ret+="v"; if(m&GLViewer::TIME_ITER) ret+="i"; return ret;}
-		void set_timeDisp(string s){MUTEX; int& m(glv->timeDispMask); m=0; FOREACH(char c, s){switch(c){case 'r': m|=GLViewer::TIME_REAL; break; case 'v': m|=GLViewer::TIME_VIRT; break; case 'i': m|=GLViewer::TIME_ITER; break; default: throw invalid_argument(string("Invalid flag for timeDisp: `")+c+"'");}}}
+		void fitAABB(python::tuple min, python::tuple max){GLV; MUTEX; glv->camera()->fitBoundingBox(tuple2vec(min),tuple2vec(max));}
+		void fitSphere(python::tuple center,Real radius){GLV; MUTEX; glv->camera()->fitSphere(tuple2vec(center),radius);}
+		void showEntireScene(){GLV; MUTEX; glv->camera()->showEntireScene();}
+		void center(bool median=false){GLV; MUTEX; if(median)glv->centerMedianQuartile(); else glv->centerScene();}
+		python::tuple get_screenSize(){GLV; return python::make_tuple(glv->width(),glv->height());} void set_screenSize(python::tuple t){GLV; MUTEX; vector<int>* ii=new(vector<int>); ii->push_back(viewNo); ii->push_back(python::extract<int>(t[0])()); ii->push_back(python::extract<int>(t[1])()); QApplication::postEvent(ensuredMainWindow(),new QCustomEvent((QEvent::Type)YadeQtMainWindow::EVENT_RESIZE_VIEW,(void*)ii));}
+		string pyStr(){return string("<GLViewer for view #")+lexical_cast<string>(viewNo)+">";}
+		void saveDisplayParameters(size_t n){GLV; MUTEX; glv->saveDisplayParameters(n);}
+		void useDisplayParameters(size_t n){GLV; MUTEX; glv->useDisplayParameters(n);}
+		string get_timeDisp(){GLV; const int& m(glv->timeDispMask); string ret; if(m&GLViewer::TIME_REAL) ret+='r'; if(m&GLViewer::TIME_VIRT) ret+="v"; if(m&GLViewer::TIME_ITER) ret+="i"; return ret;}
+		void set_timeDisp(string s){GLV; MUTEX; int& m(glv->timeDispMask); m=0; FOREACH(char c, s){switch(c){case 'r': m|=GLViewer::TIME_REAL; break; case 'v': m|=GLViewer::TIME_VIRT; break; case 'i': m|=GLViewer::TIME_ITER; break; default: throw invalid_argument(string("Invalid flag for timeDisp: `")+c+"'");}}}
+		#undef MUTEX
+		#undef GLV
 };
 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(pyGLViewer_center_overloads,center,0,1);
 
 
-pyGLViewer evtVIEW(){QApplication::postEvent(ensuredMainWindow(),new QCustomEvent(YadeQtMainWindow::EVENT_VIEW)); size_t origViewNo=ensuredMainWindow()->glViews.size(); while(ensuredMainWindow()->glViews.size()!=origViewNo+1) usleep(50000); return pyGLViewer(*ensuredMainWindow()->glViews.rbegin());}
+pyGLViewer evtVIEW(){QApplication::postEvent(ensuredMainWindow(),new QCustomEvent(YadeQtMainWindow::EVENT_VIEW)); size_t origViewNo=ensuredMainWindow()->glViews.size(); while(ensuredMainWindow()->glViews.size()!=origViewNo+1) usleep(50000); return pyGLViewer((*ensuredMainWindow()->glViews.rbegin())->viewId);}
 
 python::list getAllViews(){
 	python::list ret;
-	for(size_t i=0; i<YadeQtMainWindow::self->glViews.size(); i++) ret.append(pyGLViewer(YadeQtMainWindow::self->glViews[i]));
+	FOREACH(const shared_ptr<GLViewer>& glView, YadeQtMainWindow::self->glViews){ if(glView) ret.append(pyGLViewer(glView->viewId)); }
 	return ret;
 };
 
+
 BOOST_PYTHON_MODULE(_qt){
 	def("Generator",evtGENERATOR,"Start simulation generator");
 	def("Controller",evtCONTROLLER,"Start simulation controller");
@@ -166,6 +176,7 @@
 	def("Renderer",ensuredRenderer,"Return wrapped OpenGLRenderingEngine; the renderer is constructed if necessary.");
 	def("close",Quit);
 	def("isActive",qtGuiIsActive,"Whether the Qt GUI is being used.");
+	def("activate",qtGuiActivate,"Attempt to activate the Qt GUI from within python.");
 	def("runPlayerSession",runPlayerSession,runPlayerSession_overloads(args("savedQGLState","dispParamsNo","stride","postLoadHook","startWait")));
 	def("views",getAllViews);
 

Modified: trunk/gui/qt3/QtGUI.cpp
===================================================================
--- trunk/gui/qt3/QtGUI.cpp	2009-06-15 17:42:13 UTC (rev 1800)
+++ trunk/gui/qt3/QtGUI.cpp	2009-06-16 20:20:22 UTC (rev 1801)
@@ -10,6 +10,7 @@
 #include"YadeQtMainWindow.hpp"
 #include"GLViewer.hpp"
 #include<boost/algorithm/string.hpp>
+#include<boost/bind.hpp>
 #include <boost/filesystem/operations.hpp>
 #include <boost/filesystem/convenience.hpp>
 //#ifdef HAVE_CONFIG_H
@@ -26,8 +27,9 @@
 #endif
 
 QtGUI* QtGUI::self=NULL;
+QApplication* QtGUI::app=NULL;
 
-QtGUI::QtGUI(){self=this; mainWindowHidden=false;}
+QtGUI::QtGUI(){self=this; mainWindowHidden=false; }
 QtGUI::~QtGUI(){}
 
 CREATE_LOGGER(QtGUI);
@@ -36,6 +38,7 @@
 	cerr<<"Qt3 GUI\n=======\n\t-h to get this help\n"<<endl;
 }
 
+
 int QtGUI::run(int argc, char *argv[])
 {
 	int ch;
@@ -64,18 +67,42 @@
 		#endif
 	}
 	XInitThreads();
-   QApplication app(argc,argv);
+   app=new QApplication(argc,argv);
 	mainWindow=new YadeQtMainWindow();
 	mainWindow->show();
-	app.setMainWidget(mainWindow);
+	app->setMainWidget(mainWindow);
 	#ifdef EMBED_PYTHON
 		LOG_DEBUG("Launching Python thread now...");
 		//PyEval_InitThreads();
 		boost::thread pyThread(boost::function0<void>(&PythonUI::pythonSession));
 	#endif
-	int res =  app.exec();
-
+	int res =  app->exec();
 	delete mainWindow;
 	return res;
 }
 
+
+void QtGUI::runNaked(){
+	if(!app){ // no app existing yet
+		LOG_INFO("Creating QApplication");
+		XInitThreads();
+	   app=new QApplication(0,NULL);
+		if(!YadeQtMainWindow::self){
+			mainWindow=new YadeQtMainWindow();
+			mainWindow->guiMayDisappear=true;
+			mainWindow->hide();
+			//app->setMainWidget(mainWindow);
+		} else { LOG_ERROR("Main window was there, but not QtGUI::app??"); }
+		boost::thread appThread(boost::bind(&QApplication::exec,app));
+	}
+	//mainWindow->showSomeGui();
+#if 0
+	else if (!YadeQtMainWindow::self){ // app exists and runs, just reopen the main window
+		//LOG_INFO("Recreating main window "<<YadeQtMainWindow::self);
+		//mainWindow=new YadeQtMainWindow();
+		//mainWindow->guiMayDisappear=true;
+		mainWindow->showSomeGui();
+		//app->setMainWidget(mainWindow);
+	}
+#endif
+}

Modified: trunk/gui/qt3/QtGUI.hpp
===================================================================
--- trunk/gui/qt3/QtGUI.hpp	2009-06-15 17:42:13 UTC (rev 1800)
+++ trunk/gui/qt3/QtGUI.hpp	2009-06-16 20:20:22 UTC (rev 1801)
@@ -14,18 +14,22 @@
 class SimulationController;
 class GLViewer;
 class RenderingEngine;
+class QApplication;
 
 class QtGUI : public FrontEnd
 {
 	private :
 		YadeQtMainWindow  * mainWindow;
+		// run qtApp in separate thread, without parsing args and launching python
 
 	public:	
+		static QApplication* app;
 		static QtGUI *self;
 		bool mainWindowHidden;
 
 	public :
 		QtGUI ();
+		void runNaked();
 		virtual ~QtGUI ();
 		virtual int run(int argc, char *argv[]);
 		void help();

Modified: trunk/gui/qt3/YadeQtMainWindow.cpp
===================================================================
--- trunk/gui/qt3/YadeQtMainWindow.cpp	2009-06-15 17:42:13 UTC (rev 1800)
+++ trunk/gui/qt3/YadeQtMainWindow.cpp	2009-06-16 20:20:22 UTC (rev 1801)
@@ -27,6 +27,8 @@
 #include <boost/date_time/posix_time/posix_time.hpp>
 
 #include <yade/pkg-common/GravityEngines.hpp>
+#include<yade/gui-qt3/QtGUI.hpp>
+#include<qapplication.h>
 
 
 using namespace std;
@@ -38,6 +40,7 @@
 YadeQtMainWindow::YadeQtMainWindow() : YadeQtGeneratedMainWindow()
 {
 	self=this;
+	guiMayDisappear=false;
 
 	QGLFormat format;
 	format.setStencil(TRUE);
@@ -80,15 +83,22 @@
 	startTimer(100);
 }
 
+void YadeQtMainWindow::showSomeGui(){
+	if(controller||player||generator) return;
+	LOG_INFO("Showing main window");
+	this->show();
+}
+
 void YadeQtMainWindow::timerEvent(QTimerEvent* evt){
 	#if 1
 	//shared_ptr<MetaBody> rb=Omega::instance().getRootBody();
 		//if((rb && rb->bodies->size()>0) ||
 		if(controller || player || generator) {this->hide();}
-		else {this->show(); }
+		else { if(!guiMayDisappear) this->show(); }
 	#endif
 	// update GL views (if any)
 	redrawAll(/*force=*/false);
+	if(guiMayDisappear) { QtGUI::app->processEvents(); }
 }
 
 void YadeQtMainWindow::redrawAll(bool force){
@@ -110,11 +120,12 @@
 	preferences->mainWindowSizeX		= size().width();
 	preferences->mainWindowSizeY		= size().height();
 	IOFormatManager::saveToFile("XMLFormatManager",yadeQtGUIPrefPath.string(),"preferences",preferences);
+	self=NULL;
 }
 
 void YadeQtMainWindow::Quit(){ emit close(); }
 
-void YadeQtMainWindow::closeEvent(QCloseEvent *e){ renderer=shared_ptr<OpenGLRenderingEngine>(); closeAllChilds(); YadeQtGeneratedMainWindow::closeEvent(e); }
+void YadeQtMainWindow::closeEvent(QCloseEvent *e){ renderer=shared_ptr<OpenGLRenderingEngine>(); closeAllChilds(); YadeQtGeneratedMainWindow::closeEvent(e);  }
 
 void YadeQtMainWindow::ensureRenderer(){
 	if(!renderer){
@@ -215,7 +226,7 @@
 			}
 		}
 	}
-	LOG_FATAL("No such view???"<<glv);
+	LOG_ERROR("No such GLView?! "<<glv);
 }
 
 /* Close the last view (default); close the i-th view from the beginning (0=primary) */
@@ -232,8 +243,8 @@
 	throw std::invalid_argument("No such view");
 }
 
-void YadeQtMainWindow::closeAllChilds(){
-	while(glViews.size()>0 && glViews[0]!=NULL) { LOG_DEBUG("glViews.size()="<<glViews.size()<<", glViews[0]="<<glViews[0]); closeView(-1);}
+void YadeQtMainWindow::closeAllChilds(bool closeGL){
+	if(closeGL){ while(glViews.size()>0 && glViews[0]!=NULL) { LOG_DEBUG("glViews.size()="<<glViews.size()<<", glViews[0]="<<glViews[0]); closeView(-1);} }
 	if(player) player=shared_ptr<QtSimulationPlayer>();
 	if(controller) controller=shared_ptr<SimulationController>();
 	if(generator) generator=shared_ptr<QtFileGenerator>();

Modified: trunk/gui/qt3/YadeQtMainWindow.hpp
===================================================================
--- trunk/gui/qt3/YadeQtMainWindow.hpp	2009-06-15 17:42:13 UTC (rev 1800)
+++ trunk/gui/qt3/YadeQtMainWindow.hpp	2009-06-16 20:20:22 UTC (rev 1801)
@@ -31,7 +31,7 @@
 		void saveRendererConfig();
 		
 		void deleteSimulationController();
-		void closeAllChilds();
+		void closeAllChilds(bool closeGL=false);
 		void createView();
 		void closeView(GLViewer*);
 		void closeView(int);
@@ -41,6 +41,7 @@
 		void loadSimulation(string file);
 		void redrawAll(bool force=false);
 		void lookDown(shared_ptr<GLViewer> glv);
+		void showSomeGui();
 
 	protected :
 		shared_ptr<QtGUIPreferences> preferences;
@@ -50,16 +51,17 @@
 		YadeQtMainWindow ();
 		virtual ~YadeQtMainWindow ();
 		static YadeQtMainWindow* self; // retrieve instance pointer form elsewhere
+		bool guiMayDisappear;
 
 		DECLARE_LOGGER;
 	public slots :
 		enum{EVENT_CONTROLLER=QEvent::User+1,EVENT_PLAYER,EVENT_VIEW,EVENT_GENERATOR,EVENT_RESTORE_GLVIEWER_NUM,EVENT_RESTORE_GLVIEWER_STR,EVENT_RESTORE_VIEWER_FILE,EVENT_RESIZE_VIEW};
 		virtual void customEvent(QCustomEvent* e);
 		/* each of player, controller, generator have slots for them being opened and closed: create{Player,Controller,Generator} and the instances are kept in player, controller, generator. */
-		#define __MK_RM_CHILD(Child,child,YadeClass)  virtual void close##Child(){if(child)child=shared_ptr<YadeClass>();} virtual void create##Child(){closeAllChilds(); if(!child){child=shared_ptr<YadeClass>(new YadeClass()); connect(child.get(),SIGNAL(closeSignal()),this,SLOT(close##Child())); child->show();} else {child->show(); child->raise();}}
-		__MK_RM_CHILD(Generator,generator,QtFileGenerator);
-		__MK_RM_CHILD(Player,player,QtSimulationPlayer);
-		__MK_RM_CHILD(Controller,controller,SimulationController);
+		#define __MK_RM_CHILD(Child,child,YadeClass,closeGL)  virtual void close##Child(){if(child)child=shared_ptr<YadeClass>();} virtual void create##Child(){closeAllChilds(closeGL); if(!child){child=shared_ptr<YadeClass>(new YadeClass()); connect(child.get(),SIGNAL(closeSignal()),this,SLOT(close##Child())); child->show();} else {child->show(); child->raise();}}
+		__MK_RM_CHILD(Generator,generator,QtFileGenerator,true);
+		__MK_RM_CHILD(Player,player,QtSimulationPlayer,true);
+		__MK_RM_CHILD(Controller,controller,SimulationController,false);
 		#undef __MK_RM_CHILD
 		virtual void Quit();
 		virtual void closeEvent(QCloseEvent * evt);

Modified: trunk/gui/qt3/qt.py
===================================================================
--- trunk/gui/qt3/qt.py	2009-06-15 17:42:13 UTC (rev 1800)
+++ trunk/gui/qt3/qt.py	2009-06-16 20:20:22 UTC (rev 1801)
@@ -2,7 +2,8 @@
 from _qt import *
 
 if not isActive():
-	raise ImportError("The Qt gui is not being used (run with -N QtGUI).")
+	activate()
+#	# raise ImportError("The Qt gui is not being used (run with -N QtGUI).")