RE: RE: PyQt and PyROOT

From: Fine, Valeri <fine_at_bnl.gov>
Date: Tue, 16 Jan 2007 01:15:15 -0500


Hello Johan,  

Your script did not work because you did not use Qt properly. (That has nothing to do with ROOT /QtRoot) Please, follow my previous message those advices are still valid and . . . To fix  

> there was no canvas in the main window,
> meaning we still have a problem with the layout."
 

you have to replace your
> self.CentralWidget = qt.QWidget()

with

self.CentralWidget = qt.QWidget(self)

To fix  

> but the application was hanging up somewhere
 

you have to remove your second event loop:  

> application.exec_loop()

Hope this helps, Valeri  

I am begging a pardon with some delay . . . you see your script is the first Python script I am dealing with ;) and I still have to install PyQt to try it myself.  

PS. Please find the working equivalent of your Python script in C++ ( I did test on lxplus, it does work) #include <TRint.h>

#include <qmainwindow.h>

#include <qlayout.h>

#include <TH1.h>

#include <TQtWidget.h>  

QMainWindow *window()

{

// Create the main window

    QMainWindow *self = new QMainWindow();  

// Create the central widget.

    QWidget *CentralWidget = new QWidget(self); // This was wrong !!!

    self->setCentralWidget(CentralWidget);

    QGridLayout *Layout = new QGridLayout(CentralWidget);  

// Create a root histogram

   TH1F *hist = new TH1F("pipo","pipo", 100, 0, 100);  

// Create the main TQtWidget (using sip to get the pointer to the central widget).

   TQtWidget *Canvas = new TQtWidget(CentralWidget);  

// Place the TQtWidget in the main grid layout and draw the histogram.

   Layout->addWidget(Canvas,0,0);

   hist->Draw();  

   return self;

}

int main( int argc, char **argv )

{

   // Create an interactive ROOT application

   // This portion is to be done by PyROOT for you

   TRint *theApp = new TRint("Rint", &argc, argv); // This portion is to be done by PyROOT for you  

   // Create Qt object within ROOT application

   QMainWindow *w = window();

   w->resize(350,350);

   w->show();  

   // and enter the ROOT event loop...

   // This portion is to be done by PyROOT for you

   theApp->Run(); // This portion is to be done by PyROOT for you  

   printf(" Goob bye ROOT !\n");

}


From: Johan Bregeon [mailto:johan.bregeon_at_pi.infn.it] Sent: Mon 1/15/2007 12:41 PM
To: WLavrijsen_at_lbl.gov
Cc: Fine, Valeri; Luca Baldini; ROOT Talk Subject: Re: [ROOT] RE: PyQt and PyROOT

Thanks all for your help,
we were able to solve a couple of more problems following your advice, but unfortunately we couldn't have something stable working. but we actually do not have the time / man power /knowledge to go further with building up a ROOT application with a Qt gui, using pyroot and pyqt, so we decided to stop here on that point.

Our new idea is to use only pyRoot for this purpose, so let me start another trade...
cheers,
Johan

WLavrijsen_at_lbl.gov wrote:
> Dear all,

>

>
>> 2) What is creating the 'other' QApplication ? (we instance only one in
>> the main !)
>>    
>

> well, some gApplication will need to exist at some point: both ROOT GUI (e.g.
> your histo display) as well as Qt (buttons, frame, etc.) will need to receive
> notifications from the OS, which are dispatched in a mainloop. If not, parts
> of your GUI will freeze. You can either dispatch to both systems yourself, by
> writing your own mainloop, or let QtRoot take care of it, following Valeri's
> instructions.
>

>
>> ROOT had been started (QApplication was created too via ROOT Qt
>> plug-in). May be, Wim can explain us at which point the PyROOT
>> instantiates ROOT.
>>    
>

> For ROOT 5.14, you can actually override gApplication, as long as you do it
> between "import ROOT" and the first use of ROOT.<anything other than gROOT>.
> Of course, some calls on gROOT trigger the creation of a default gApplication.
>

> In your script, application creation is done later, and a TPyROOTApplication
> is created by that time (PyROOT does a simple check if ( ! gApplication ) on
> the first access to anything other than gROOT in the ROOT module, to see if it
> should create an application). I.e., this line: "ROOT.gSystem.Load('qtcint')".
>

> Note that TPyROOTApplication is nothing but a trivial TApplication derived,
> where the real work is done.
>

> HTH,
> Wim
> --
> Wim.Lavrijsen_at_cern.ch -- WLavrijsen_at_lbl.gov -- www.lavrijsen.net
>

> "Stop making excuses for your software." --first step towards quality
> "GIGO is not a valid design pattern." --corollary
>
Received on Tue Jan 16 2007 - 07:15:36 CET

This archive was generated by hypermail 2.2.0 : Tue Jan 16 2007 - 17:50:01 CET